angular-localization
angular-localization copied to clipboard
Language persistence longer than session
Hi,
is there a way to persist language longer than session. If i set another language than my defaultLanguage, every time i refresh the page, it first loads the default language and than switches to selected language (i do that manually, after getting the user settings). The problem would be solved it would be possible to save cookie longer then session. I can do that manually, but every time the cookie gets overriden by default language because i have: persistSelection: true.
Here is the config:
app.value('localeConf', { basePath: 'languages', defaultLocale: 'en-US', sharedDictionary: 'common', fileExtension: '.lang.json', persistSelection: true, cookieName: 'COOKIE_LOCALE_LANG', observableAttrs: new RegExp('^data-(?!ng-|i18n)'), delimiter: '::' }).value('localeSupported', [ 'en-US', 'de-DE' ]).value('localeFallbacks', { 'en': 'en-US', 'de': 'de-DE' });
Do you have any suggestions?
best regards Ivan
@ivanstojkovicapps that's interesting, let me take a look and debug and get back to you, it should store in the cookie and be permanent but if that's not the case I might need to fix something.
Btw, are you loading angular-cookies? What version of ng are you running?
Hi,
angular 1.4.2 and i am loading ngCookies
I think the only problem is that the cookie expiration date is session. After the session is finished (on new one started) it doesn't have any data in the cookie and uses the default.
@ivanstojkovicapps I see, that's interesting as I don't think we set the date anywhere. They might've added it in 1.4.x and I will have to take a look and update the codebase to conform. Thanks!
perfect!
Seems like we are using $cookieStore which is deprecated in 1.4+
Good catch, do you want to submit a PR to use $cookies instead?
I don't think the issue is cookie store.
@ivanstojkovicapps Please correct if I am wrong, but it seems your user session will clear the cookie at a given interval. If we want to persist the locale beyond the user session, then it has to be set in localStorage or sessionStorage instead of the cookie.
imo, sessionStorage may suit the requirement, since sessionStorage may store the value longer than desired.
still facing the same issue.............