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

Javascript localization library #4024

Closed
nijel opened this issue Jun 12, 2020 · 7 comments
Closed

Javascript localization library #4024

nijel opened this issue Jun 12, 2020 · 7 comments
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@nijel
Copy link
Member

nijel commented Jun 12, 2020

Is your feature request related to a problem? Please describe.
Sometimes it would be useful to translate static HTML content. Typical use case could be our static error page.

Describe the solution you'd like

  • Javascript library to load the translations and inject them into the page
    • The initial implementation can only support strings manually marked in the HTML for translation
    • Might be based on Django gettext library later to support usage from the javascript
  • Strings export addon for Weblate to push localized strings to JSON
    • Should be served externally to make it available when Hosted Weblate is down

Describe alternatives you've considered
Right now, the error page is not localized, what is not nice and people tend to complain about that.

Additional context
WeblateOrg/hosted#35

@nijel nijel added the enhancement Adding or requesting a new feature. label Jun 12, 2020
@nijel nijel added this to the 4.2 milestone Jun 12, 2020
@nijel
Copy link
Member Author

nijel commented Jun 16, 2020

Played a bit with this, the basic text extraction and replacement could be:

document.querySelectorAll('*').forEach(function(node) {
    if (node.children.length === 0 && node.textContent) {
        console.log(node.textContent); 
        node.textContent='x';
    }
});

@julen
Copy link
Contributor

julen commented Jun 16, 2020

Why not generate language-specific HTML files and serve them by default based on Accept-Language headers? Seems like a simpler solution to me.

@nijel
Copy link
Member Author

nijel commented Jun 16, 2020

It would work in this use case, but the intention is to support localization of static pages in general. GitHub pages might be another example of things which could be localized by it.

@julen
Copy link
Contributor

julen commented Jun 16, 2020

If it's for static pages I honestly think HTML is the way to go — I might miss some context, but in principle there's no strong technical reason to err on using JS there. JS localization should be left for SPAs and interactive components.

@nijel
Copy link
Member Author

nijel commented Jun 16, 2020

I'm not expert in that, but we got several questions on that topic. AFAIK GitHub doesn't support serving localized page depending on Accept-Language and generally localization of static or statically generated pages seem tricky for many users, while including JavaScript which does that seems easy.

@nijel
Copy link
Member Author

nijel commented Jul 8, 2020

Friend just pointed me to https://weglot.com/ which is basically built around this idea with some additional features (plugins for various CMS, server side proxying, ...).

@nijel nijel self-assigned this Aug 3, 2020
@nijel nijel closed this as completed in 7d15cdf Aug 3, 2020
@github-actions
Copy link

github-actions bot commented Aug 3, 2020

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, consider supporting Weblate by donating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants