|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>Example: Linked message with message function</title> |
| 6 | + <script src="../../../node_modules/vue/dist/vue.global.js"></script> |
| 7 | + <script src="../../../dist/vue-i18n.global.js"></script> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <div id="app"> |
| 11 | + <form> |
| 12 | + <label>{{ t('message.language') }}</label> |
| 13 | + <select v-model="locale"> |
| 14 | + <option value="en">en</option> |
| 15 | + <option value="ja">ja</option> |
| 16 | + </select> |
| 17 | + </form> |
| 18 | + <p>{{ t('message.linked') }}</p> |
| 19 | + <label>{{ t('message.homeAddress') }}</label> |
| 20 | + <p class="error">{{ t('message.missingHomeAddress') }}</p> |
| 21 | + <p>{{ t('message.custom_modifier', { snake: 'message.snake' }) }}</p> |
| 22 | + </div> |
| 23 | + <script> |
| 24 | + const { createApp } = Vue |
| 25 | + const { createI18n, useI18n } = VueI18n |
| 26 | + |
| 27 | + const i18n = createI18n({ |
| 28 | + legacy: false, |
| 29 | + locale: 'en', |
| 30 | + messages: { |
| 31 | + en: { |
| 32 | + message: { |
| 33 | + language: 'Language', |
| 34 | + the_world: 'the world', |
| 35 | + dio: 'DIO:', |
| 36 | + // '@:message.dio @:message.the_world !!!!' |
| 37 | + linked: ({ linked }) => `${linked('message.dio')} ${linked('message.the_world')} !!!!`, |
| 38 | + homeAddress: 'Home address', |
| 39 | + // 'Please provide @.lower:message.homeAddress' |
| 40 | + missingHomeAddress: ({ linked }) => `Please provide ${linked('message.homeAddress', 'lower')}`, |
| 41 | + snake: 'snake case', |
| 42 | + // "custom modifiers example: @.snakeCase:{'message.snake'}" |
| 43 | + custom_modifier: ({ linked }) => `custom modifiers example: ${linked('message.snake', 'snakeCase')}` |
| 44 | + } |
| 45 | + }, |
| 46 | + ja: { |
| 47 | + message: { |
| 48 | + language: '言語', |
| 49 | + the_world: 'ザ・ワールド', |
| 50 | + dio: 'ディオ:', |
| 51 | + // '@:message.dio @:message.the_world !!!!' |
| 52 | + linked: ({ linked }) => `${linked('message.dio')} ${linked('message.the_world')} !!!!`, |
| 53 | + homeAddress: 'ホームアドレス', |
| 54 | + // 'どうか、@.lower:message.homeAddress を提供してください。' |
| 55 | + missingHomeAddress: ({ linked }) => `どうか、${linked('message.homeAddress', 'lower')} を提供してください。`, |
| 56 | + snake: 'スネーク ケース', |
| 57 | + // "カスタム修飾子の例: @.snakeCase:{'message.snake'}" |
| 58 | + custom_modifier: ({ linked }) => `カスタム修飾子の例: ${linked('message.snake', 'snakeCase')}` |
| 59 | + } |
| 60 | + } |
| 61 | + }, |
| 62 | + modifiers: { |
| 63 | + snakeCase: str => str.split(' ').join('-') |
| 64 | + } |
| 65 | + }) |
| 66 | + |
| 67 | + const app = createApp({ |
| 68 | + setup() { |
| 69 | + const { t, locale } = useI18n() |
| 70 | + |
| 71 | + // Something to do ... |
| 72 | + // |
| 73 | + |
| 74 | + return { t, locale } |
| 75 | + } |
| 76 | + }) |
| 77 | + app.use(i18n) |
| 78 | + app.mount('#app') |
| 79 | + </script> |
| 80 | + </body> |
| 81 | +</html> |
0 commit comments