angular-localization icon indicating copy to clipboard operation
angular-localization copied to clipboard

Language persistence longer than session

Open ivanstojkovicapps opened this issue 9 years ago • 8 comments

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 avatar Dec 24 '15 13:12 ivanstojkovicapps

@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?

doshprompt avatar Dec 24 '15 17:12 doshprompt

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 avatar Dec 24 '15 17:12 ivanstojkovicapps

@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!

doshprompt avatar Dec 24 '15 17:12 doshprompt

perfect!

ivanstojkovicapps avatar Dec 24 '15 17:12 ivanstojkovicapps

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?

doshprompt avatar Dec 24 '15 18:12 doshprompt

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.

bretkikehara avatar Dec 28 '15 21:12 bretkikehara

imo, sessionStorage may suit the requirement, since sessionStorage may store the value longer than desired.

bretkikehara avatar Dec 28 '15 21:12 bretkikehara

still facing the same issue.............

shubhamkumarnayak avatar Mar 16 '17 18:03 shubhamkumarnayak