$translate on missing key does not return the key, but a failed promise
See original GitHub issueSubject of the issue
The documentation says “If [the translation id] doesn’t exist it’ll probably just return the translation id.”
On that basis, I would expect a call like:
$translate("MISSING_KEY").then(function(txt) { console.log(txt); })
to log “MISSING_KEY”.
However, it does nothing at all, because the promise returned from $translate is completed with a failure.
The correct code would be:
$translate("MISSING_KEY").then(function(txt) { console.log(txt); }, function(txt) { console.log(txt); })
as you can see in the “it('should return translation id if translation doesn\'t exist'” test at translate.spec.js:276
This means that the documentation is misleading and makes code that uses the service difficult to write correctly.
For example, this code in ng-admin will return nothing at all if the “errorMessage” translation key is not found:
$translate(errorMessage, {
status: error && error.status,
details: error && error.data && typeof error.data === 'object' ? JSON.stringify(error.data) : {}
}).then(text => notification.log(text, { addnCls: 'humane-flatty-error' }));
… because the author did not anticipate that the promise returned by $translate could fail. (I will raise a separate bug with ng-admin to try to fix this.)
Your environment
- version of angular-translate: 2.11.0
- version of angular: 1.4.8
- which browser and its version: n/a
Steps to reproduce
Reproduced in the unit test linked above.
Expected behaviour
The promise returned by $translate("MISSING_KEY") should complete with the value "MISSING_KEY"
Actual behaviour
The promise returned by $translate("MISSING_KEY") does not complete, but fails with an error value of "MISSING_KEY"
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Hello,
It seems that this behaviour appeared between 2.4.1 and 2.11.0 We discovered it when updating angular translate library.
We have a process that call angular-translate for a bunch of keys for translation. We store all related promises in an array and then call
$q.allon it.Before, when one of the key was missing, the promise was resolved anyway with the key of each missing translation. Now, the rejection of one promise implies the rejection of all promises.
Moreover, I think this is akward since the filter does not behave this way. It just returns the key when the translation is missing.
Is it possible to fallback to previous behaviour by introducing a setting for example?
Well, I think the (new) promise document by mdn is only slightly older than our release of 2.0 😃 Said this, I want to say this is a style which we have introduced some time ago (finally released early 2014).
There are already some things perhaps everyone would change in a new system (see #995), but the api (v2) is fixed.
So, basically: Yes. Would be better. But not in v2 any more.