Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Use jed1x json format to correctly handle pluralization #753

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Jan 28, 2022

Fixes

Fixes #702 by @obulat

Description

This PR uses a more modern JSON format for downloading the translations from translate.wordpress.org, jed1x. This enables pluralization (the NGX format did not have any information about pluralization).

Testing Instructions

Run pnpm run i18n:get-translations to update the translations for all locales. You should see that the keys that need to be pluralized (eg. waveform.current-time, browse-page.all-result-count-more), have several values joined with a pipe if translations for that locale has been done.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat added 🟧 priority: high Stalls work on the project or its dependents ✨ goal: improvement Improvement to an existing user-facing feature 🕹 aspect: interface Concerns end-users' experience with the software labels Jan 28, 2022
@obulat obulat requested a review from a team as a code owner January 28, 2022 17:44
@obulat obulat requested review from zackkrida and krysal January 28, 2022 17:44
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM! Good catch 🙂

@@ -405,7 +405,7 @@
"browse-page": {
"all-no-results": "No results",
"all-result-count": "{localeCount} result|{localeCount} results",
"all-result-count-more": "Over {localeCount} results",
"all-result-count-more": "Over {localeCount} result|Over {localeCount} results",
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there's some kind of ESLint rule we could write to emit a warning or something when we find a translation string that should probably have plural variations... like maybe something basic, if the English string ends with s and also contains a variable interpolation? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting idea, @sarayourfriend !

src/locales/scripts/jed1x-json-to-json.js Show resolved Hide resolved
Comment on lines +3 to +28
/**
* Convert a Jed1x-Translate object to a nested JSON object.
*
* Create a nested JSON object, clean up keys from jed1x context with special
* character, remove keys without values, convert values from array to string,
* if strings are for plural forms, join them with the pipe character.
* Go from this:
* {
* "browse-page.load\u0004Load more results": [
* "Загрузить ещё результаты"
* ],
* "browse-page.all-result-count-more\u0004Over ###localeCount### results": [
* "Более ###localeCount### результата",
* "Более ###localeCount### результатов",
* "Более ###localeCount### результатов"
* ]
* "browse-page.search-form.button\u0004Search": [],
* }
* To:
* {
* "browse-page: {
* "load": "Загрузить ещё результаты"
* "all-result-count-more": "Более ###localeCount### результата|Более ###localeCount### результатов|Более ###localeCount### результатов",
* }
*
*/
Copy link
Member

Choose a reason for hiding this comment

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

This is excellent documentation, great!

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

The documentation made it very easy to understand the changes here. LGTM!

@obulat obulat merged commit 53ca0f8 into main Feb 1, 2022
@obulat obulat deleted the i18n_plural_download branch February 1, 2022 12:57
rbadillap added a commit that referenced this pull request Feb 2, 2022
* main: (73 commits)
  Make audio/image pages without ids show a 404 (#768)
  Fix logo button paddings and simplify implementation (#767)
  Fix global audio rtl close placement (#780)
  Check for `null` localStorage explicitly (#763)
  Truncate global audio text to two lines (#773)
  New image details page (#682)
  Switch to path-based i18n routing (#701)
  Enable source maps in production (#755)
  Remove Jamendo and Wikimedia Commons from audio meta sources (#747)
  Use jed1x json format to correctly handle pluralization (#753)
  Fix logo color on error page layout (#752)
  Add homepage content switcher for mobile screens (#716)
  Add inline-start border to filters on desktop (#748)
  Fix header items not fitting in (#718)
  Expose `close` to popover content via slot props (#736)
  Truncate row layout audio titles (#735)
  Stop blocking on analytics requests (#715)
  Style links globally (#727)
  Refactor the usage of i18n result count computation (#707)
  Use `VPopover` for the content report form (#719)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🕹 aspect: interface Concerns end-users' experience with the software ✨ goal: improvement Improvement to an existing user-facing feature 🟧 priority: high Stalls work on the project or its dependents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[i18n] Pluralized translations are not downloaded
3 participants