An open API service indexing awesome lists of open source software.

https://github.com/floriank/ngtranslator

Translate module for AngularJS
https://github.com/floriank/ngtranslator

Last synced: 4 months ago
JSON representation

Translate module for AngularJS

Awesome Lists containing this project

README

        

# ngTranslator

Translate you [AngularJS](http://angularjs.org/) applications. Original module and idea by [Philipp Klose](https://github.com/thehippo).

## Usage

Configure the language you want:

app = angular.module('YourModuleName', ['ngTranslator']);

app.config(['translateConfigProvider', function(translateConfig) {
translateConfig.setLanguage('de');
}]);

Load the translations:

app.run(['$http', 'translateData', function(http, translateData) {
http.get('translation.json').success(function(translations) {
translateData.setTranslations(translations);
});
}]);

Use it:


first_paragraph


first_paragraph




**Notes:**

* If a key or a language are not found an (configurable) error message will be displayed where the translation should be.
* If translation data is misconfigured for a key and (configurable) error message will be displayed where the translation should be.

## Translation data format

{
"de": {
"first_paragraph": "Erster Absatz",
"user_count": {
"":"Kein Benutzer online",
"0":"Kein Benutzer online",
"1": "Ein Benutzer online",
"2": "Zwei Benutzer online",
"defaultTranslation": "{{ count }} Benutzer online"
}
},
"en": {
"first_paragraph": "First paragraph",
"user_count": {
"":"No User online",
"0":"No User online",
"1": "One User online",
"2": "Two User online",
"defaultTranslation": "{{ count }} User online"
}
}
}

**Notes:**

* Translations could contain Angular expressions (e.g.: `{{ count }}`). These expression are watched and updated if they change
on the scope
* If you have a translation with multiple case it **must** have the field `defaultTranslation`. Only expressions from the
`defaultTranslation` field are watched.