i18next / ng-i18next

translation for AngularJS using i18next
https://github.com/i18next/ng-i18next
MIT License
161 stars 54 forks source link

How to use a preloaded translation file #69

Closed powmedia closed 9 years ago

powmedia commented 9 years ago

I run a build process which packages all app files into one .js file, which could include the default translation file. How do I provide this to ng-i18next so that it doesn't try to fetch it from the server?

bugwelle commented 9 years ago

You could try resStore in i18next options.

Example: https://github.com/i18next/ng-i18next/blob/master/test/unit/i18nextDirectiveSpec.js

You could put your translation files in one variable. Here's an example how it could look like:

var myTranslationFiles = {};
//Your german language file
myTranslationFiles['de-DE'] = {
    translation: {
        'hello': 'Herzlich Willkommen!'
        //and more...
    }
};
//Your dev/english language file
myTranslationFiles['dev'] = {
    translation: {
        'hello': 'Welcome!'
        //and more....
    }
};

//more code...

//i18next / ng-i18next config
var i18nextOptions = {
    lng: 'de-DE',
    useCookie: false,
    useLocalStorage: false,
    fallbackLng: 'dev',
    resStore: myTranslationFiles
};

I'm sorry you had to wait for two days for this answer. :)

Regards, Andre

bugwelle commented 9 years ago

I'll close this now since there are no more comments by the questioner. ;)