lavinjj / angularjs-localizationservice

AngularJS Resource Localization Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

language detection during initialization

xliyong opened this issue · comments

Hi,

During module initialization, the langage value is determined by
language:$window.navigator.userLanguage || $window.navigator.language

This may not work on earlier version of Android browsers.

I am using the following snippet for language detection.

And I think it is better to use normalized language string for resource loading. I have seen language string returned by browsers in various format: "en-US", "en-us", "en_us", "en", etc. I am actually defining a new angular service to normalize the string, which can be done in the module itself.

var lang, androidLang;
// works for earlier version of Android (2.3.x)
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
    lang = androidLang[1];
} else {
    // works for iOS and Android 4.x
    lang = navigator.userLanguage || navigator.language;
}

Nice find! Do you want to fork the project and submit the above as a pull request? That way as you make changes to get it to work under PhoneGap, you can submit a pull request and I'll add them to the source.

Thanks!

have been busy with my project. will do that once things get better. Thank you again for your work.

Resolved.