Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide simple debug mode #316

Closed
ansonlouis opened this issue Dec 14, 2021 · 5 comments
Closed

Provide simple debug mode #316

ansonlouis opened this issue Dec 14, 2021 · 5 comments

Comments

@ansonlouis
Copy link

It would be useful to provide some sort of debug mode that can slightly alter the output when enabled. This can help devs see strings that are going through fbt and, more importantly, notice strings that are not going through fbt. Perhaps this could be an option in the babel plugins or an option in init.

A simple proposal, using the init route, would be to allow a final string transform function. This would allow devs to create their own format for debug mode, such as wrapping the string in brackets "[this string is translated]". I looked into several ways of going about this with the current api, but they are fairly hacky and may break easily.

@pkqinys
Copy link
Contributor

pkqinys commented Dec 15, 2021

I want to clarify your question. Are you asking for

  • the ability to add special flags in the translation(results of running yarn translate-fbts)
    OR
  • the ability to highlight translated/untranslated strings during runtime.

The latter is kind of supported if you are running in DEV mode:

if (__DEV__) {
if (!table && locale !== DEFAULT_SRC_LOCALE) {
console.warn('Translations have not been provided');
}
}

@ansonlouis
Copy link
Author

This would be runtime and would affect the output in the actual DOM (production = "My string", development = "[My string]"). This is just for an eyeball test to help catch bugs while developing and ensure necessary strings are being run through the library. If you have ideas on better ways to achieve this goal then that's certainly welcome.

@pkqinys
Copy link
Contributor

pkqinys commented Dec 19, 2021

This would be runtime and would affect the output in the actual DOM

Oh I see. You can indeed take advantage of the fbtInit() method.

FbtHooks.js declares a getTranslatedInput() method that determines how to get the final translated text. You can find its default implementation in FbtTranslations.js.

You pass into fbtInit()a custom implementation of getTranslatedInput() that:

  1. Looks up a string's translation.
  2. if the translation exists, wrap it in [] and return it.
  3. Otherwise return null (which will make the text show up as English string in the actual DOM)

@ansonlouis
Copy link
Author

Sweet thanks! We actually got it to work through a similar fashion

getFbtResult: result => {
    return new FbtResult(['[', ...result.contents, ']']);
}

Please comment if this approach would cause problems

@pkqinys
Copy link
Contributor

pkqinys commented Dec 20, 2021

I don't think that will work. result.contents could be translated string or English string, which means every UI string will show up inside a [] regardless whether it was translated

@pkqinys pkqinys closed this as completed Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants