Skip to content

Commit

Permalink
fix(h5p-server): missing translations when language was not found (#1063
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JPSchellenberg authored Feb 17, 2021
1 parent 09cec79 commit 5bc9976
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/h5p-server/src/LibraryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ export default class LibraryManager {
);
return this.getLanguage(library, languageCodeMatch[1]);
}
if (language !== 'en' && language !== '.en') {
return this.getLanguage(library, 'en');
}
if (language === 'en') {
return this.getLanguage(library, '.en');
}
return null;
}
}
Expand Down
19 changes: 16 additions & 3 deletions packages/h5p-server/test/LibraryManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,29 @@ describe('basic file library manager functionality', () => {
);
});

it('returns null file for language en', async () => {
it('returns the English language file for language xx', async () => {
const libManager = new LibraryManager(
new FileLibraryStorage(`${__dirname}/data/libraries`)
);

const language = await libManager.getLanguage(
{ machineName: 'H5P.Example1', majorVersion: 1, minorVersion: 1 },
'en'
'xx'
);
expect(language).toBeNull();
expect(JSON.parse(language)).toMatchObject({
semantics: [
{
label: 'Greeting text',
default: 'Hello world!',
description: 'The greeting text displayed to the end user.'
},
{
label: 'Card image',
description:
'Image shown on card, optional. Without this the card will show just the text.'
}
]
});
});

it('returns the de language file for de-DE', async () => {
Expand Down

0 comments on commit 5bc9976

Please sign in to comment.