|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>Translation component example</title> |
| 6 | + <script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js" ></script> |
| 7 | + <script src="https://unpkg.com/vue-i18n@8/dist/vue-i18n.js"></script> |
| 8 | + <script src=" https://cdn.jsdelivr.net/npm/@vue/[email protected]" ></script> |
| 9 | + <script src="../../../../packages/vue-i18n-bridge/dist/vue-i18n-bridge.global.js"></script> |
| 10 | + </head> |
| 11 | + <body> |
| 12 | + <h1>Translation component example</h1> |
| 13 | + |
| 14 | + <div id="app"> |
| 15 | + <h2>localize with slot contents:</h2> |
| 16 | + <i18n-t tag="p" class="name" keypath="message.named"> |
| 17 | + <template #name> |
| 18 | + <span>kazupon</span> |
| 19 | + </template> |
| 20 | + </i18n-t> |
| 21 | + |
| 22 | + <h2>localize with DOM contents:</h2> |
| 23 | + <i18n-t keypath="message.list" locale="en"> |
| 24 | + <span class="lang" |
| 25 | + >{{ t('message.language', {}, { locale: 'en' }) }}</span |
| 26 | + > |
| 27 | + </i18n-t> |
| 28 | + |
| 29 | + <h2>localize with using linked:</h2> |
| 30 | + <i18n-t keypath="message.linked"> |
| 31 | + <template #name> |
| 32 | + <span>かずぽん</span> |
| 33 | + </template> |
| 34 | + </i18n-t> |
| 35 | + |
| 36 | + <h2>localize with using plural:</h2> |
| 37 | + <form> |
| 38 | + <label for="locale-select" |
| 39 | + >{{ t('message.quantity', {}, { locale: 'en' }) }}</label |
| 40 | + > |
| 41 | + <select id="locale-select" v-model="count"> |
| 42 | + <option value="0">0</option> |
| 43 | + <option value="1">1</option> |
| 44 | + <option value="2">2</option> |
| 45 | + </select> |
| 46 | + </form> |
| 47 | + <i18n-t keypath="message.plural" locale="en" :plural="count"> |
| 48 | + <template #n> |
| 49 | + <b>{{ count }}</b> |
| 50 | + </template> |
| 51 | + </i18n-t> |
| 52 | + </div> |
| 53 | + <script> |
| 54 | + const { createApp, ref } = VueCompositionAPI |
| 55 | + const { createI18n, useI18n } = VueI18nBridge |
| 56 | + |
| 57 | + Vue.use(VueCompositionAPI) |
| 58 | + Vue.use(VueI18n, { bridge: true }) |
| 59 | + |
| 60 | + const i18n = createI18n( |
| 61 | + { |
| 62 | + legacy: false, |
| 63 | + locale: 'ja', |
| 64 | + messages: { |
| 65 | + en: { |
| 66 | + message: { |
| 67 | + language: 'English', |
| 68 | + quantity: 'Quantity', |
| 69 | + list: 'hello, {0}!', |
| 70 | + named: 'hello, {name}!', |
| 71 | + linked: '@:message.named How are you?', |
| 72 | + plural: 'no bananas | {n} banana | {n} bananas' |
| 73 | + } |
| 74 | + }, |
| 75 | + ja: { |
| 76 | + message: { |
| 77 | + language: '日本語', |
| 78 | + list: 'こんにちは、{0}!', |
| 79 | + named: 'こんにちは、{name}!', |
| 80 | + linked: '@:message.named ごきげんいかが?' |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + }, |
| 85 | + VueI18n |
| 86 | + ) |
| 87 | + |
| 88 | + const app = createApp({ |
| 89 | + setup() { |
| 90 | + const { t } = useI18n() |
| 91 | + const count = ref(0) |
| 92 | + return { count, t } |
| 93 | + } |
| 94 | + }) |
| 95 | + app.use(i18n) |
| 96 | + app.mount('#app') |
| 97 | + </script> |
| 98 | + </body> |
| 99 | +</html> |
0 commit comments