Skip to content

Commit

Permalink
feat: Make "*" the default subkey, instead of "__"
Browse files Browse the repository at this point in the history
  • Loading branch information
maranomynet committed Sep 14, 2017
1 parent 7d8fc27 commit 5a45279
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var messages = {

hasDefaultSubkey: {
foo: 'Foo subkey value',
__: 'Default value',
'*': 'Default value',
},

'Prosa Key': 'This is prosa!',
Expand Down Expand Up @@ -116,7 +116,7 @@ t('saveButton', 'tooltip') => 'Save unsaved changes'
t('simpleButton', 'label') => 'Simple'
t('simpleButton', 'tooltip') => 'Simple'

//default '__' subkey
//default '*' subkey
t('hasDefaultSubkey', 'foo') => 'Foo subkey value'
t('hasDefaultSubkey', 'missing') => 'Default value'
t('hasDefaultSubkey') => 'Default value'
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
replacements = replacements || {}

if (translationIsObject) {
var propValue = (subKey != null && translation[subKey]) || translation.__
var propValue = (subKey != null && translation[subKey]) || translation['*']
if (propValue != null) {
translation = propValue
} else if (typeof subKey === 'number') {
Expand Down
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('translate.js', function () {
11: '{day}. November {year}',
12: '{day}. December {year}',

__: 'WAT! {n}!?',
n: 'Is always overridden by __'
'*': 'WAT! {n}!?',
n: 'Is always overridden by "*"'
},

'Prosa Key': 'This is prosa!',

comboCounter: '{name} is {n} years old.',
translationWithSubkeys: { 'foo': 'FOO' },
translationWithDefaultSubkey: { __: 'I am a default value' }
translationWithDefaultSubkey: { '*': 'I am a default value' }
}

var t = translate(translationsObject)
Expand Down Expand Up @@ -181,10 +181,10 @@ describe('translate.js', function () {
it('should ignore replacements object if translation is a plain string', function () {
expect(t3b('plain', {nonexistentreplacement: 'foo'})).to.equal('I like this.')
})
it('should return the "__" subkey value if no subkey is passed', function () {
it('should return the "*" subkey value if no subkey is passed', function () {
expect(t3b('translationWithDefaultSubkey')).to.equal('I am a default value')
})
it('should retry the "__" subkey value if passed subkey is missing', function () {
it('should retry the "*" subkey value if passed subkey is missing', function () {
expect(t3b('translationWithDefaultSubkey', 'nonexistentsubkey') ).to.equal('I am a default value')
expect(t3b('date', 13, {day: '13', year: 2013}) ).to.equal('WAT! 13!?')
})
Expand Down

0 comments on commit 5a45279

Please sign in to comment.