• Lexical
Show / Hide Table of Contents
  • Lexical.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Utility
      • DisposeList
      • FileScanner
      • VisitTree
      • File Operation
  • Lexical.FileProvider
    • Introduction
    • Package
    • Package.Abstractions
    • Root
    • Zip
    • Dll
    • SharpCompress
    • SharpZipLib
    • FileScanner
    • Utils
  • Lexical.Localization
    • Introduction
    • Tutorial
    • Asset
      • IAsset
      • IStringAsset
    • Line
      • ILine
      • ILineFactory
      • ILineRoot
      • ILineFormat
      • ILineLogger
      • LineComparer
    • File
      • ILineReader
      • ILineWriter
      • Ini
      • Json
      • Xml
      • Resx
      • Resources
    • Miscellaneous
      • Plurality
      • ICulturePolicy
      • IStringFormat
      • Dependency Injection
    • Practices
      • Class Library
      • Class Library DI
      • Class Library DI opt.
  • Lexical.Utilities
    • Introduction
    • UnicodeString
    • FileScanner
    • Permutation
    • Tuples
    • StructList

Json File

Example of .json 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})"
    }
  },
  "Culture:sv:Type:ConsoleApp1.MyController:Key:Success": "Det funkar",
  "Culture:sv:Type:ConsoleApp1.MyController:Key:Error": "Det funkar inte (Kod=0x{0:X8})"
}

Code example:

// Read .json file
IEnumerable<ILine> lines = JsonLinesReader.Default.ReadLines("localization.json");

// Read .json file as string-key lines
IEnumerable<KeyValuePair<string, IString>> stringlines = 
    JsonLinesReader.Default.ReadUnformedLines("localization.json", LineFormat.Parameters);

// Read .json as tree
ILineTree tree = JsonLinesReader.Default.ReadLineTree("localization.json");

// Read IAsset
IAsset asset = JsonLinesReader.Default.FileAsset("localization.json");

Escape Rules

Ini files use the following escaping rules.

Unescaped Escaped (in file) Description
" \"
: \\: Parameter separator
\{ \\{ Braces escaped when they don't refer to an argument.
\} \\} Braces escaped when they don't refer to an argument.
\n (new line) \n
\t (tab) \t
\r (carriage return) \r
\a (audio) \a
\b (back space) \b
\f (form feed) \f
\ (back slash) \\
(codepoint) \uhhhh


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"


Colon : is escaped as \\: in key. No escaping is used in value.

ILine key = root.Key("X:Y").Format("Text:Text");
"Key:X\\:Y": "Text:Text"


Back-slash in key is escaped as \\\\. Back-slash in value is escaped as \\.

ILine key = root.Key("X\\Y").Format("\\Folder\\File");
"Key:X\\\\Y": "\\Folder\\File"


Control characters are escaped with unicode pattern \uhhhh.

ILine key = root.Key("\u0000\u0001").Format("\u0002\u0003");
"Key:\u0000\u0001": "\u0002\u0003"


Quotes are escaped as \".

ILine key = root.Key("\"String\"").Format("\"In quotes\"");
"Key:\"String\"": "\"In quotes\""


Braces { and } don't need escaping when used to refer to an argument.

ILine key = root.Key("").Format("Hello mr. {0}");
"Key:String": "Hello mr(s). {0}"

However, if braces are not intended to formulate arguments, then they are escaped with double back-slashes \\.

ILine key = root.Key("").Format("\\{In curly brackets\\}");
"Key:String": "\\{In curly brackets\\}"
Back to top Copyright © 2015-2020 Toni Kalajainen