-
-
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(config): custom message formatter (#57) by @jvmccarthy
Allow for register a custom message formatter function with `Vue.config.i18nFormatter` for more flexibility in formatting messages.
- Loading branch information
1 parent
9586f71
commit 2748eb4
Showing
7 changed files
with
93 additions
and
5 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
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,47 @@ | ||
import assert from 'power-assert' | ||
import Vue from 'vue' | ||
import locales from './fixture/locales' | ||
|
||
describe('custom formatter', () => { | ||
before(done => { | ||
Object.keys(locales).forEach(lang => { | ||
Vue.locale(lang, locales[lang]) | ||
}) | ||
Vue.config.lang = 'en' | ||
Vue.nextTick(done) | ||
}) | ||
|
||
after(done => { | ||
Vue.config.i18nFormatter = null | ||
Vue.nextTick(done) | ||
}) | ||
|
||
describe('global', () => { | ||
it('allows for specifying a custom formatter', done => { | ||
Vue.config.i18nFormatter = (string, ...args) => { | ||
assert.equal('the world', string) | ||
assert.equal(1, args[0]) | ||
assert.equal('two', args[1]) | ||
assert.deepEqual({ name: 'joe' }, args[2]) | ||
done() | ||
} | ||
|
||
Vue.t('message.hello', 1, 'two', { name: 'joe' }) | ||
}) | ||
}) | ||
|
||
describe('instance', () => { | ||
it('allows for specifying a custom formatter', done => { | ||
const vm = new Vue() | ||
Vue.config.i18nFormatter = (string, ...args) => { | ||
assert.equal('the world', string) | ||
assert.equal(1, args[0]) | ||
assert.equal(2, args[1]) | ||
assert.equal(3, args[2]) | ||
done() | ||
} | ||
|
||
vm.$t('message.hello', [1, 2, 3]) | ||
}) | ||
}) | ||
}) |
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