Enable `locale` override at callsite
jrwats opened this issue · 5 comments
A potentially nice feature to add to the runtime and Babel parser would be to enable a locale
override at the callsite.
prompts = [
...
<fbt desc="..." locale="es_ES">Switch to Spanish</fbt>,
<fbt desc="..." locale="de_DE">Switch to German</fbt>,
...
];
is a lot easier to reason about than updating genTranslatedInput
to do what you want.
Originally posted by @jrwats in #190 (reply in thread)
Use case (locale selector): #190 (comment)
Hey , can i work over this issue ?
Of course! We're not actively working on it internally.
Hey, Can you direct me to the file I need to contribute ?
NOTE: our babel-plugin-fbt
plugin is currently undergoing a massive refactor to finally address #35. So what's checked into Github differs greatly from v0.20.0. There's a lot of undocumented changes currently checked into the repo, so if you want to tackle this soon, you may want to check in with @kayhadrin and @pkqinys if you have any questions or whether there's risk for merge conflicts.
Here's where we currently process options. That locale
attribute will appear similar to author
or project
.
You'll need to add it to the "allowed" list of options
fbt/packages/babel-plugin-fbt/src/FbtConstants.js
Lines 23 to 33 in 743e2e5
After that we need to decide on how we want this manifested at runtime. It can be a "reserved key" in the payload itself
similar to the __vcg
Line 136 in 743e2e5
but, I think cleanest would be to add it to the options
runtime parameter
Line 96 in 743e2e5
Following that, you'll want to process that option to change the lookup of the translations. This should be pretty straightforward. Update the signature here to take an optional locale
parameter and only read from the IntlViewerContext
if it's nullish.
fbt/runtime/nonfb/FbtTranslations.js
Line 29 in 76debd6