anu-localization
A package which provides localization for strings.
Last updated 2 years ago by simon128 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install anu-localization 
SYNC missed versions from official npm registry.

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

This module provides basic localization for strings.

How To Use

Structure

The structure anu-localization

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:

/**
* Translates a 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;

Current Tags

  • 1.0.0                                ...           beta (2 years ago)
  • 1.1.3                                ...           latest (2 years ago)

17 Versions

  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |