Page MenuHomeWickedGov Phorge

MessageBundleLuaLibrary.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

MessageBundleLuaLibrary.php

<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\Translate\MessageBundleTranslation;
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase;
use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError;
use MediaWiki\Extension\Translate\Services;
use MediaWiki\MediaWikiServices;
class MessageBundleLuaLibrary extends LibraryBase {
public function register() {
$extensionLuaPath = __DIR__ . '/lua/MessageBundleLibrary.lua';
$lib = [
'validate' => [ $this, 'validate' ],
'getMessageBundleTranslations' => [ $this, 'getMessageBundleTranslations' ]
];
$opts = [
'pageLanguageCode' => $this->getTitle()->getPageLanguage()->getCode()
];
return $this->getEngine()->registerInterface( $extensionLuaPath, $lib, $opts );
}
public function validate( string $messageBundleTitle ): void {
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
$mbTitle = $titleFactory->newFromText( $messageBundleTitle );
if ( !MessageBundle::isSourcePage( $mbTitle ) ) {
throw new LuaError( "$messageBundleTitle is not a valid message bundle." );
}
}
public function getMessageBundleTranslations(
string $messageBundleTitle,
string $languageCode,
bool $skipFallbacks
): array {
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
$messageBundle = new MessageBundle( $titleFactory->newFromText( $messageBundleTitle ) );
$messageBundleTranslationLoader = Services::getInstance()->getMessageBundleTranslationLoader();
if ( !MessageBundle::isSourcePage( $messageBundle->getTitle() ) ) {
throw new LuaError( "Message bundle with title $messageBundleTitle not found" );
}
return [ $messageBundleTranslationLoader->get( $messageBundle, $languageCode, $skipFallbacks ) ];
}
}

File Metadata

Mime Type
text/x-php
Expires
Aug 16 2026, 12:41 (11 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
94/03/6dfe54fe99a14b55962c73a997de
Default Alt Text
MessageBundleLuaLibrary.php (1 KB)

Event Timeline