Librarizing the cross-cutting aspects of 18n logic is a prerequisite for librarizing many other components. There have been lots of fragmented discussions about this so filing this task to have a more central place to track it.
(This is about the PHP side only; see T143463 for the Javascript i18n code.)
On the PHP side, the ubiquitous i18n class is Message, which is a bit of a kitchen sink, tightly coupled to database and cache logic; it needs an interface and a minimal implementation that just carries keys and parameters around. MessageSpecifier was an attempt at that, but there seems to be consensus that it's missing a number of necessary features:
- parameter formatting - raw, escaped, number, duration etc. (we might want to consider dropping the XXXParams methods first to simplify things, see T120649#2745260)
- specifying a set of fallback message keys in the same object
- specifying the language
- probably some kind of abstraction for Message::$useDatabase such as cusutomized/default
If message loading/parsing/etc is stripped from the value-object successor of Message, there will be need for some kind of MessageRenderer service interface for taking a message and turning it into a string (or maybe a Message since it's unlikely we can get rid of __toString-based auto-rendering in MediaWiki anytime soon).
The other relevant MediaWiki class is MessageLocalizer, which is basically a Message factory for injecting some of the above settings (language etc) based on global state. Not sure if that would need to be separate from the renderer service.
We might also want to provide a less-minimal implementation that allows using MediaWiki-style i18n features ({{PLURAL}}, {{GENDER}} etc) in non-MediaWiki code (both to provide a nice user experience for our libraries when they are used outside of MediaWiki, and for standalone apps such as PHP-based Toolforge tools).
Prior art:
- https://github.com/Krinkle/intuition (used by various Toolforge tools, including any tools that are based on krinkle/toollabs-base, or wikimedia/ToolforgeBundle).
- https://github.com/Nikerabbit/monkey-i18n.