-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐ new(number): add number localization
- Loading branch information
Showing
6 changed files
with
209 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default { | ||
'en-US': { | ||
currency: { | ||
style: 'currency', currency: 'USD', currencyDisplay: 'symbol' | ||
}, | ||
decimal: { | ||
style: 'decimal', useGrouping: false | ||
} | ||
}, | ||
'ja-JP': { | ||
currency: { | ||
style: 'currency', currency: 'JPY', currencyDisplay: 'symbol' | ||
}, | ||
numeric: { | ||
style: 'decimal', useGrouping: false | ||
}, | ||
percent: { | ||
style: 'percent', useGrouping: false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import numberFormats from './fixture/number' | ||
|
||
const desc = VueI18n.availabilities.numberFormat ? describe : describe.skip | ||
desc('number format', () => { | ||
describe('getNumberFormat / setNumberFormat', () => { | ||
it('should be worked', done => { | ||
const i18n = new VueI18n({ | ||
locale: 'en-US', | ||
numberFormats | ||
}) | ||
const el = document.createElement('div') | ||
document.body.appendChild(el) | ||
|
||
const money = 101 | ||
const vm = new Vue({ | ||
i18n, | ||
render (h) { | ||
return h('p', { ref: 'text' }, [this.$n(money, 'currency')]) | ||
} | ||
}).$mount(el) | ||
|
||
const { text } = vm.$refs | ||
const zhFormat = { | ||
currency: { | ||
style: 'currency', currency: 'CNY', currencyDisplay: 'name' | ||
} | ||
} | ||
nextTick(() => { | ||
assert.equal(text.textContent, '$101.00') | ||
i18n.setNumberFormat('zh-CN', zhFormat) | ||
assert.deepEqual(i18n.getNumberFormat('zh-CN'), zhFormat) | ||
i18n.locale = 'zh-CN' | ||
}).then(() => { | ||
assert.equal(text.textContent, '101.00人民币') | ||
}).then(done) | ||
}) | ||
}) | ||
|
||
describe('mergeNumberFormat', () => { | ||
it('should be merged', () => { | ||
const i18n = new VueI18n({ | ||
locale: 'ja-JP', | ||
numberFormats | ||
}) | ||
const percent = { style: 'percent' } | ||
i18n.mergeNumberFormat('en-US', { percent }) | ||
assert.deepEqual(percent, i18n.getNumberFormat('en-US').percent) | ||
}) | ||
}) | ||
}) |