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
- Host: GitHub
- URL: https://github.com/floriank/ngtranslator
- Owner: floriank
- License: mit
- Created: 2014-02-18T10:36:05.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-07-16T14:28:13.000Z (almost 5 years ago)
- Last Synced: 2025-02-27T18:44:26.070Z (4 months ago)
- Language: CoffeeScript
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.