question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable `locale` override at callsite

See original GitHub issue

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 https://github.com/facebook/fbt/discussions/190#discussioncomment-514257_

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jrwatscommented, Jun 8, 2021

NOTE: our babel-plugin-fbt plugin is currently undergoing a massive refactor to finally address https://github.com/facebook/fbt/issues/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. https://github.com/facebook/fbt/blob/743e2e55ee6103b781938f1b72925a0f2304394a/packages/babel-plugin-fbt/src/babel-processors/FbtFunctionCallProcessor.js#L433-L456

You’ll need to add it to the “allowed” list of options https://github.com/facebook/fbt/blob/743e2e55ee6103b781938f1b72925a0f2304394a/packages/babel-plugin-fbt/src/FbtConstants.js#L23-L33

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 https://github.com/facebook/fbt/blob/743e2e55ee6103b781938f1b72925a0f2304394a/runtime/shared/fbt.js#L136

but, I think cleanest would be to add it to the options runtime parameter https://github.com/facebook/fbt/blob/743e2e55ee6103b781938f1b72925a0f2304394a/runtime/shared/fbt.js#L96

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. https://github.com/facebook/fbt/blob/76debd6aa2c7076a2018ba7ab20a8caa5e9e5ebb/runtime/nonfb/FbtTranslations.js#L29

1reaction
jrwatscommented, Jun 7, 2021

Of course! We’re not actively working on it internally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow the user to override winget's locale setting #422 - GitHub
I'd like to override the winget locale to change its output language. ... For example, configure scripts generated by GNU autoconf use ...
Read more >
Change the locale at runtime? - android - Stack Overflow
We'd like to add a feature so the PC can instruct the Android app to change its locale at runtime, i.e., start the...
Read more >
Acknowledgements | Discord
Gotta show respect where respect is due. See all the licenses and open source projects that Discord uses.
Read more >
Visual Studio Code Display Language (Locale)
You can also override the default UI language by explicitly setting the VS Code display language using the Configure Display Language command. Press...
Read more >
Locale - ArchWiki
Before a locale can be enabled on the system, it must be generated. ... The system-wide locale can be overridden in each user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found