Skip to content

Commit

Permalink
Test graceful handling of string translations subkeys/replacements
Browse files Browse the repository at this point in the history
This allows certain translation-packages to simplify complex
translation keys down to a simple string without causing breakage.

Example use-cases include:
* writing simpler i18n files for languages that simply don't
  have the concept of pluralization.
* Shorthanding `subkey`ed translations where all subkeys should
  have the same text.
  • Loading branch information
maranomynet committed Oct 20, 2016
1 parent dace371 commit 08c36f6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ describe('translate.js', function () {
expect(t3b('horses', 7)).to.equal('Pluralization keys are missing')
})

it('should ignore count/subkey if translation is a plain string', function () {
expect(t3b('plain', 666)).to.equal('I like this.')
expect(t3b('plain', 'nonexistentsubkey')).to.equal('I like this.')
})
it('should ignore replacements object if translation is a plain string', function () {
expect(t3b('plain', {nonexistentreplacement: 'foo'})).to.equal('I like this.')
})


// wrong arguments
var t4 = translate(translationsObject, 'asd')
it('should return a translated string with the correct plural form and replaced placeholders: t(key, count, replacements) [wrong optio arg]', function () {
Expand Down

1 comment on commit 08c36f6

@maranomynet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, @StephanHoyer these tests already pass very nicely. This is only to prevent accidental regressions later.

Please sign in to comment.