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

Translate error messages from auth.js #23

Open
stephanvierkant opened this issue Mar 27, 2018 · 5 comments
Open

Translate error messages from auth.js #23

stephanvierkant opened this issue Mar 27, 2018 · 5 comments

Comments

@stephanvierkant
Copy link
Contributor

In #22 I've added a Dutch translation for one single message ('press button').

However, I didn't translate the error messages (yet): https://github.com/darookee/u2f-two-factor-bundle/blob/master/Resources/public/js/auth.js#L10

What's the best way to translate error messages in a Javascript file? I know how translations in Symfony/Twig work, but I'm not sure what's the best way to translate strings from a Javascript files.

@darookee
Copy link
Owner

I'm not aware of any best practices for translating string ins JS files in a symfony environment, but this bundle looks promising. But using it would add another dependency to this bundle...

@stephanvierkant
Copy link
Contributor Author

Using a bundle to translate just a couple of short error messages seems somehow overkill to me.

Maybe we should do something like this:

<script type="text/javascript">
    var translations = {
       // ... 
       'yes' : {{ 'yes' | trans }},
       // ...
    }
</script>

Stolen from https://stackoverflow.com/questions/6940433/what-is-the-best-way-to-translate-javascript-literal-strings-in-assetic-assets/42175123

@darookee
Copy link
Owner

Yes, that sounds reasonable.

@stephanvierkant
Copy link
Contributor Author

stephanvierkant commented Apr 9, 2018

Let's pick this up together with #25.

I think we should translate the types, not the codes:

https://github.com/grantila/u2f-api#user-content-errors or https://developers.yubico.com/U2F/Libraries/Client_error_codes.html

OK = 0 // u2f-api will never throw errors with this code
OTHER_ERROR = 1
BAD_REQUEST = 2
CONFIGURATION_UNSUPPORTED = 3
DEVICE_INELIGIBLE = 4
TIMEOUT = 5

@darookee
Copy link
Owner

darookee commented Apr 12, 2018

Yes, that's a good idea. I'll look into #25 and #26 as soon as I can.

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