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

Move untranslated strings into data-i18n attributes #8874

Conversation

rebecca-shoptaw
Copy link
Collaborator

@rebecca-shoptaw rebecca-shoptaw commented Mar 6, 2024

Closes #8848.

Fix. Makes string translation possible by internationalizing and moving text from JavaScript to HTML.

Technical

Very simple and easy to replicate in similar PR's! Of the various data-i18n examples in the codebase, the one I liked most and went with involves just:

  1. Adding i18n strings to the top of the HTML file, i.e.:
$ i18n_strings = {
    $ "empty_excerpt": _("Please provide an excerpt."),
    $ "over_wordcount": _("That excerpt is too long.")
    $ } 
  1. Adding the strings as an attribute to the div where the text will be displayed: data-i18n="$json_encode(i18n_strings)"
  2. In the JavaScript, replacing the plain string with a call to the data-i18n attribute:
const i18nStrings = JSON.parse(document.querySelector('#excerpts-errors').dataset.i18n);

if (!data.excerpt) {
    return error('#excerpts-errors', '#excerpts-excerpt', i18nStrings['empty_excerpt']);
}
  1. Regenerating the messages.pot file using the relevant Docker command to keep everything up to date

Note: There's a currently un-used string -- "Please enter a valid URL." -- added to the data-i18n for web.html to prep for that string's addition as part of #8871.

Testing

Previously untranslated strings like "Please choose an image or provide a URL" should appear in the messages.pot file.

Stakeholders

@jimchamp

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 16.00%. Comparing base (42f396d) to head (6037e0a).
Report is 6 commits behind head on master.

Files Patch % Lines
openlibrary/plugins/openlibrary/js/edit.js 0.00% 6 Missing ⚠️
openlibrary/plugins/openlibrary/js/covers.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8874      +/-   ##
==========================================
- Coverage   16.02%   16.00%   -0.03%     
==========================================
  Files          89       89              
  Lines        4693     4699       +6     
  Branches      818      820       +2     
==========================================
  Hits          752      752              
- Misses       3434     3439       +5     
- Partials      507      508       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jimchamp jimchamp assigned jimchamp and unassigned scottbarnes Mar 11, 2024
@jimchamp jimchamp added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Mar 12, 2024
Copy link
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rebecca-shoptaw --- lgtm!

@jimchamp jimchamp merged commit 545cf04 into internetarchive:master Mar 12, 2024
4 checks passed
@jimchamp jimchamp removed the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Apr 2, 2024
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

Successfully merging this pull request may close these issues.

Fix untranslated error messages in add.html and web.html.
4 participants