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

Use window.navigator.language if no language cookie is set. #53

Merged
merged 2 commits into from Jul 23, 2015

Conversation

bretmorris
Copy link
Contributor

cookieStore always evaluates to true if persistSelection is true and $injector.has('$cookieStore'). This means that ngLocalize will not use a user's default language. Instead, it will just default to the defaultLocale. In my opinion, this is not the desired behavior.

Review on Reviewable

`cookieStore` always evaluates to `true` if `persistSelection` is `true` and `$injector.has('$cookieStore')`. This means that ngLocalize will not use a user's default language. Instead, it will just default to the `defaultLocale`. In my opinion, this is not the desired behavior.
@@ -262,7 +262,7 @@ angular.module('ngLocalize')
return currentLocale;
}

setLocale(cookieStore ? cookieStore.get(localeConf.cookieName) : $window.navigator.userLanguage || $window.navigator.language);
setLocale(cookieStore.get(localeConf.cookieName) ? cookieStore.get(localeConf.cookieName) : $window.navigator.userLanguage || $window.navigator.language);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setLocale(cookieStore && cookieStore.get(localeConf.cookieName) ? /* ... */);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would cookieStore evaluate to false and cookieStore.get(localeConf.cookieName) evaluate to true? If cookieStore is false then cookieStore.get(localeConf.cookieName) will definitely be false as well. Seems like an unnecessary check. Am I overlooking something?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cookieStore doesn't exist, referencing cookieStore.get will cause an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Better safe than sorry! Thanks!

Attempt at fixing failing test.
doshprompt added a commit that referenced this pull request Jul 23, 2015
fix(locale): use window.navigator.language if no language cookie is set.
@doshprompt doshprompt merged commit d21df3b into doshprompt:master Jul 23, 2015
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

Successfully merging this pull request may close these issues.

None yet

2 participants