languagetool-org / languagetool-website-2018

OUTDATED, do not use anymore
12 stars 11 forks source link

How to translate strings in*.js? #20

Closed danielnaber closed 6 years ago

danielnaber commented 6 years ago

Do you have a suggestion how to translate in JS with the same system as in Laravel? I need to translate this: https://github.com/languagetool-org/languagetool-website-2018/blob/master/public/js/main.js#L77-L90

nickchamel commented 6 years ago

@danielnaber

For now, the work of filling sublangs is done by this function:

screen shot 2018-05-05 at 23 08 24

We can further produce an object with langs options:

screen shot 2018-05-05 at 23 08 40

but not only with the selected language but also with the current locale. For example:

screen shot 2018-05-05 at 23 08 47

Or best solution would be to store this data on the server (for example, the same messages.php). Then when clicking on Language, make AJAX request to api (need to create it, for example /api/sublangs?lang=en&locale=de). Then form the array of languages strings in response and render it on client.

danielnaber commented 6 years ago

Sorry, the place I pointed was not the most relevant one. https://github.com/languagetool-org/languagetool-website-2018/blob/master/public/js/main.js#L250-L406 is actually more relevant. It populates JS data structures later to be used in editor2.js. Any idea how to simplify this so the data comes from messages.php? I'm not sure Ajax API will work, as this introduces timing issues, so pre-filling on the server seems more robust?

nickchamel commented 6 years ago

@danielnaber please check changes on 20-passing-messages-to-client After that all messages are available in the window object and they can be assigned as values for the TinyMCE when it's initialized:

screen shot 2018-05-09 at 22 37 42