Page MenuHomePhabricator

Lua interface for convenient access to translations in a message bundle
Open, HighPublic16 Estimated Story Points

Description

[Add more details]

Details

Show related patches Customize query in gerrit

Event Timeline

The problem that we are trying to solve is documented here: https://www.mediawiki.org/wiki/Translatable_modules

The Scribunto extension allows embedding scripting languages in MediaWiki. Currently only Lua scripting language is supported. Modules such as the Institution module use Scribunto with Lua.

To make functionality from our extension available to modules in Lua, we will have to extend Scribunto library. An extension that currently does this is the Proofread extension. (1, 2, 3)

Change #1020856 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] Add a sample Lua library to access message bundles

https://gerrit.wikimedia.org/r/1020856

Change #1023116 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Load the translations from MessageBundle

https://gerrit.wikimedia.org/r/1023116

Change #1025313 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[integration/config@master] Translate: Add dependency on Scribunto

https://gerrit.wikimedia.org/r/1025313

Change #1025380 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Load translations from fallback

https://gerrit.wikimedia.org/r/1025380

Change #1025766 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Add loadDefaultTranslations method

https://gerrit.wikimedia.org/r/1025766

Change #1025767 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Improve error handling

https://gerrit.wikimedia.org/r/1025767

I've been working on some POC patches, which can be found here. My goal is to gain a better understanding of Modules, Lua, and extending the Scribunto library. The API will be updated based on community feedback, but here are some planned changes that I think make sense:

  • Loading message bundles based on the page title rather than the message group ID. For example: TMB.new("MessageBundleDemoForever"), where TMB is the translatable message bundle module.
  • Adding language fallback support by default.
  • Including a method in the library to fetch translations based on the page language.

Change #1025313 merged by jenkins-bot:

[integration/config@master] Translate: Add dependency on Scribunto

https://gerrit.wikimedia.org/r/1025313

Change #1031178 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[integration/config@master] Translate: Add phan dependency

https://gerrit.wikimedia.org/r/1031178

Change #1031178 merged by jenkins-bot:

[integration/config@master] Translate: Add phan dependency on Scribunto

https://gerrit.wikimedia.org/r/1031178

Change #1031591 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Add code to validate the message bundle

https://gerrit.wikimedia.org/r/1031591

Change #1031592 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Change the way translations are requested

https://gerrit.wikimedia.org/r/1031592

Change #1034082 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Add method to get page language code

https://gerrit.wikimedia.org/r/1034082

Change #1034083 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Add ability to skip loading fallbacks

https://gerrit.wikimedia.org/r/1034083

Change #1034084 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Add ability to pass params for translations

https://gerrit.wikimedia.org/r/1034084

Change #1034085 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Add method documentation

https://gerrit.wikimedia.org/r/1034085

It just came into my mind that the current patches don’t return any information on the status of the translations (language, fuzziness) other than the ability to disable fallbacks. Users of this Lua interface may want to use similar markup as Translate’s page translation feature to indicate that a translation is fuzzy or missing. So I think that given a message key and a language, it should be possible to get a Lua table with the following information (either as table keys or as methods):

  • state: fuzzy, normal, maybe even reviewed
  • language: MediaWiki language code or mw.language object of the actually used language, which may be the requested language, English, or any other fallback language

I’m writing here because I’m not sure which one of the many patches this belongs in, or if a new patch should be added to the end of the relation chain.

Change #1035356 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Add method to load all translations

https://gerrit.wikimedia.org/r/1035356

It just came into my mind that the current patches don’t return any information on the status of the translations (language, fuzziness) other than the ability to disable fallbacks. Users of this Lua interface may want to use similar markup as Translate’s page translation feature to indicate that a translation is fuzzy or missing. So I think that given a message key and a language, it should be possible to get a Lua table with the following information (either as table keys or as methods):

  • state: fuzzy, normal, maybe even reviewed
  • language: MediaWiki language code or mw.language object of the actually used language, which may be the requested language, English, or any other fallback language

I’m writing here because I’m not sure which one of the many patches this belongs in, or if a new patch should be added to the end of the relation chain.

Thanks for surfacing this. I'll try to work on it in a patch at the end of the relation chain albeit maybe not immediately.

Change #1025766 abandoned by Abijeet Patro:

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Add loadDefaultTranslations method

Reason:

No longer necessary.

https://gerrit.wikimedia.org/r/1025766

Change #1025767 abandoned by Abijeet Patro:

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Improve error handling

Reason:

https://gerrit.wikimedia.org/r/1025767

It just came into my mind that the current patches don’t return any information on the status of the translations (language, fuzziness) other than the ability to disable fallbacks. Users of this Lua interface may want to use similar markup as Translate’s page translation feature to indicate that a translation is fuzzy or missing. So I think that given a message key and a language, it should be possible to get a Lua table with the following information (either as table keys or as methods):

  • state: fuzzy, normal, maybe even reviewed
  • language: MediaWiki language code or mw.language object of the actually used language, which may be the requested language, English, or any other fallback language

I’m writing here because I’m not sure which one of the many patches this belongs in, or if a new patch should be added to the end of the relation chain.

Few initial thoughts on this:

  • Whenever direct translations are fetched, those will be referred to by :t() or by translations, else we will use the term messages or :m(), getMessages etc
  • It would be nice to return the Message class objects that we have on PHP, but we will have to see if serialization of a PHP class object to Lua is possible. If not, we will return array from the PHP API and create the Lua Message objects and return that to the developer.
    • Reference code to construct an array of translations / messages can be found in QueryMessageCollectionActionApi class.

Change #1036589 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] WIP: MessageBundleLuaLibrary: Handle parser cache expiry

https://gerrit.wikimedia.org/r/1036589