Translationcatalog - Source Excerpt 03
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/TranslationCatalog.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/TranslationCatalog.php
foreach ( $candidates as $candidate ) {
if ( is_string( $candidate ) && '' !== $candidate && is_readable( $candidate ) ) {
$paths[ $candidate ] = $candidate;
}
}
return array_values( $paths );
}
/**
* Read one JSON dictionary file.
*
* @param string $file_path Dictionary path.
* @return array|null
*/
private static function read_dictionary_file( $file_path ) {
$contents = file_get_contents( $file_path );
if ( ! is_string( $contents ) || '' === trim( $contents ) ) {
return null;
}
$data = json_decode( $contents, true );
return is_array( $data ) ? $data : null;
}
/**
* Extract direct helper-call strings from a PHP source file.
*
* @param string $contents PHP file contents.
* @param array $strings Runtime string map.
* @return void
*/
private static function extract_helper_call_strings( $contents, array &$strings ) {
$functions = '(?:ui_text|spiralist_get_ui_text|spiralist_render_ui_label|uaixlr_t|ns12lr_t|acnmb_t|acn_cs_t|acn_ui_t)';
$patterns = array(
"/\\b{$functions}\\(\\s*'((?:\\\\.|[^'])+)'\\s*,\\s*'((?:\\\\.|[^'])*)'/s",
"/\\b{$functions}\\(\\s*\"((?:\\\\.|[^\"])+)\"\\s*,\\s*\"((?:\\\\.|[^\"])*)\"/s",
);
$format_functions = '(?:uaixlr_t_format|ns12lr_t_format|acnmb_tf)';
$format_patterns = array(
"/\\b{$format_functions}\\(\\s*'((?:\\\\.|[^'])+)'\\s*,\\s*(?:array\\s*\\(.*?\\)|\\[[\\s\\S]*?\\]|[^,]+)\\s*,\\s*'((?:\\\\.|[^'])*)'/s",
"/\\b{$format_functions}\\(\\s*\"((?:\\\\.|[^\"])+)\"\\s*,\\s*(?:array\\s*\\(.*?\\)|\\[[\\s\\S]*?\\]|[^,]+)\\s*,\\s*\"((?:\\\\.|[^\"])*)\"/s",
);
foreach ( $patterns as $pattern ) {
preg_match_all( $pattern, $contents, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
self::register_runtime_string( $strings, $match[1], $match[2] );
}
}
foreach ( $format_patterns as $pattern ) {
preg_match_all( $pattern, $contents, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
self::register_runtime_string( $strings, $match[1], $match[2] );
}
}
}
/**
* Extract array-pair strings such as labelKey/label or titleKey/title.
*
* @param string $contents PHP file contents.
* @param string $field Base field name.
* @param array $strings Runtime string map.
* @return void
*/
private static function extract_array_pair_strings( $contents, $field, array &$strings ) {
$key_field = preg_quote( $field . 'Key', '/' );
$value_field = preg_quote( $field, '/' );
$patterns = array(
"/['\"]{$key_field}['\"]\\s*=>\\s*'((?:\\\\.|[^'])+)'\\s*,\\s*['\"]{$value_field}['\"]\\s*=>\\s*'((?:\\\\.|[^'])*)'/s",
"/['\"]{$value_field}['\"]\\s*=>\\s*'((?:\\\\.|[^'])*)'\\s*,\\s*['\"]{$key_field}['\"]\\s*=>\\s*'((?:\\\\.|[^'])+)'/s",
"/['\"]{$key_field}['\"]\\s*=>\\s*\"((?:\\\\.|[^\"])+)\"\\s*,\\s*['\"]{$value_field}['\"]\\s*=>\\s*\"((?:\\\\.|[^\"])*)\"/s",
"/['\"]{$value_field}['\"]\\s*=>\\s*\"((?:\\\\.|[^\"])*)\"\\s*,\\s*['\"]{$key_field}['\"]\\s*=>\\s*\"((?:\\\\.|[^\"])+)\"/s",
);
foreach ( $patterns as $index => $pattern ) {
preg_match_all( $pattern, $contents, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
if ( in_array( $index, array( 0, 2 ), true ) ) {
self::register_runtime_string( $strings, $match[1], $match[2] );
} else {
self::register_runtime_string( $strings, $match[2], $match[1] );
}
}
}
}
/**
* Register one runtime string entry.
*
* @param array $strings Runtime string map.
* @param string $runtime_key Stable runtime key.
* @param string $source_text English source text.
* @return void
*/
private static function register_runtime_string( array &$strings, $runtime_key, $source_text ) {
$runtime_key = trim( stripcslashes( (string) $runtime_key ) );
$source_text = trim( stripcslashes( (string) $source_text ) );
if ( '' === $runtime_key || '' === $source_text ) {
return;
}
if ( ! isset( $strings[ $runtime_key ] ) || '' === $strings[ $runtime_key ] ) {
$strings[ $runtime_key ] = $source_text;
}
}
/**
* Normalize an export locale tag, preserving the special template export.
*
* @param string $locale_tag Locale tag.
* @return string
*/
private static function normalize_export_locale( $locale_tag ) {
$locale_tag = trim( (string) $locale_tag );
if ( 'template' === strtolower( $locale_tag ) ) {
return 'template';
}
return LocaleValidator::canonicalize_tag( $locale_tag );
}
}