Ini File
Example of .ini localization file.
[Type:ConsoleApp1.MyController]
Key:Success = Success
Key:Error = Error (Code=0x{0:X8})
[Culture:en:Type:ConsoleApp1.MyController]
Key:Success = Success
Key:Error = Error (Code=0x{0:X8})
[Culture:fi:Type:ConsoleApp1.MyController]
Key:Success = Onnistui
Key:Error = Virhe (Koodi=0x{0:X8})
Code example:
// Read .ini lines
IEnumerable<ILine> lines = IniLinesWriter.Default.ReadLines("localization.ini");
// Read .ini file as string-key lines
IEnumerable<KeyValuePair<string, IString>> stringlines =
IniLinesWriter.Default.ReadUnformedLines("localization.ini", LineFormat.Parameters);
// Read .ini as tree
ILineTree tree = IniLinesWriter.Default.ReadLineTree("localization.ini");
// Read IAsset
IAsset asset = IniLinesWriter.Default.FileAsset("localization.ini");
Escape Rules
Ini files use the following escaping rules.
Unescaped | Escaped (in file) | Description |
---|---|---|
= | \= | In keys only |
[ | \[ | In sections only |
] | \] | In sections only |
\{ | \{ | Braces escaped when they don't refer to an argument. |
\} | \} | Braces escaped when they don't refer to an argument. |
: | \: | Parameter separator |
\0 (null char) | \0 | |
\n (new line) | \n | |
\t (tab) | \t | |
\r (carriage return) | \r | |
\a (audio) | \a | |
\b (back space) | \b | |
\f (form feed) | \f | |
\ (back slash) | \\ | |
' ' (space) | '\ ' | |
(codepoint) | \xhh | |
(codepoint) | \uhhhh | |
(codepoint) | \Uhhhhhhhh |
Colon : is escaped as \: in key, but don't use any escaping in value.
ILine key = root.Key("X:Y").Format("Text:Text");
Key:X\:Y = Text:Text
New line is escaped as \n, and carriage-return as \r.
ILine key = root.Key("X\nY").Format("line1\r\nline2\r\n");
Key:X\nY = line1\r\nline2\r\n
Back-slash is escaped as \\.
ILine key = root.Key("X\\Y").Format("\\Folder\\File");
Key:X\\Y = \\Folder\\File
Control characters are escaped with patterns \xhh and \uhhhh.
ILine key = root.Key("\u0000\u0001").Format("\u0002\u0003");
Key:\0\x01 = \x02\x03
Quotes don't need escaping.
ILine key = root.Key("\"String\"").Format("\"In quotes\"");
Key:"String" = "In quotes"
Braces { and } don't need escaping.
ILine key = root.Key("").Format("Hello mr. {0}");
Key:String = Hello mr. {0}
However, if braces are not intended to formulate arguments, then they are escaped with back-slashes \.
ILine key = root.Key("").Format("\\{In curly brackets\\}");
Key:String = \{In curly brackets\}
Spaces ' ' and tabs \t before and after first non-whitespace characters are trimmed out. To not trim them out, whitespace must be escaped '\ ' and '\t'.
ILine key = root.Key("").Format(" White-space before and after. ");
Key:String = \ White-space before and after.\