Dynamic translation keys
See original GitHub issueSo I’m not sure how to solve this really, but here’s the problem.
It picks this up as a Missing i18n Entry
lang.label.${choice}
And in my lang files it picks these up as Unused i18n Entry
lang.label.ar-AE
lang.label.de-DE
lang.label.en-US
lang.label.es-ES
lang.label.fr-CA
lang.label.fr-FR
lang.label.he-IL
My code has this within a loop where choice
is one of [ar-AE, de-DE, en-US, etc]
:
<label :for="choice">{{ $t(`lang.label.${choice}`) }}</label>
Could your tool treat the ${choice}
as a wildcard somehow and therefore not flag these items as missing?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:15 (6 by maintainers)
Top Results From Across the Web
How to dynamically construct translation keys for input ...
For this I am trying to generate the translation keys dynamically. My current attempt in html code looks like this:.
Read more >Dynamic Translation - Product Documentation | ServiceNow
Dynamic Translation enables you to add mapping between the ServiceNow® language codes and the language codes used by the translation service ...
Read more >Translating Dynamic Content (Strings) - Phrase
Use Phrase to translate dynamic segments, e.g. blog posts or product information ... as keys and values, decide on a key structure for...
Read more >Translation Keys - BigCommerce Dev Center
Translation keys exist in JSON files and are invoked based on the user's browser language. With a Stencil theme, you can define multiple...
Read more >Dynamic Translations in Angular - Christian Lüdemann
This post is going to cover how to fix this by introducing dynamic translation capabilities using ngx-translate for getting translations from a NodeJS...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Proposal 1
A quick workaround could be a “classic” ignore comment to tell vue-i18n-extract to ignore some entries we know are highly dynamics.
code:
translation:
Proposal 2
Building on the previous example we can use the comment to “tag” the dynamic lines with the used strings, as a mapping, to avoid dangling translations in case of refactoring.
code:
translation:
Yeah there are several occasions where you want some dynamic content in your paths. I’ve seen this with:
v-t
directive that allows for an object to be passed through, as opposed to a string literal.:path
in a<i18n>
componentI’ve thought a lot about how we can achieve support for dynamic paths… Let me sort of ‘brain dump’ here and maybe someone smarter than me can chime in:
RegExp
matchers that anI18NItem
path is dynamic. Dynamic can mean different things (see the list above) so we need ways to know which ‘type’ of dynamic path we have.This is where I hit a wall, there isn’t some ‘full proof’ way to evaluate the dynamic path without making a lot of assumptions about the users source code.
So, I’m open to hearing some other solutions. Or, possible workarounds we should document to make sure users know that this is a limitation of the library.