// a.vue
<i18n>
{
"en-us": {
"hello": "hello"
},
"zh-cn": {
"hello": "哈囉"
}
}
</i18n>
// b.vue
<i18n locale="en-us">
{
"hello": "hello"
}
</i18n>
<i18n locale="zh-cn">
{
"hello": "哈囉"
}
</i18n>
// a.vue
<i18n src="src/locale/index.json">
</i18n>
// index.json
{
"en-us": {
"hello": "hello"
},
"zh-cn": {
"hello": "哈囉"
}
}
以下排版皆是:
// component.vue
// message.js
this.$t('fruits.apple')
// => An apple
export default {
fruits: {
apple: "An apple."
}
}
this.$t('fruits.apple', { adjective: "fresh" } )
// => A(n) fresh apple.
export default {
fruits: {
apple: "A(n) {adjective} apple."
}
}
this.$tc('fruits.apple', 1)
// => 倖存的蘋果
export default {
fruits: {
apple: "倖存的蘋果 | {n}個蘋果",
apple: "倖存的蘋果 | {count}個蘋果
}
}
this.$tc('fruits.apple', 0)
// => 一個都不留
export default {
fruits: {
apple: "一個都不留 | 倖存的蘋果 | {n}個蘋果",
apple: "一個都不留 | 倖存的蘋果 | {count}個蘋果"
}
}
this.$n(123.456789, 'amount')
// => 123.46
export default {
amount: {
maximumFractionDigits: 2
}
}
參考 $n - 數字
this.$t('fruits.apple')
// => 多個蘋果
export default {
"fruits": {
"apple": "一個都不留 | 倖存的蘋果 | @:count.many個蘋果",
"apple": "一個都不留 | 倖存的蘋果 | @:(count.many)個蘋果"
},
"count": {
"many": "多個",
}
}
this.$t('sentence')
// => A HUGE apple.
export default {
sentense: 'A @.upper:huge apple.',
adjectives: {
huge: 'huge'
}
}
this.$i18n.locale = 'en'
this.$t(path, options)
this.$tc(path, count)
this.$te(path) -> boolean
this.$n(number, path)
this.$d(number | Date, path)
{n}
{count}
(zero | )single | plural
@:(path)
假設我們要將下面一組數字進行排序: var input = [3, 2, 4, 1] 很快地,我們可能就想出以下的程式碼來達成需求: function sortInput() { // 去掉奇數 for (let i = 0; i < input.length; ++i) { for (let j = 0; j < input.length - i - 1; ++j) {
Oct 25, 2021ToC [ToC] 為什麼要用 CLI Pros: 搭配 vi, vscode, sublime 等工具, 編輯 commit message(別人都已打完 message,而你還在等 IDE 開編輯訊息的彈窗? Learn once, use everywhere! 不需要滑鼠(你也有滑鼠突然沒電的困擾嗎? 提升英打速度(?
Oct 12, 2021[ToC] JavaScript 為什麼不採用多執行緒 單執行緒的狀況下- 習慣的思維 const userTable = { '1': { money: 10000 } } function withdraw (id, money) { userTable[id].money -= money }
Nov 16, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up