Comments (2)
Thanks so much for getting back to me. I went with the approach of installing the i18next-vue@vue-27-next
version and using the <slot></slot>
custom slot values. This fixed the interpolation!
However, it seemed to cause some of my component units tests began failing that don't use the i18next
component but do use Vue slot syntax (<template #foo>
). I don't have as much time as I'd like to debug and it's entirely possible it's something to do with our set up not the library. I have a working shim of the @panter
component so I'm going to go ahead and use that pending our upgrade to Vue 3.
Thanks again for your time and clear explanation of my options.
P.S. Yes! It was indeed a simplification for the sake of example -- thanks for the tip!
from i18next-vue.
I'm happy to hear you found the migration docs helpful π
re 1: The 1.x documentation was indeed not up to date regarding the translation component. I've changed that to match what we have in the 2.x documentation.
re 2:
Why it is not working
I believe this problem is related to the Interpolation configuration you use with single curly braces:
interpolation: {
prefix: '{',
suffix: '}',
},
This is different from the default double curly {{
/}}
values. The translation component (always) uses single curly braces as well. This interferes with your config, because i18next itself will already try and interpolate all placeholders:
In your example you pass the result of $t('Need help with {processor}?')
as the :translate
prop. As you saw when debugging, the $t call has replaced {processor}
with nothing. This is because $t
is the "ordinary" $t
, which tries to interpolate all values, including {processor}
with given replacements. As there is no replacement in the $t call itself, it is just removed. After that, there is no {processor}
left in the translation that the translation component can replace.
With the default double curly braces configuration, $t would just get the translation, but leave the single curly placeholder {processor}
alone, so the translation component can do the interpolation.
Solution(s)
There is no simple solution in version 1.1.0 for this, assuming you can't just switch to double curly braces for i18next's interpolation.
Since version 2.2 the Vue 3 version of i18next-vue supports configuring something else than single curly braces to find what to interpolate in the translation component, see https://github.com/i18next/i18next-vue#custom-slot-values.
You could e.g. use
"Need help with {processor}?": "ΒΏNecesita ayuda con <slot>processor</slot>?",
or another start/end pattern that makes sense for you.
This is also available on the special i18next-vue@vue-27-next version, see https://github.com/i18next/i18next-vue/tree/vue-27-next. This is a backport of i18next-vue 3.0 to Vue 2.7 and needs the same additional migration that would otherwise be necessary when switching from i18next-vue 2.x to 3.0, see https://i18next.github.io/i18next-vue/migration-v3.html.
If you are willing to that additional changes to use the @vue-27-next version, that's great.
If you'd rather have 1.x version with just configurable start/end patterns for the translation component, let me know. This is not super easy to do, but I'd then try and selectively bring back that functionality to 1.x.
P.S.
I assume the translation component example is simplified and in reality uses some HTML. Otherwise, you would not need <i18next>
at all and could just let $t interpolate the plaintext processor
value
{{ $t('Need help with {processor}?', {processor}) }}
.
from i18next-vue.
Related Issues (16)
- Update GitHub workflows to match the new organization HOT 5
- support esm export
- importing i18next-vue breaks type checking a basic nuxt app HOT 4
- Please update for i18next > v22.5.0 HOT 2
- Changes for `i18next-vue` v3 HOT 1
- test HOT 1
- [Typescript Error] useTranslation - Type instantiation is excessively deep and possibly infinite HOT 2
- Unable to install via npm? HOT 2
- dont work lazy loading file HOT 2
- how to access this.$i18next in composition api setup HOT 2
- Support TypeScript HOT 7
- The `i18next` object returned from the `useTranslation()` is not reactive. HOT 3
- Limit the scope of a SFC component to some namespace and key prefix. HOT 7
- Implement <i18next> component. HOT 17
- support v-t directive HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18next-vue.