LanguageNameIndexer: Simplify code

Inline one loop and remove autonym handling since getting the
translation of a language name in its own language gives the
autonym.

Change-Id: I0c8ff8e3ce0c7f23d123656b091df37aa71b2cd7
This commit is contained in:
Niklas Laxström
2016-06-15 10:04:07 +02:00
parent 9ac675811b
commit 920155fb18
2 changed files with 4 additions and 12 deletions

View File

@@ -33,24 +33,16 @@ class LanguageNameIndexer extends Maintenance {
public function execute() {
$languages = Language::fetchLanguageNames( null, 'all' );
$all = [];
$buckets = [];
foreach ( $languages as $sourceLanguage => $autonym ) {
$all[$sourceLanguage][strtolower( $autonym )] = true;
$translations = LanguageNames::getNames( $sourceLanguage, 0, 2 );
foreach ( $translations as $targetLanguage => $translation ) {
$all[$targetLanguage][] = strtolower( $translation );
$translation = strtolower( $translation );
$bucket = LanguageNameSearch::getIndex( $translation );
$buckets[$bucket][$translation] = $targetLanguage;
}
}
foreach ( $all as $targetLanguage => $names ) {
foreach ( $names as $name ) {
$bucket = LanguageNameSearch::getIndex( $name );
$buckets[$bucket][$name] = $targetLanguage;
}
}
$this->output( 'Total buckets: ' . count( $buckets ) . "\n" );
file_put_contents( 'langnames.ser', serialize( $buckets ) );
}

File diff suppressed because one or more lines are too long