Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Using forceLanguage does not load language automatically #1389

Closed
elpeq opened this issue Feb 1, 2016 · 8 comments
Closed

Using forceLanguage does not load language automatically #1389

elpeq opened this issue Feb 1, 2016 · 8 comments

Comments

@elpeq
Copy link

elpeq commented Feb 1, 2016

Hello,

tested in angular-translate 2.9

forceLanguage doesn't work if StaticFilesLoader is used:
$translateProvider.useStaticFilesLoader

Yann

@knalli
Copy link
Member

knalli commented Feb 9, 2016

@elpeq Please provide always a working demo with your issue.

I've made a demo, but cannot see any problem with this: http://plnkr.co/edit/iiBTCvK3t2qwUeTZiamd?p=preview

@knalli knalli added the waiting label Feb 9, 2016
@craig-at-rsg
Copy link

@elpeq Is a language failing to load, and then you're using forceLanguage? I handled the rejection from the static file loader and that let me continue.

return $translateStaticFilesLoader({ prefix: 'languages/', key: options.key, suffix: '.json' })['catch'](function () { return {}; })

@elpeq
Copy link
Author

elpeq commented Feb 15, 2016

Hello @knalli
I've adapted your demo and added a 3 language pt_PT that shows, that the force language doesn't work.
http://plnkr.co/edit/6BJPNGqS0YYo2fBJb8jf?p=preview

@knalli knalli changed the title forceLanguage doesn't work if StaticFilesLoader is used Using forceLanguage does not load language automatically Feb 15, 2016
@knalli knalli added this to the 2.9.2 milestone Feb 15, 2016
@knalli
Copy link
Member

knalli commented Feb 15, 2016

Alright: the language will be not loaded automatically.

@knalli knalli modified the milestones: 2.11.0, 2.10.0 Feb 28, 2016
knalli added a commit that referenced this issue Mar 20, 2016
All service, directive and filter supports `forceLanguage` supporting an override language selector for the specified translation id. Until now, the translation has not been resolved correctly if the language's translations has not been used yet.

Fixes #1389
@knalli
Copy link
Member

knalli commented Mar 20, 2016

Fixed with 14bc956

@knalli knalli closed this as completed Mar 20, 2016
@almeidap
Copy link

almeidap commented Apr 20, 2016

Forcing a language is now working in version 2.11.0 but it produces errors when trying to switch to another language afterwards:

angular.js:13236 TypeError: Cannot read property 'key' of undefined
    at angular-translate.js:2216
    at processQueue (angular.js:15552)
    at angular.js:15568
    ...

You should be able to reproduce the issue if you click in any language button on the updated demo Plunk (see console for stack trace):
http://plnkr.co/edit/3YVgipajDFwLuYBVVBeh?p=preview

FYI, angular-translate determines my preferred language as French, which is correct.

@almeidap
Copy link

In fact after some more testing, it looks like forcing a translation only works properly when using the translate pipe. Take a look to the improved demo again:
http://plnkr.co/edit/3YVgipajDFwLuYBVVBeh?p=preview

  • When using the translate-force directives, it fails radomly (probably due to the promise mechanism behind the scene).
  • Note that I had to comment the $translateProvider.determinePreferredLanguage() call as it seems to conflict with $translateProvider.fallbackLanguage() (see fallbackLanguage() invocation changes breaks useLocalStorage #1075) and breaks completely translate-force.

Unless there is something wrong in the demo, this issue should be reopened again.

@knalli
Copy link
Member

knalli commented Apr 20, 2016

We don't reopen.. the workflow is always a new issue. => #1471

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

No branches or pull requests

4 participants