Dictionariespage - Source Excerpt 03
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/Admin/DictionariesPage.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/Admin/DictionariesPage.php
private static function export_locale_options() {
$english = LocaleRepository::get_supported_locale( 'en-US' );
$options = array(
'en-US' => trim( (string) ( $english['nativeName'] ?? 'English (United States)' ) ),
);
$known = array(
'en-US' => true,
);
foreach ( LocaleRepository::get_supported_locales() as $record ) {
$tag = isset( $record['tag'] ) ? LocaleValidator::canonicalize_tag( $record['tag'] ) : '';
if ( '' === $tag || isset( $known[ $tag ] ) ) {
continue;
}
$label = trim( (string) ( $record['nativeName'] ?? $record['language'] ?? $tag ) );
if ( '' === $label ) {
$label = $tag;
}
$options[ $tag ] = $label . ' (' . $tag . ')';
$known[ $tag ] = true;
}
foreach ( array_keys( DictionaryRepository::dictionary_manifest() ) as $tag ) {
$tag = LocaleValidator::canonicalize_tag( $tag );
if ( '' === $tag || isset( $known[ $tag ] ) ) {
continue;
}
$options[ $tag ] = $tag;
$known[ $tag ] = true;
}
return $options;
}
/**
* Stream a translator-facing dictionary export to the browser.
*
* @param string $locale_tag Locale tag or "template".
* @return void
*/
private static function stream_dictionary_download( $locale_tag ) {
$dictionary = TranslationCatalog::build_translator_dictionary( $locale_tag );
$filename = 'template' === $locale_tag ? 'template.json' : LocaleValidator::canonicalize_tag( $locale_tag ) . '.json';
nocache_headers();
header( 'Content-Type: application/json; charset=utf-8' );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
echo Json::encode( $dictionary );
exit;
}
}