angularjs-localizationservice icon indicating copy to clipboard operation
angularjs-localizationservice copied to clipboard

Fall back on default resource file when key is not present in localized resource file

Open somelinguist opened this issue 12 years ago • 3 comments

Thanks for the great library. It made providing i18n support to my app very easy.

One feature I suggest is letting the service fall back to the default resource file if a given key/value combination is not in a localized resource file.

I'm developing a desktop app using node-webkit. I'm foreseeing the possibility of some tech-savvy users creating their own localized resource files. It would be great if even if they happened to leave out a key/value combination, the app would still output something other than the missing key or nothing.

somelinguist avatar Oct 10 '13 21:10 somelinguist

What I would suggest doing is to actually change from a dictionary to an object and by default populate it with the default values and then over write the values with the language file.

I'll try to create a branch showing how to do this over the weekend when I have more time.

lavinjj avatar Oct 16 '13 17:10 lavinjj

i am doing something like that:


// checks the dictionary for a localized resource string
            getLocalizedString: function(value) {
                // default the result to an empty string
                var result = '';
                // make sure the dictionary has valid data
                if ((localize.dictionary !== []) && (localize.dictionary.length > 0)) {
                    // use the filter service to only return those entries which match the value
                    // and only take the first result
                    var entry = $filter('filter')(localize.dictionary, function(element) {
                            return element.key === value;
                        }
                    )[0];
                    // set the result
                    if(entry) {
                        result = entry.value;
                    } else {
                        result = '[i18n: '+value+']';
                    }
                }
                // return the value to the call
                return result;
            }

xavadu avatar Nov 07 '13 14:11 xavadu

I'm doing this

result = entry? entry.value : value;

returning the original value

Cosmitar avatar Apr 14 '14 19:04 Cosmitar