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

No fallback language used when storage language not loaded properly #739

Closed
greckin opened this issue Sep 24, 2014 · 2 comments
Closed

No fallback language used when storage language not loaded properly #739

greckin opened this issue Sep 24, 2014 · 2 comments
Milestone

Comments

@greckin
Copy link

greckin commented Sep 24, 2014

Hi,

Please consider following plunker: http://plnkr.co/edit/cQM7dQmfSWJGMGJsjQ6N

It uses localeStorage to remember user's chosen language. A preferred language is set to German, a fallback one to English. Polish language is not provided for a static loader.
When we first enter plunker we can see that everything is written in German except one button which uses a fallback language. So far, so good.
If we switch language to Polish, since no translations are provided for Polish, it will use fallback language as expected.

Now local storage remembers that user has chosen Polish as a chosen language and if we refresh page angular-translate will try to load Polish translation and of course it will fail. However, no fallback language is going to be used, which for me is an expected behaviour.

It happens because angular-translate has never set $uses value and we will fail on if statement below:

var table = $uses ? $translationTable[$uses] : $translationTable, Interpolator = interpolationId ? interpolatorHashMap[interpolationId] : defaultInterpolator;

if (table && Object.prototype.hasOwnProperty.call(table, translationId)) {
    (...)
}

So table will be resolved to a table with objects per language keys, not a map of key into translations and we fail on hasOwnProperty check.

For the same reason ($uses not being set) we fail on a statement to check for a fallback language:

if ($uses && $fallbackLanguage && $fallbackLanguage.length) {
  fallbackTranslation(translationId, interpolateParams, Interpolator).then(function (translation) {
    deferred.resolve(translation);
  }, function (_translationId) {
    deferred.reject(applyNotFoundIndicators(_translationId));
  });
}

I am aware that is unlikely to run to this issue on a production unless someone decides to remove support for a language that users' locale storages may already remember. I am not sure if you will consider it as a bug but for me it is a bit inconsistent behaviour.

Best regards

@tspaeth
Copy link
Member

tspaeth commented Sep 24, 2014

The "using non-existing" fallback-languages has already been discussed somewhere - I just can't find the ticket actually.

But yes, until now, the standard loader does not check the $http - response states for validity an puts it into the hands of the developer to provide consistent language setup.

If you want - feel free to provide a nice PR :-).

greckin pushed a commit to greckin/angular-translate that referenced this issue Sep 28, 2014
…s set

and not being able to load locale from storage

Closes angular-translate#739
knalli pushed a commit to knalli/angular-translate that referenced this issue Oct 21, 2014
… set

and not being able to load locale from storage

By @greckin

Closes angular-translate#739
@knalli knalli added this to the 2.5.0 milestone Nov 23, 2014
@knalli
Copy link
Member

knalli commented Nov 23, 2014

Solved by PR.

@knalli knalli closed this as completed Nov 23, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants