Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
somelinguist opened this issue Oct 10, 2013 · 3 comments

Comments

@somelinguist
Copy link

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.

@lavinjj
Copy link
Owner

lavinjj commented Oct 16, 2013

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.

@xavadu
Copy link

xavadu commented Nov 7, 2013

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;
            }

@Cosmitar
Copy link

I'm doing this

result = entry? entry.value : value;

returning the original value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants