|
| 1 | +# Components |
| 2 | + |
| 3 | +## BaseFormatProps |
| 4 | + |
| 5 | +BaseFormat Props for Components that is offered Vue I18n |
| 6 | + |
| 7 | +**Signature:** |
| 8 | +```typescript |
| 9 | +export interface BaseFormatProps |
| 10 | +``` |
| 11 | + |
| 12 | +**Details** |
| 13 | + |
| 14 | +The interface definitions of the underlying props of components such as Translation, DatetimeFormat, and NumberFormat. |
| 15 | + |
| 16 | +### locale |
| 17 | + |
| 18 | +**Signature:** |
| 19 | +```typescript |
| 20 | +locale?: Locale; |
| 21 | +``` |
| 22 | + |
| 23 | +**Details** |
| 24 | + |
| 25 | +Specifies the locale to be used for the component. |
| 26 | + |
| 27 | +If specified, the global scope or the locale of the parent scope of the target component will not be overridden and the specified locale will be used. |
| 28 | + |
| 29 | +### scope |
| 30 | + |
| 31 | +**Signature:** |
| 32 | +```typescript |
| 33 | +scope?: ComponetI18nScope; |
| 34 | +``` |
| 35 | + |
| 36 | +**Details** |
| 37 | + |
| 38 | +Specifies the scope to be used in the target component. |
| 39 | + |
| 40 | +You can specify either `global` or `parent`. |
| 41 | + |
| 42 | +If `global` is specified, global scope is used, else then `parent` is specified, the scope of the parent of the target component is used. |
| 43 | + |
| 44 | +If the parent is a global scope, the global scope is used, if it's a local scope, the local scope is used. |
| 45 | + |
| 46 | +### tag |
| 47 | + |
| 48 | +**Signature:** |
| 49 | +```typescript |
| 50 | +tag?: string | object; |
| 51 | +``` |
| 52 | + |
| 53 | +**Details** |
| 54 | + |
| 55 | +Used to wrap the content that is distribute in the slot. If omitted, the slot content is treated as Fragments. |
| 56 | + |
| 57 | +You can specify a string-based tag name, such as `p`, or the object for which the component is defined. |
| 58 | + |
| 59 | +## DatetimeFormat |
| 60 | + |
| 61 | +Datetime Format Component |
| 62 | + |
| 63 | +**Signature:** |
| 64 | +```typescript |
| 65 | +DatetimeFormat: { |
| 66 | + name: string; |
| 67 | + props: { |
| 68 | + value: { |
| 69 | + type: (NumberConstructor | DateConstructor)[]; |
| 70 | + required: boolean; |
| 71 | + }; |
| 72 | + format: { |
| 73 | + type: (ObjectConstructor | StringConstructor)[]; |
| 74 | + }; |
| 75 | + } & { |
| 76 | + tag: { |
| 77 | + type: (ObjectConstructor | StringConstructor)[]; |
| 78 | + }; |
| 79 | + locale: { |
| 80 | + type: StringConstructor; |
| 81 | + }; |
| 82 | + scope: { |
| 83 | + type: StringConstructor; |
| 84 | + validator: (val: "parent" | "global") => boolean; |
| 85 | + default: "parent" | "global"; |
| 86 | + }; |
| 87 | + }; |
| 88 | + setup(props: DatetimeFormatProps, context: SetupContext): RenderFunction; |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +**Details** |
| 93 | + |
| 94 | +See the following items for property about details |
| 95 | + |
| 96 | +:::danger |
| 97 | + Not supported IE, due to no support `Intl.DateTimeFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts) |
| 98 | + |
| 99 | +If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat) |
| 100 | +::: |
| 101 | + |
| 102 | +**See Also** |
| 103 | +- [FormattableProps](component#formattableprops) |
| 104 | +- [BaseFormatProps](component#baseformatprops) |
| 105 | +- [Custom Formatting](../../guide/essentials/datetime#custom-formatting) |
| 106 | + |
| 107 | +## DatetimeFormatProps |
| 108 | + |
| 109 | +DatetimeFormat Component Props |
| 110 | + |
| 111 | +**Signature:** |
| 112 | +```typescript |
| 113 | +export declare type DatetimeFormatProps = FormattableProps<number | Date, Intl.DateTimeFormatOptions>; |
| 114 | +``` |
| 115 | + |
| 116 | +## FormattableProps |
| 117 | + |
| 118 | +Formattable Props |
| 119 | + |
| 120 | +**Signature:** |
| 121 | +```typescript |
| 122 | +export interface FormattableProps<Value, Format> extends BaseFormatProps |
| 123 | +``` |
| 124 | +
|
| 125 | +**Details** |
| 126 | +
|
| 127 | +The props used in DatetimeFormat, or NumberFormat component |
| 128 | +
|
| 129 | +### format |
| 130 | +
|
| 131 | +**Signature:** |
| 132 | +```typescript |
| 133 | +format?: string | Format; |
| 134 | +``` |
| 135 | +
|
| 136 | +**Details** |
| 137 | +
|
| 138 | +The format to use in the target component. |
| 139 | +
|
| 140 | +Specify the format key string or the format as defined by the Intl API in ECMA 402. |
| 141 | +
|
| 142 | +### value |
| 143 | +
|
| 144 | +**Signature:** |
| 145 | +```typescript |
| 146 | +value: Value; |
| 147 | +``` |
| 148 | +
|
| 149 | +**Details** |
| 150 | +
|
| 151 | +The value specified for the target component |
| 152 | +
|
| 153 | +## NumberFormat |
| 154 | +
|
| 155 | +Number Format Component |
| 156 | +
|
| 157 | +**Signature:** |
| 158 | +```typescript |
| 159 | +NumberFormat: { |
| 160 | + name: string; |
| 161 | + props: { |
| 162 | + value: { |
| 163 | + type: NumberConstructor; |
| 164 | + required: boolean; |
| 165 | + }; |
| 166 | + format: { |
| 167 | + type: (ObjectConstructor | StringConstructor)[]; |
| 168 | + }; |
| 169 | + } & { |
| 170 | + tag: { |
| 171 | + type: (ObjectConstructor | StringConstructor)[]; |
| 172 | + }; |
| 173 | + locale: { |
| 174 | + type: StringConstructor; |
| 175 | + }; |
| 176 | + scope: { |
| 177 | + type: StringConstructor; |
| 178 | + validator: (val: "parent" | "global") => boolean; |
| 179 | + default: "parent" | "global"; |
| 180 | + }; |
| 181 | + }; |
| 182 | + setup(props: NumberFormatProps, context: SetupContext): RenderFunction; |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +**Details** |
| 187 | + |
| 188 | +See the following items for property about details |
| 189 | + |
| 190 | +:::danger |
| 191 | + Not supported IE, due to no support `Intl.NumberFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts) |
| 192 | + |
| 193 | +If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat) |
| 194 | +::: |
| 195 | + |
| 196 | +**See Also** |
| 197 | +- [FormattableProps](component#formattableprops) |
| 198 | +- [BaseFormatProps](component#baseformatprops) |
| 199 | +- [Custom Formatting](../../guide/essentials/number#custom-formatting) |
| 200 | + |
| 201 | +## NumberFormatProps |
| 202 | + |
| 203 | +NumberFormat Component Props |
| 204 | + |
| 205 | +**Signature:** |
| 206 | +```typescript |
| 207 | +export declare type NumberFormatProps = FormattableProps<number, Intl.NumberFormatOptions>; |
| 208 | +``` |
| 209 | + |
| 210 | +## Translation |
| 211 | + |
| 212 | +Translation Component |
| 213 | + |
| 214 | +**Signature:** |
| 215 | +```typescript |
| 216 | +Translation: { |
| 217 | + name: string; |
| 218 | + props: { |
| 219 | + keypath: { |
| 220 | + type: StringConstructor; |
| 221 | + required: boolean; |
| 222 | + }; |
| 223 | + plural: { |
| 224 | + type: (StringConstructor | NumberConstructor)[]; |
| 225 | + validator: (val: any) => boolean; |
| 226 | + }; |
| 227 | + } & { |
| 228 | + tag: { |
| 229 | + type: (ObjectConstructor | StringConstructor)[]; |
| 230 | + }; |
| 231 | + locale: { |
| 232 | + type: StringConstructor; |
| 233 | + }; |
| 234 | + scope: { |
| 235 | + type: StringConstructor; |
| 236 | + validator: (val: "parent" | "global") => boolean; |
| 237 | + default: "parent" | "global"; |
| 238 | + }; |
| 239 | + }; |
| 240 | + setup(props: TranslationProps, context: SetupContext): RenderFunction; |
| 241 | +} |
| 242 | +``` |
| 243 | + |
| 244 | +**Details** |
| 245 | + |
| 246 | +See the following items for property about details |
| 247 | + |
| 248 | +**See Also** |
| 249 | +- [TranslationProps](component#translationprops) |
| 250 | +- [BaseFormatProps](component#baseformatprops) |
| 251 | +- [Component Interpolation](../../guide/advanced/component) |
| 252 | + |
| 253 | +**Examples** |
| 254 | + |
| 255 | + |
| 256 | +```html |
| 257 | +<div id="app"> |
| 258 | + <!-- ... --> |
| 259 | + <i18n path="term" tag="label" for="tos"> |
| 260 | + <a :href="url" target="_blank">{{ $t('tos') }}</a> |
| 261 | + </i18n> |
| 262 | + <!-- ... --> |
| 263 | +</div> |
| 264 | +``` |
| 265 | + |
| 266 | + |
| 267 | +```js |
| 268 | +import { createApp } from 'vue' |
| 269 | +import { createI18n } from 'vue-i18n' |
| 270 | + |
| 271 | +const messages = { |
| 272 | + en: { |
| 273 | + tos: 'Term of Service', |
| 274 | + term: 'I accept xxx {0}.' |
| 275 | + }, |
| 276 | + ja: { |
| 277 | + tos: '利用規約', |
| 278 | + term: '私は xxx の{0}に同意します。' |
| 279 | + } |
| 280 | +} |
| 281 | + |
| 282 | +const i18n = createI18n({ |
| 283 | + locale: 'en', |
| 284 | + messages |
| 285 | +}) |
| 286 | + |
| 287 | +const app = createApp({ |
| 288 | + data: { |
| 289 | + url: '/term' |
| 290 | + } |
| 291 | +}).use(i18n).mount('#app') |
| 292 | +``` |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | +## TranslationProps |
| 298 | + |
| 299 | +Translation Component Props |
| 300 | + |
| 301 | +**Signature:** |
| 302 | +```typescript |
| 303 | +export interface TranslationProps extends BaseFormatProps |
| 304 | +``` |
| 305 | +
|
| 306 | +### keypath |
| 307 | +
|
| 308 | +**Signature:** |
| 309 | +```typescript |
| 310 | +keypath: string; |
| 311 | +``` |
| 312 | +
|
| 313 | +**Details** |
| 314 | +
|
| 315 | +The locale message key can be specified prop |
| 316 | +
|
| 317 | +### plural |
| 318 | +
|
| 319 | +**Signature:** |
| 320 | +```typescript |
| 321 | +plural?: number | string; |
| 322 | +``` |
| 323 | +
|
| 324 | +**Details** |
| 325 | +
|
| 326 | +The Plural Choosing the message number prop |
| 327 | +
|
0 commit comments