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

Planning issue to revive JavaScript i18n-js translation #6534

Open
jywarren opened this issue Oct 25, 2019 · 4 comments
Open

Planning issue to revive JavaScript i18n-js translation #6534

jywarren opened this issue Oct 25, 2019 · 4 comments
Labels
discussion feature explains that the issue is to add a new feature planning Planning issues!

Comments

@jywarren
Copy link
Member

Re #3262, we have pure js translation set up here:

I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"js":{"dashboard":{"all_updates":"All updates","none":"None","selected_updates":"Selected updates"}}});

I'm wondering if we can compile our Ruby translations into this file too? This will help with user generated content like features, which will soon include the navbar and other key areas of the site.

@jywarren jywarren added feature explains that the issue is to add a new feature planning Planning issues! discussion labels Oct 25, 2019
@jywarren
Copy link
Member Author

It seems that this gem (already installed) can autogenerate the translations.js file on the fly?

https://github.com/fnando/i18n-js/blob/master/README.md#rails-app-with-asset-pipeline

Bears some testing!

@jywarren
Copy link
Member Author

This is cool and can build on @gauravano's work!

@jywarren
Copy link
Member Author

OK, I found that we can:

  1. delete /app/assets/javascript/application/i18n/translations.js
  2. delete the "only JS" line from /config/i18n-js.yml so that all translations are automatically copied from Ruby locale files in /config/locales/ into an autogenerated translations.js file which is already loaded into the client side environment
  3. use I18n.missingBehaviour='guess'; to make I18n try really hard to find a translation (although this isn't perfect!)
  4. replace items on the page with their translations, using this schema:
// for h1 elements:
$('h1').each(function(i, e) {
  $(e).html(I18n.t($(e).html())); 
});

We can adapt this to make any element with class translate get auto-translated, or all sub-elements, if it has them.

And we could also have a data-translation="tags.index.follow" style attribute so we can use HTML attributes to require a very specific translation in the I18n namespace. But if it doesn't exist, it'll just guess.

This will make our translations nice and robust for feature-based content!

@NitinBhasneria
Copy link
Collaborator

@jywarren Are this tasks still need to be done. If yes, may I try please?

@stale stale bot added the stale label Oct 7, 2020
@publiclab publiclab deleted a comment from stale bot Oct 8, 2020
@stale stale bot removed the stale label Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion feature explains that the issue is to add a new feature planning Planning issues!
Projects
None yet
Development

No branches or pull requests

2 participants