Skip to content

Commit

Permalink
feat: Make "__default__" the default subkey, instead of "*"
Browse files Browse the repository at this point in the history
  • Loading branch information
maranomynet committed Apr 20, 2018
1 parent 5a45279 commit 9ffffef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 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__: '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 __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.__default__
if (propValue != null) {
translation = propValue
} else if (typeof subKey === 'number') {
Expand Down
6 changes: 3 additions & 3 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 "*"'
__default__: 'WAT! {n}!?',
n: 'Is always overridden by __default__'
},

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

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

var t = translate(translationsObject)
Expand Down

0 comments on commit 9ffffef

Please sign in to comment.