Skip to content

Commit

Permalink
fix: Translator should return key when no translation found (#79)
Browse files Browse the repository at this point in the history
* fix: translator returns null when no translation found

* test: updated tests
  • Loading branch information
lem-onade authored May 17, 2021
1 parent ec1ad34 commit 3a60ba8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('AlertComponent', () => {

const message = window.document.body.getElementsByTagName('nde-alert')[0].shadowRoot.querySelector('.message').innerHTML.replace(/<!---->/g, '');

expect(message.trim()).toBe('');
expect(message.trim()).toBe(component.alert.message);

});

Expand Down
10 changes: 5 additions & 5 deletions packages/nde-erfgoed-core/lib/i8n/memory-translator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('MemoryTranslator', () => {

describe('translate', () => {

it('Should translate an existing key in an existing locale.', () => {
it('Should return an existing key in an existing locale.', () => {

const value = service.translate('foo', 'en-GB');

Expand All @@ -51,19 +51,19 @@ describe('MemoryTranslator', () => {

});

it('Should translate return null with an existing key in an non-existing locale.', () => {
it('Should return the input key with an existing key in an non-existing locale.', () => {

const value = service.translate('foo.bar', 'nl-NL');

expect(value).toBeFalsy();
expect(value).toEqual('foo.bar');

});

it('Should translate return null with an non-existing key in an existing locale.', () => {
it('Should return the input key with an non-existing key in an existing locale.', () => {

const value = service.translate('lorem', 'nl-NL');

expect(value).toBeFalsy();
expect(value).toEqual('lorem');

});

Expand Down
3 changes: 2 additions & 1 deletion packages/nde-erfgoed-core/lib/i8n/memory-translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class MemoryTranslator {
(translation) => translation.locale === usedLocale && translation.key === key
);

return foundTranslation ? foundTranslation.value : null;
// return key when no translation was found
return foundTranslation?.value || key;

}

Expand Down

0 comments on commit 3a60ba8

Please sign in to comment.