12 public function register() {
13 $extensionLuaPath = __DIR__ .
'/lua/MessageBundleLibrary.lua';
15 'validate' => [ $this,
'validate' ],
16 'getMessageBundleTranslations' => [ $this,
'getMessageBundleTranslations' ]
19 'pageLanguageCode' => $this->getTitle()->getPageLanguage()->getCode()
22 return $this->getEngine()->registerInterface( $extensionLuaPath, $lib, $opts );
25 public function validate(
string $messageBundleTitle ):
void {
26 $titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
27 $mbTitle = $titleFactory->newFromText( $messageBundleTitle );
28 if ( !MessageBundle::isSourcePage( $mbTitle ) ) {
29 throw new LuaError(
"$messageBundleTitle is not a valid message bundle." );
33 public function getMessageBundleTranslations(
34 string $messageBundleTitle,
38 $titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
39 $messageBundle =
new MessageBundle( $titleFactory->newFromText( $messageBundleTitle ) );
40 $messageBundleTranslationLoader = Services::getInstance()->getMessageBundleTranslationLoader();
41 if ( !MessageBundle::isSourcePage( $messageBundle->getTitle() ) ) {
42 throw new LuaError(
"Message bundle with title $messageBundleTitle not found" );
45 return [ $messageBundleTranslationLoader->get( $messageBundle, $languageCode, $skipFallbacks ) ];