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

Commit

Permalink
fix(service): return empty string when found in fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhu authored and knalli committed Oct 9, 2016
1 parent 132e49a commit d76227e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/service/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
if (fallbackLanguageIndex < $fallbackLanguage.length) {
var langKey = $fallbackLanguage[fallbackLanguageIndex];
result = getFallbackTranslationInstant(langKey, translationId, interpolateParams, Interpolator);
if (!result) {
if (!result && result !== '') {
result = resolveForFallbackLanguageInstant(fallbackLanguageIndex + 1, translationId, interpolateParams, Interpolator);
}
}
Expand Down
11 changes: 10 additions & 1 deletion test/unit/service/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2316,11 +2316,15 @@ describe('pascalprecht.translate', function () {
.useLoader('customLoader')
.translations('en', {
'FOO': 'bar',
'BAR': 'foo'
'BAR': 'foo',
'BARE': ''
})
.translations('de', {
'FOO2': 'bar2'
})
.translations('fr', {
'BARE': 'bare'
})
.preferredLanguage('de')
.fallbackLanguage('en');

Expand Down Expand Up @@ -2349,12 +2353,17 @@ describe('pascalprecht.translate', function () {
it('should return translation if translation id exist', function () {
expect($translate.instant('FOO')).toEqual('bar');
expect($translate.instant('FOO2')).toEqual('bar2');
expect($translate.instant('BARE')).toEqual('');
});

it('should return translation id if translation id nost exist', function () {
expect($translate.instant('FOO3')).toEqual('FOO3');
});

it('should return the first translation if multiple fallbacks exist', function () {
expect($translate.instant('BARE')).toEqual('');
});

it('should return translation id with default interpolator if translation id nost exist', function () {
expect($translate.instant('FOO4 {{value}}', {'value': 'PARAM'})).toEqual('FOO4 PARAM');
});
Expand Down

0 comments on commit d76227e

Please sign in to comment.