question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add languages after i18next init in Angular?

See original GitHub issue

0 down vote favorite I want to use the i18next library to handle my localisations in my Angular 1.5.3 + Ionic project.

In my situation, the translations are per-user and will be provided after the user logs in.

I want to initialize i18next in the app.js file and then add translations in my register controller. It’s not working out for me.

App.js

if (window.i18next) {
    console.log('i18next'); //prints out i18next

    window.i18next.init({
        debug: true,
        lng: 'English', // If not given, i18n will detect the browser language.
        fallbackLng: 'English', // Default is dev
        useCookie: false,
        useLocalStorage: false
    }, function (err, t) {
        console.log('resources loaded'); //prints out resources loaded
    });
}

(function () {

    'use strict';

    angular.module(myApp, [
        'ionic',
        'ngCordova',
        'jm.i18next',
        'ngSanitize'
    ])
})();

Register.controller.js

(function () {
    "use strict";


    angular
        .module(myApp)
        .controller('RegisterController', function ($i18next, $scope) {

            console.log('> > > > > register controller::: ', $i18next);
//prints out: I18nTranslateService {$rootScope: m, options: Object, tOptions: Object, modules: Array(0), translations: Object…}



            $i18next.i18n.addResouceBundle('English', 'translations', {
              HELLO: 'hiya'
            });

//Object {exception: "TypeError: $i18next.i18n.addResouceBundle is not a function", stack: "TypeError: $i18next.i18n.addResouceBundle is not a…t:4400/lib/ionic/js/ionic.bundle.min.js:472:11277", cause: null}

})();

In addition to this, I have also tried to do window.i18next.addResourceBundle as well as $i18next.addResourceBundle and say that it is not a function. In the documentation it says that you can add items after init: https://www.i18next.com/add-or-load-translations.html

I am not sure what I am doing wrong.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
aubrey-fowlercommented, May 31, 2017

Thanks for your help it’s working great now.

0reactions
jamuhlcommented, May 31, 2017

init with resources: {}

i18next.init({
  ...,
  resources: {}
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Tutorial on Localizing with I18next | Phrase
First of all, navigate to the Angular Quickstart Page and install Node.js, Angular-cli and create a new application. Let's name it "my-i18n-app" ...
Read more >
Add or Load Translations - i18next documentation
Add after init. You can add the translations after init. import i18next from 'i18next';. ​. i18next.init({ resources: {} });. i18next.addResourceBundle('en' ...
Read more >
Angular Internationalization
The localization process includes the following actions. Extract text for translation into different languages; Format data for a specific locale.
Read more >
How To Use Internationalization (i18n) in Angular | DigitalOcean
You can use @angular/cli to create a new Angular Project. In your terminal window, use the following command: npx @angular/cli new ...
Read more >
Angular Localization - Unleash the full power of i18next - locize
Take your own Angular project or create a new one, i.e. with the Angular cli. ... We are going to adapt the app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found