dhoko / angular-ngBabelfish

Internationalization module for angular.js, it's magic !
MIT License
11 stars 3 forks source link

Problem with Translator for updateSate after lazy setData #38

Closed mbertin closed 9 years ago

mbertin commented 9 years ago

In order to update scope values we have to call updateState. But for lazy loading i18n.data is equals to the language so the following condition for updating the scope doesn't work.

 function setTranslation(page) {
        page = page || config.state;

        // Prevent too many digest
        if(i18n.currentState === page && i18n.stateLoaded && i18n.current === i18n.previousLang) {
          return;
        }

        i18n.currentState = page;
        i18n.active = true;

        var lang = i18n.current;
        var common = {}, currentPageTranslation = {};
        // It doesn't work for lazy loading 
        if(i18n.data[lang]) {
dhoko commented 9 years ago

It's a bug froom your feature. In lazy mode data cannot be different. The condition is valid.

    /**
     * Build i18n.data.
     * @param  {Object} data Data from the translation file
     */
    function buildI18n(data) {

        if(!config.lazy) {
            i18n.data = data;
            return;
        }

        i18n.data[i18n.current] = data;
    }

So if we are in lazy mode i18n.data contains key such as fr-FR, en-EN. i18n.data is our translations. Not a translation

dhoko commented 9 years ago

todo add a test for this case.