User:Daniel Kinzler (WMDE)/I18n-JS

From mediawiki.org

This page describes issues related to i18n in MediaWiki's JavaScript code (both client side and server side).

Observations[edit]

  • Most messages use wikitext formatting
  • Many messages use parameters
  • Message parameters are often used in conjunction with parser functions for plural handling, gendering, date and number formatting, etc.
  • Resolving a message key with parameters to a target string can be done easily enough with an web API call, but this does not scale for a UI with hundreds of messages, even if the API call is done between processes on the same server.
  • Loading all messages needed by the UI would be straight forward if each UI module declared in advance which messages it needs, but raw messages would still need to have parameter substitution applied (easy) and be parsed into HTML (hard).
  • It may be possible to create a JS framework that allows all messages that need rendering to be collected (together with any parameters) and send to the server for processing in a single batch.
  • Re-implementation of full wikitext parsing in JS is not feasible.
  • Re-implementation of a subset of wikitext parsing in JS may be feasible.
  • Messages may make use of parser functions and tags implemented by extensions in PHP. Extensions would have to also provide a JS implementation for these, to make them usable in messages.

Status Quo[edit]

  • wikimedia/jquery.i18n supports explicit message loading, parameter substitution, and plurals. It only has very limited wikitext support (essentially, links and nothing else).
  • mw.message supports explicit message loading, parameter substitution, and limited wikitext, including PLURAL, GENDER, GRAMMAR, and FORMATNUM. This ties in with the ResourceLoader mechanism for batch loading.

Questions[edit]

  • How do the two existing i18n systems relate to each other?
  • What percentage of existing messages can be processed correctly by either of the existing JS based solutions?
  • Do the existing solutions ever call out to the MediaWiki web API for processing, or is it all pure JS?

Suggestions[edit]

  • Define a "clean" subset of wikitext for use in messages, and implement it in JS
  • Ensure that (nearly?) all messages only use that subset.
  • Provide a web API for resolving messages that require full wikitext processing.