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

JS files with translations in client/lang dir are not used #138

Closed
sandervanscheepen opened this issue Oct 2, 2023 · 5 comments
Closed
Assignees

Comments

@sandervanscheepen
Copy link

sandervanscheepen commented Oct 2, 2023

Issue:
translations provided in JS files are not used
(except for the ones that are loaded in PHP, like in Method->getUnavailableMessage and RegisterHandler->getSupportText which results in partially translated screens)

This is the result when I load a site in Dutch. The English text is the fallback in bundle.js, the Dutch comes from _t in PHP (not JS)
image

Steps:
When I edit the fallback translation of TOTPRegister.INTRO in client/dist/js/bundle.js I see that fallback string in the second step of setting up MFA (/Security/login/default/mfa). So the English fallback text is used and not the translations in en.js or any of the localised variants.

I think the fix should be:

  • expose "client/lang" in composer.json
  • add this to Method->applyRequirements
    Requirements::add_i18n_javascript('silverstripe/totp-authenticator: client/dist/lang');

Note: This is similar to #85

PRs

@GuySartorelli
Copy link
Member

Thanks for reporting this.

Can you please confirm the following:

  1. What version of silverstripe/mfa and silverstripe/totp-authenticator are you using?
  2. How are you managing the locale for your website? i.e. what are you doing to tell Silverstripe CMS that it should be using your dutch translation files?

@sandervanscheepen
Copy link
Author

sandervanscheepen commented Oct 3, 2023

  1. "silverstripe/totp-authenticator" at 4.6.2 and "silverstripe/mfa" at 4.8.1
  2. i18n::set_locale('nl_NL'); in app/_config.php (site does not use Fluent)
    fyi setting it to i18n::set_locale('nl'); makes no difference.

When I manually edit vendor/silverstripe/totp-authenticator/client/dist/js/bundle.js to say

c.default.createElement("p",null,a._t("TOTPRegister.INTRO","IN BUNDLE FALLBACK Verification codes are created by an app on your phone. ")

This shows up in on my screen:
image


@GuySartorelli
Copy link
Member

Awesome, that's good context to have, thank you for that. That seems to indicate that there's a problem with pulling in translations from a project (or at least from js translation files) rather than those being hardcoded which has been a problem with mfa in the past.

Something similar to this was patched in silverstripe/admin and released in 1.13.3 - are you using at least 1.13.3 of the admin module?

@sandervanscheepen
Copy link
Author

sandervanscheepen commented Oct 4, 2023

Thanks for having a look.

I require silverstripe/recipe-cms 4.13 what results in silverstripe/admin at 1.13.13
So I have the update from silverstripe/silverstripe-admin#1523

If you look at the MFA module, in BaseHandlerTrait this line seems to tell Requirements where to look voor translation JS files:
Requirements::add_i18n_javascript('silverstripe/mfa: client/lang'); The translations from that modules JS files seem to load fine on the frontend. In the MFA module the client/lang folder is also exposed in composer.json

This line is not present at the moment in the TOTP module so I think Requirements is not aware of the JS translations of this module. When I expose client/lang and add this line to the class Method in the method named applyRequirements all seems to be working fine:

Requirements::add_i18n_javascript('silverstripe/totp-authenticator: client/dist/lang');

@emteknetnz
Copy link
Member

Linked PRs have been merged, they'll be automatically tagged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants