Anu
This package is part of the Anu-family.
Anu (అణు) is a word in Telugu (a language spoken in south india) which means as much as atomic. Thats what every Anu-package should be about. Simple and clean.
All Anu-packages are available via npm and can be used with javascript and typescript. The packages are written in typescript and compiled to javascript + a type definition file.
Anu-Localization
Work in progress...
This is going to be a basic localization package with no fancy extra weight.
How To Use
Structure
Setting up the configuration:
The configuration should look like this:
{
"FallbackLanguage": "english",
"RegexString": "T{(\\w+)}",
"LocalizationLanguages": [
{
"Key": "german",
"FilePath": "./localization.json",
"HttpLanguageKey": "de"
},
{
"Key": "english",
"FilePath": "./localization.json",
"HttpLanguageKey": "en"
}
]
}
- "FallbackLanguage": The language which is used if the configuration does not include one of the languages the Http-request wants.
- "RegexString": The regular expression which will be used to identify the keys in a html document that should be translated.
- "LocalizationLanguages": An array of languages this application supports.
- "Key": The key that is used to find the appropriate translation for the language.
- "FilePath": The path to the file that contains the translations for the language.
- "HttpLanguageKey": The key which is used in Http-request.
Setting up a file containing translations:
A file that contains translation should look like this:
[
{
"Key": "TEST",
"Translations": [
{
"LanguageKey": "english",
"Translation": "testenglish"
},
{
"LanguageKey": "german",
"Translation": "testdeutsch"
}
]
}
]
- "Key": The key that should be translated.
- "Translations": The appropriate translations.
- "LanguageKey": The key of the appropriate language.
- "Translation": The translation.
The service:
Work in progress
/**
* Translates the complete string.
* @param stringForTranslation The string which should be translated.
* @param languages The languages for which the translation should be found.
* @param localizationObjects The objects that should contain the translations.
*/
public TranslateWholeString(
stringForTranslation: string,
languages: LocalizationLanguage[],
localizationObjects: LocalizationObject[]): string;
/**
* Translates a key.
* @param key The key which should be translated.
* @param languages The languages for which the translation should be found.
* @param localizationObjects The objects that should contain the translation.
*/
public Translate(
key: string,
languages: LocalizationLanguage[],
localizationObjects: LocalizationObject[]): string;