20 public const NO_FFS_CLASS = 1;
21 public const INVALID_FFS_CLASS = 2;
23 protected $reverseCodeMap;
34 string $targetPattern =
''
38 'class' => self::class,
39 'id' => $group->
getId(),
44 'sourcePattern' =>
'',
45 'targetPattern' => $targetPattern,
50 if ( !$group instanceof
self ) {
51 $actual = get_class( $group );
52 throw new DomainException(
"Expected FileBasedMessageGroup, got $actual" );
59 $class = $this->getFromConf(
'FILES',
'class' );
61 if ( $class ===
null ) {
62 throw new RuntimeException(
'FFS class is not set.', self::NO_FFS_CLASS );
65 if ( !class_exists( $class ) ) {
66 throw new RuntimeException(
"FFS class $class does not exist.", self::INVALID_FFS_CLASS );
69 return new $class( $this );
73 return $this->getMessageGroupCache( $this->getSourceLanguage() )->exists();
76 public function load( $code ) {
77 $ffs = $this->getFFS();
78 $data = $ffs->read( $code );
80 return $data ? $data[
'MESSAGES'] : [];
89 $supportedKeys = [
'MESSAGES',
'AUTHORS',
'EXTRA' ];
91 $parsedData = $this->getFFS()->read( $code );
95 foreach ( $supportedKeys as $key ) {
96 $data[$key] = $parsedData[$key] ?? [];
108 if ( $this->isSourceLanguage( $code ) ) {
109 $pattern = $this->getFromConf(
'FILES',
'definitionFile' );
110 if ( $pattern !==
null ) {
111 return $this->replaceVariables( $pattern, $code );
115 $pattern = $this->getFromConf(
'FILES',
'sourcePattern' );
116 if ( $pattern ===
null ) {
117 throw new MWException(
'No source file pattern defined.' );
120 return $this->replaceVariables( $pattern, $code );
123 public function getTargetFilename( $code ) {
125 $pattern = $this->getFromConf(
'FILES',
'targetPattern' );
126 if ( $pattern !==
null ) {
127 return $this->replaceVariables( $pattern, $code );
131 if ( $this->isSourceLanguage( $code ) ) {
132 $pattern = $this->getFromConf(
'FILES',
'definitionFile' );
136 if ( $pattern ===
null ) {
137 $pattern = $this->getFromConf(
'FILES',
'sourcePattern' );
140 if ( $pattern ===
null ) {
141 throw new MWException(
'No source file pattern defined.' );
147 $pattern = str_replace(
'%GROUPROOT%',
'.', $pattern );
148 return $this->replaceVariables( $pattern, $code );
158 global $IP, $wgTranslateGroupRoot;
161 '%CODE%' => $this->mapCode( $code ),
163 '%GROUPROOT%' => $wgTranslateGroupRoot,
164 '%GROUPID%' => $this->getId(),
167 return str_replace( array_keys( $variables ), array_values( $variables ), $pattern );
175 if ( !isset( $this->conf[
'FILES'][
'codeMap'] ) ) {
179 if ( isset( $this->conf[
'FILES'][
'codeMap'][$code] ) ) {
180 return $this->conf[
'FILES'][
'codeMap'][$code];
182 if ( !isset( $this->reverseCodeMap ) ) {
183 $this->reverseCodeMap = array_flip( $this->conf[
'FILES'][
'codeMap'] );
186 if ( isset( $this->reverseCodeMap[$code] ) ) {
187 return 'x-invalidLanguageCode';
204 '_not_empty' =>
true,
208 '_ignore_extra_keys' =>
true,
211 'definitionFile' => [
216 '_not_empty' =>
true,
232 $cache = $this->getMessageGroupCache( $this->getSourceLanguage() );
233 if ( !$cache->exists() ) {
234 return array_keys( $this->getDefinitions() );
236 return $cache->getKeys();
242 $namespace = $this->getNamespace();
245 $cache = $this->getMessageGroupCache( $this->getSourceLanguage() );
246 if ( $cache->exists() ) {
247 foreach ( $cache->getKeys() as $key ) {
248 $messages[$key] = $cache->get( $key );
253 $collection = MessageCollection::newFromDefinitions( $definitions, $code );
254 $this->setTags( $collection );
261 $cache = $this->getMessageGroupCache( $code );
262 if ( $cache->exists() ) {
263 $msg = $cache->get( $key );
265 if ( $msg !==
false ) {
270 $nkey = str_replace(
' ',
'_', strtolower( $key ) );
271 $keys = $cache->getKeys();
273 foreach ( $keys as $k ) {
274 if ( $nkey === str_replace(
' ',
'_', strtolower( $k ) ) ) {
275 return $cache->get( $k );
287 "translate_groupcache-{$this->getId()}/{$code}.cdb"
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array