33 protected function __construct() {
42 $obj =
new $conf[
'BASIC'][
'class']();
44 $obj->namespace = $obj->parseNamespace();
49 public function getConfiguration() {
54 return $this->getFromConf(
'BASIC',
'id' );
57 public function getLabel( IContextSource $context =
null ) {
58 return $this->getFromConf(
'BASIC',
'label' );
62 return $this->getFromConf(
'BASIC',
'description' );
66 return $this->getFromConf(
'BASIC',
'icon' );
70 return $this->namespace;
74 return $this->getFromConf(
'BASIC',
'meta' );
78 $conf = $this->getFromConf(
'BASIC',
'sourcelanguage' );
89 protected function getFromConf( $section, $key =
null ) {
90 if ( $key ===
null ) {
91 return $this->conf[$section] ??
null;
93 return $this->conf[$section][$key] ??
null;
97 $validatorConfigs = $this->getFromConf(
'VALIDATORS' );
98 if ( $validatorConfigs ===
null ) {
104 foreach ( $validatorConfigs as $config ) {
106 $msgValidator->addValidator( $config );
107 }
catch ( Exception $e ) {
108 $id = $this->
getId();
109 throw new InvalidArgumentException(
110 "Unable to construct validator for message group $id: " . $e->getMessage(),
117 return $msgValidator;
121 if ( !isset( $this->mangler ) ) {
122 $class = $this->getFromConf(
'MANGLER',
'class' ) ?? StringMatcher::class;
124 if ( $class ===
'StringMatcher' || $class === StringMatcher::class ) {
126 $manglerConfig = $this->conf[
'MANGLER'] ??
null;
127 if ( $manglerConfig ) {
128 $this->mangler->setConf( $manglerConfig );
131 return $this->mangler;
134 throw new InvalidArgumentException(
135 'Unable to create StringMangler for group ' . $this->
getId() .
': ' .
136 "Custom StringManglers ($class) are currently not supported."
140 return $this->mangler;
150 $insertableConf = $this->getFromConf(
'INSERTABLES' ) ?? [];
152 foreach ( $insertableConf as $config ) {
153 if ( !isset( $config[
'class'] ) ) {
154 throw new InvalidArgumentException(
155 'Insertable configuration for group: ' . $this->
getId() .
156 ' does not provide a class.'
160 if ( !is_string( $config[
'class'] ) ) {
161 throw new InvalidArgumentException(
162 'Expected Insertable class to be string, got: ' . gettype( $config[
'class'] ) .
163 ' for group: ' . $this->
getId()
167 $suggesters[] = InsertableFactory::make( $config[
'class'], $config[
'params'] ?? [] );
172 if ( $messageValidator ) {
173 $suggesters = array_merge( $suggesters, $messageValidator->getInsertableValidators() );
185 if ( $type ===
null ) {
188 foreach ( $this->getRawTags() as $type => $patterns ) {
189 $taglist[$type] = $this->parseTags( $patterns );
194 return $this->parseTags( $this->getRawTags( $type ) );
198 protected function parseTags( $patterns ) {
199 $messageKeys = $this->getKeys();
206 foreach ( $patterns as $index => $pattern ) {
207 if ( strpos( $pattern,
'*' ) ===
false ) {
208 $matches[] = $pattern;
209 unset( $patterns[$index] );
213 if ( count( $patterns ) ) {
222 foreach ( $messageKeys as $key ) {
223 if ( $mangler->matches( $key ) ) {
232 protected function getRawTags( $type =
null ) {
233 if ( !isset( $this->conf[
'TAGS'] ) ) {
237 $tags = $this->conf[
'TAGS'];
242 return $tags[$type] ?? [];
246 foreach ( $this->
getTags() as $type => $tags ) {
247 $collection->
setTags( $type, $tags );
251 protected function parseNamespace() {
252 $ns = $this->getFromConf(
'BASIC',
'namespace' );
254 if ( is_int( $ns ) ) {
258 if ( defined( $ns ) ) {
259 return constant( $ns );
262 $index = MediaWikiServices::getInstance()->getContentLanguage()
266 throw new MWException(
"No valid namespace defined, got $ns." );
272 protected function isSourceLanguage( $code ) {
281 global $wgTranslateWorkflowStates;
282 $conf = $wgTranslateWorkflowStates ?: [];
284 Hooks::run(
'Translate:modifyMessageGroupStates', [ $this->
getId(), &$conf ] );
291 $groupConfiguration = $this->getConfiguration();
292 if ( !isset( $groupConfiguration[
'LANGUAGES'] ) ) {
297 $codes = array_flip( array_keys( TranslateUtils::getLanguageNames(
null ) ) );
299 $lists = $groupConfiguration[
'LANGUAGES'];
300 $exclusionList = $lists[
'exclude'] ??
null;
301 if ( $exclusionList !==
null ) {
302 if ( $exclusionList ===
'*' ) {
305 } elseif ( is_array( $exclusionList ) ) {
306 foreach ( $exclusionList as $code ) {
307 unset( $codes[$code] );
316 $disabledLanguages = Services::getInstance()->getConfigHelper()->getDisabledTargetLanguages();
319 $checks = [ $this->
getId(), strtok( $this->
getId(),
'-' ),
'*' ];
320 foreach ( $checks as $check ) {
321 if ( isset( $disabledLanguages[ $check ] ) ) {
322 foreach ( array_keys( $disabledLanguages[ $check ] ) as $excludedCode ) {
323 unset( $codes[ $excludedCode ] );
328 $inclusionList = $lists[
'include'] ??
null;
329 if ( $inclusionList !==
null ) {
330 if ( $inclusionList ===
'*' ) {
333 } elseif ( is_array( $inclusionList ) ) {
334 foreach ( $inclusionList as $code ) {
335 $codes[$code] =
true;
344 return $this->getFromConf(
'BASIC',
'support' );
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