[go: up one dir, main page]

Page MenuHomePhabricator

Lua interface for convenient access to translations in a message bundle
Closed, ResolvedPublic16 Estimated Story Points

Description

Wikimedia projects extensively use templates and Lua modules for critical features like infoboxes, and welcome messages. These are developed by skilled community members and are essential for the functionality and user experience across multiple languages. Despite their complexity and importance, templates and modules lack a framework for internationalization and localization, unlike MediaWiki extensions.

This video goes over the problem that we are trying to solve in more detail:
https://www.mediawiki.org/wiki/File:Wikimedia_Language_showcase_September_2020.webm

You can also read: https://www.mediawiki.org/wiki/Translatable_modules

Create a Lua module that will allow modules to access the strings defined in a message bundle.

Current status

The functionality is enabled on testwiki.

Some notes for testing out the functionality: https://www.mediawiki.org/wiki/User:APatro_(WMF)/Message_Bundle_Lua_Integration/Testing

Details

SubjectRepoBranchLines +/-
operations/mediawiki-configmaster+6 -0
translatewikimaster+3 -0
mediawiki/extensions/Translatemaster+2 -1
mediawiki/extensions/Translatemaster+121 -0
mediawiki/extensions/Translatemaster+14 -18
mediawiki/extensions/Translatemaster+14 -5
mediawiki/extensions/Translatemaster+13 -5
mediawiki/extensions/Translatemaster+37 -12
mediawiki/extensions/Translatemaster+5 -2
mediawiki/extensions/Translatemaster+2 -1
mediawiki/extensions/Translatemaster+6 -3
mediawiki/extensions/Translatemaster+66 -8
mediawiki/extensions/Translatemaster+17 -10
mediawiki/extensions/Translatemaster+37 -6
mediawiki/extensions/Translatemaster+16 -0
mediawiki/extensions/Translatemaster+122 -2
mediawiki/extensions/Translatemaster+25 -5
mediawiki/extensions/Translatemaster+4 -0
integration/configmaster+1 -1
integration/configmaster+1 -1
Show related patches Customize query in gerrit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

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

Change #1020856 merged by jenkins-bot:

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

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

Change #1031591 merged by jenkins-bot:

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

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

Change #1023116 merged by jenkins-bot:

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

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

Change #1025380 merged by jenkins-bot:

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

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

Change #1031592 merged by jenkins-bot:

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

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

Change #1034082 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] MessageBundleLuaLibrary: Add page language code in module options

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

Hi, for Tech News, please could someone advise on the wording and timing of the entry?
I see it is tagged as 1.43.0-wmf.11 and hence rolling out next week, but I'm not sure if it needs to be announced in the upcoming edition, or if there's perhaps a good reason to delay it by a week or more (e.g. to write/update any related documentation that we'd link to from the entry). Thanks.

While some changes have been merged, others are still under review. The not yet merged MessageBundleLibrary.lua: Return message object from t() method is a breaking change; we shouldn’t encourage people to use the feature (so it shouldn’t be announced in Tech News) before that gets merged.

Hi, for Tech News, please could someone advise on the wording and timing of the entry?
I see it is tagged as 1.43.0-wmf.11 and hence rolling out next week, but I'm not sure if it needs to be announced in the upcoming edition, or if there's perhaps a good reason to delay it by a week or more (e.g. to write/update any related documentation that we'd link to from the entry). Thanks.

Hi @Quiddity, thanks for surfacing this.

This is still in development and the feature is disabled by default. We plan to take feedback about the API from the community with the feature enabled on translatewiki.net.

The documentation around this is also still a WIP. I'll comment on this task when its read to be announced.

Change #1034083 merged by jenkins-bot:

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

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

Change #1034084 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Return message object from t() method

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

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

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Remove API access to skipFallback param

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

Change #1034085 merged by jenkins-bot:

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

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

Change #1035356 merged by jenkins-bot:

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

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

Change #1049885 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Remove API access to skipFallback param

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

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

[mediawiki/extensions/Translate@master] MessageBundleLibrary: Code improvements

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

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

[translatewiki@master] Enable message bundle and Scribunto Lua module integration

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

Change #1049967 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] MessageBundleLibrary.lua: Code improvements

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

Documentation about the Module API: https://www.mediawiki.org/wiki/User:APatro_(WMF)/Message_Bundle_Lua_Integration

Some challenges: https://www.mediawiki.org/wiki/User:APatro_(WMF)/Message_Bundle_Lua_Integration/Challenges

Still waiting to be enabled on translatewiki.net in order to request for community feedback.

We've set-up a test instance on https://language-translate.wmcloud.org/index.php/Main_Page where the message bundle integration with Lua modules is enabled. The feature can be tested there. Registrations are not open so please drop me a message here to get access. We're working on have PluggableAuth + WSOAuth setup (T366934)

Waiting for review on 1036589: MessageBundleLuaLibrary: Handle parser cache expiry for dependents | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Translate/+/1036589 before deploying this on translatewiki.net

Change #1036589 merged by jenkins-bot:

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

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

Waiting for review on 1036589: MessageBundleLuaLibrary: Handle parser cache expiry for dependents | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Translate/+/1036589 before deploying this on translatewiki.net

Patch is now merged and deployed on translatewiki.net and on https://language-translate.wmcloud.org/index.php/Main_Page. Needs QA. I'll be doing it.

Tested with the following setup on translatewiki.net:

I then tried to use it in https://translatewiki.net/wiki/User:Abijeet_Patro/LuaTestPage but I don't see the translations from the message bundle appearing.

Needs more investigation.

I made an edit to the module to make the messages appear. However, what I had to make is definitely not good… Looks like the message ID gets a namespace prefix somewhere, which it definitely shouldn’t. (By the way, mw.logObject(mb:getAllTranslations()) helped a log during the debugging.)

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

[mediawiki/extensions/Translate@master] MessageBundle: When normalizing translation key remove prefixed title key

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

Change #1087864 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] MessageBundle: When normalizing translation key remove prefixed title

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

Change #1050026 abandoned by Abijeet Patro:

[translatewiki@master] Enable message bundle and Scribunto Lua module integration

Reason:

In favor of I2d9d4b7e3dda18a295de945b138dea8b4fce9ccd

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

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

[operations/mediawiki-config@master] Translate: Enable message bundle Scribunto module

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

I made an edit to the module to make the messages appear. However, what I had to make is definitely not good… Looks like the message ID gets a namespace prefix somewhere, which it definitely shouldn’t. (By the way, mw.logObject(mb:getAllTranslations()) helped a log during the debugging.)

Thanks, we made a change to fix this. I "undid" your edit and things work as expected

Change #1087914 merged by jenkins-bot:

[operations/mediawiki-config@master] Translate: Enable message bundle Scribunto module on testwiki

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

Mentioned in SAL (#wikimedia-operations) [2024-11-07T08:07:30Z] <kartik@deploy2002> Started scap sync-world: Backport for [[gerrit:1087914|Translate: Enable message bundle Scribunto module on testwiki (T359918)]]

Mentioned in SAL (#wikimedia-operations) [2024-11-07T08:13:09Z] <kartik@deploy2002> kartik, abi: Backport for [[gerrit:1087914|Translate: Enable message bundle Scribunto module on testwiki (T359918)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2024-11-07T08:26:09Z] <kartik@deploy2002> Finished scap sync-world: Backport for [[gerrit:1087914|Translate: Enable message bundle Scribunto module on testwiki (T359918)]] (duration: 18m 39s)

Thanks, we made a change to fix this. I "undid" your edit and things work as expected

Thanks! (Next time, feel free to do a real undo: I don’t mind having my edits reverted, as long as there’s a good reason for that.)

QA Note: Waiting for deployment and testing on Testwiki. I'll be doing the QA myself.

Nikerabbit changed the task status from Open to In Progress.Mon, Nov 11, 9:28 AM
abi_ updated the task description. (Show Details)
abi_ moved this task from Need QA to Done on the LPL Essential (LPL Essential 2024 Nov-Dec) board.