I see that ZMultiLingualString->internalGetStringForLanguage returns a structure with a title and a language string:
~~https://gerrit.wikimedia.org/g/mediawiki/extensions/WikiLambda/+/89c663692f8a4503bf4f0f293af4e3ea290f9fae/includes/ZObjects/ZMultiLingualString.php#205~~
But it sounds to me familiar with ZMonoLingualString (which holds a Z_MONOLINGUALSTRING_LANGUAGE and a Z_MONOLINGUALSTRING_VALUE properties). Does it make sense to return an instance of this class or not? If it does, I can open an issue and provide a pull-request :)
I would tend to return a structure which would look like the Message class, so with it we may:
- define a placeholder text to use (instead of the use of $isTItle + $returnPlaceholder) using a setPlaceholder($placeholder: string) function;
- set a flag so we may fallback to English or not (LanguageFallback::MESSAGES VS LanguageFallback::STRICT) ;
- get the return type we want using a method (like value() to get the string value only and zMonolingualString() to get the whole ZMonolingual instance)
This would remove the flag arguments and remove the getStringForLanguage, getStringForLanguageOrEnglish and getStringAndLanguageCode methods. This would, I would say, make the code more expressive in the call sites.
Here is an example for how we may lookup a string given a locale:
// instead of using getStringAndLanguageCode $stringAndLanguage = $zMultiLingualString ->buildStringForLanguage($lang) // This returns some structure which implements the below methods (`fallbackWithEnglish()`, `placeholderWith()`, `getStringAndLanguageCode()`) ->fallbackWithEnglish() ->placeholderWith('wikilambda-editor-default-name') // we may otherwise add a `placeholderForTitle()` method ->getStringAndLanguageCode(); // No placeholder nor english fallback $strictStringAndLanguage = $zMultiLingualString->buildStringForLanguage($lang)->getStringAndLanguageCode(); // instead of using getStringForLanguage $string = $zMultiLingualString ->buildStringForLanguage($lang) ->placeholderWith('wikilambda-multilingualstring-nofallback') // or `placeholderNoFallback()` ->getString();