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

Evaluate use of string i18n library in Twinkle #1

Closed
siddharthvp opened this issue Jan 5, 2021 · 3 comments
Closed

Evaluate use of string i18n library in Twinkle #1

siddharthvp opened this issue Jan 5, 2021 · 3 comments

Comments

@siddharthvp
Copy link
Member

JS string i18n libraries used on MediaWiki are all typically written for use in the wgUserLanguage rather than the wgContentLanguage. This poses a problem for Twinkle since many of our i18n string usages are in edited text; and edits saved to wikis should be in the content language of the wiki.

mediawiki.language is a collection of utilities but doesn't offer a message parser. Also, it's based on wgUserLanguage, whichc can't be changed.

mw.Message and mw.jqueryMsg

  • Locale is wgUserLanguage and can't be changed.
  • Offers magic words like ns, formatnum, SITENAME and many others
  • Offers HTML parsing, with built-in safeguards to stop XSS attacks

jquery.i18n

  • locale can be changed from the wgUserLanguage default. It is a global variable
  • Available as a ResourceLoader module

banana-i18n

  • Not available as a RL module. Needs to be bundled alongside Twinkle using webpack.
  • Locale can be specified.
  • formatnum templating not supported. Digits are always rendered as Arabic numerals.

i18next

  • External (non-WMF). Popular js library.
  • Does not use the "banana" message templating format which is used on MediaWiki and which translatewiki.net folks are familiar with.

Likely options: jquery.i18n and banana-i18n.

jquery.i18n vs banana-i18n

  • Both use the familiar "banana" message syntax
  • Locale specification in jquery.i18n is a global. Any other script can modify the locale and Twinkle would break. Banana-i18n uses a class-based system so that we remain in control.
  • This is same as jquery-i18n, except that this doesn't rely on jquery. The DOM-related functions are missing, which we don't need. This is the more modern library and is actively supported.

Issues with banana-i18n:

  • For plural rules parsing, it relies on Intl.PluralRules which isn't supported on IE 11 and Safari <13.
    • Solutions:
      • mediawiki.libs.pluralruleparser is available as a ResourceLoader module. Use a modified version of the the library that uses it instead.
      • Use v1.1 of the library which instead uses cldrpluralruleparser npm package and the plural rule data stored in a JSON file.
      • Drop support for for these browsers.
  • Does not translate numerals (also a problem with jquery-i18n)
    • Solutions:
      • Patch the library to add support for this.

None of these libraries appear to support the mw.language.listToText-like function in messages. This makes it seemingly impossible to localise strings of the form "Added tag1, tag2 and tag3 to article" (here, the number of tags is variable).

@siddharthvp
Copy link
Member Author

siddharthvp commented Jan 7, 2021

For the numeral translation limitation of https://github.com/wikimedia/banana-i18n, I have submitted a patch: wikimedia/banana-i18n#43

At the moment, however, it doesn't look like there is anyone active over there (the main maintainer is on a long leave). The plan as of now is to create a fork of banana-i18n with the following changes:

@siddharthvp
Copy link
Member Author

Created https://github.com/wikimedia-gadgets/orange-i18n with the above-mentioned changes.

@siddharthvp
Copy link
Member Author

None of these libraries appear to support the mw.language.listToText-like function in messages. This makes it seemingly impossible to localise strings of the form "Added tag1, tag2 and tag3 to article" (here, the number of tags is variable).

Support for this is now implemented in orange-i18n (see README patches # 3).

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

No branches or pull requests

1 participant