Localization File
Four fileformats can be used out of the box, provided that the files follow a suitable structure. Localization files can be organized in many ways, internally and between each other. Key name policy is used for describing file names and lines.
Files can be loaded with a couple of ways.
- Using a reader to construct an asset.
- With asset loader and part builder.
- With asset loader and part class.
Example of .resx localization file.
Loading Asset
Files can then be loaded with a constructor.
// Use explicit reader instance
IAsset asset = IniLinesWriter.Default.FileAsset("localization.ini");
// Infer reader instance from file extension '.ini'
IAsset asset = LocalizationReaderMap.Instance.FileAsset("localization.ini");
Implementing
ILineFileFormat is interface for classes that tokenize text file formats, and any hierarchical formats. (Click here)
csharp
And then adding to constructor delegate to LocalizationReaderMap.Instance.
// Add reader of custom .ext format to the global collection of readers.
LocalizationReaderMap.Instance["ext"] = new ExtFileFormat();
Non-hierarchical formats can be implemented by implementing IAsset that reads the format.
Example implementation ExtFileFormat. (Click here)
csharp
class ExtFileFormat : ILocalizationKeyLinesStreamReader
{
public string Extension => "ext";
public IEnumerable<KeyValuePair<ILine, string>> ReadKeyLines(Stream stream, ILineFormat lineFormat = default)
{
ILine key = Key.Create("Section", "MyClass").Append("Key", "HelloWorld").Append("Culture", "en");
yield return new KeyValuePair<ILine, string>(key, "Hello World!");
}
}