Skip to content

Commit

Permalink
Merge pull request #551 from nextcloud/feat/code-cov-gettext
Browse files Browse the repository at this point in the history
Add missing test cases for `gettext.ts`
  • Loading branch information
ChristophWurst authored Jan 10, 2023
2 parents c99ff04 + 6ef8c97 commit 520ffe2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/gettext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ describe('gettext', () => {
expect(translation).toEqual('I wish Nextcloud were written in Rust')
})

it('is fault tolerant to invalid placeholders', () => {
const gt = getGettextBuilder()
.setLanguage('de')
.build()

const translation = gt.gettext('This is {value}', {
value: false
})

expect(translation).toEqual('This is {value}')
})

it('used nextcloud-style placeholder replacement for plurals', () => {
const gt = getGettextBuilder()
.setLanguage('de')
Expand Down Expand Up @@ -145,6 +157,27 @@ msgstr[2] "%n slika uklonjenih"
expect(translation).toEqual('2 slika uklonjenih')
})

it('falls back to english', () => {
const pot = `msgid ""
msgstr ""
"Last-Translator: Translator, 2023\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid "abc"
msgstr "xyz"
`
// Do not set local explicitly, so 'en' should be used
const gt = getGettextBuilder()
.addTranslation('en', po.parse(pot))
.build()

const translation = gt.gettext('abc')

expect(translation).toEqual('xyz')
})

it('does not escape special chars', () => {
const gt = getGettextBuilder()
.setLanguage('de')
Expand Down

0 comments on commit 520ffe2

Please sign in to comment.