The localization dictionary is a data structure used to store and obtain translations of strings. A localization dictionary contains a map of keys and their translations. The NLocalizationDictionary class provides the following properties:
- CultureName - gets/sets the name of the culture this dictionary provides translation for in the format "languagecode2-country/regioncode2", for example "en-US", "de-DE", "ru-RU", "bg-BG" and so on.
- FlagIcon - gets/sets the flag icon associated with this localization dictionary.
- FontSize - gets/sets the font size in points (pt) that should be applied to the UI of the application that uses this dictionary. This font size is applied automatically to the UI theme of the NOV widgets when the localization dictionary is passed to the NApplication.LocalizeFromStream method.
NOV provides a single instance of the NLocalizationDictaionary class accessible through the static readonly Instance field. To set the translation of a given key, you can use the SetTranslation method of the dictionary. For example, the code below sets a German translation to the text "Cancel".
Set a term translation |
Copy Code
|
---|---|
NLocalizationDictionary.Instance.SetTranslation("Cancel", "Abbrechen"); |
To get the translation of a given key you can use the NLoc.Get shortcut method like this:
Get a term translation |
Copy Code
|
---|---|
string localizedString = NLoc.Get("Cancel"); |
The NLoc.Get method returns the translation of the given key or the key itself if a translation for it is not found in the dictionary.
Alternatively to get the translation of a given key, you can use the TryGetTranslation method of the localization dictionary. This method returns true if a translation of the given key is found in the dictionary and false otherwise. The translation itself is returned as an out parameter.