You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: clarify v-t limitations and reactivity behavior (#2118)
- Improved explanation of `v-t`'s limitations regarding inline HTML and dynamic template expressions.
- Clarified that `v-t` supports reactivity but is less flexible compared to `$t`.
- Enhanced wording for better readability and accuracy.
This improves the documentation to better reflect the behavior of `v-t` and avoid potential misunderstandings.
As mentioned in [the scope section](../essentials/scope.md), vue-i18n has a global scope and a local scope.
121
+
As explained in [the scope section](../essentials/scope.md), `vue-i18n` supports both global and local scopes.
122
122
123
-
The scope under which `v-t` is also affected by scope when it works.
124
-
125
-
- local scope: using the i18n option in Legacy API style or using `useScope: ‘local'` in `useI18n`.
126
-
- global scope: all cases other than the above.
123
+
The behavior of `v-t` depends on the scope in which it is used:
127
124
125
+
-**Local scope**: Applied when using the i18n option in Legacy API style or setting `useScope: 'local'` in `useI18n`.
126
+
-**Global scope**: Used in all other cases.
128
127
129
128
## `$t` vs `v-t`
130
129
131
130
### `$t`
132
131
133
-
`$t` is function of VueI18n instance. It has the following pros and cons:
134
-
135
-
#### Pros
136
-
137
-
You can **flexibly** use mustache syntax `{}` in templates and also computed props and methods in Vue component instance.
132
+
`$t` is a function of the `VueI18n` instance with the following advantages and disadvantages:
138
133
139
-
#### Cons
134
+
#### Pros:
135
+
- Allows for **flexible usage** within templates, including mustache syntax `{}`.
136
+
- Supports computed properties and methods within Vue components.
140
137
141
-
`$t` is executed **every time** when re-render occurs, so it does have translation costs.
138
+
#### Cons:
139
+
-`$t` is executed **on every re-render**, which can add translation overhead.
142
140
143
141
### `v-t`
144
142
145
-
`v-t` is a custom directive. It has the following pros and cons:
146
-
147
-
#### Pros
148
-
149
-
`v-t` has **better performance** than the `$t` function due to its pre-translation is possible with the Vue compiler module which was provided by [vue-i18n-extensions](https://github.com/intlify/vue-i18n-extensions).
143
+
`v-t` is a custom directive with its own set of pros and cons:
150
144
151
-
Therefore it’s possible to make **more performance optimizations**.
145
+
#### Pros:
146
+
- Offers **better performance** than `$t`, as translations can be preprocessed by the Vue compiler module provided by [vue-i18n-extensions](https://github.com/intlify/vue-i18n-extensions).
147
+
- Enables **performance optimizations** by reducing runtime translation overhead.
152
148
153
-
#### Cons
149
+
#### Cons:
150
+
- Less flexible than `$t`; it’s **more complex** to use.
151
+
- Inserts translated content directly into the element’s `textContent`, which means it cannot be used inside inline HTML structures or combined with other dynamic template expressions.
152
+
- When using server-side rendering (SSR), you must configure a [custom transform](https://github.com/intlify/vue-i18n-extensions#server-side-rendering-for-v-t-custom-directive) by setting the `directiveTransforms` option in the `compile` function of `@vue/compiler-ssr`.
154
153
155
-
`v-t` cannot be flexibly used like `$t`, it’s rather **complex**. The translated content with `v-t` is inserted into the `textContent` of the element. Also, when you use server-side rendering, you need to set the [custom transform](https://github.com/intlify/vue-i18n-extensions#server-side-rendering-for-v-t-custom-directive) to `directiveTransforms` option of the `compile` function of `@vue/compiler-ssr`.
0 commit comments