From caab22e5b2bcaf8fe6f88b31151b0407319701a4 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 1 Jul 2015 15:42:32 +0000 Subject: [PATCH] l10n: Update `wp_get_installed_translations()` to support variants of a language. * A variant of a language has its own locale, for example the locale of the formal variant of German is `de_DE_formal`. * Update `remove_accents()` and some CSS rules to support `de_DE_formal`. * Add tests for `get_bloginfo( 'language' )`. * API changes will be deployed over the next few days. see #28303. git-svn-id: https://develop.svn.wordpress.org/trunk@33027 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/l10n.css | 12 +++++--- src/wp-includes/formatting.php | 2 +- src/wp-includes/l10n.php | 2 +- tests/phpunit/tests/formatting/BlogInfo.php | 34 +++++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/tests/formatting/BlogInfo.php diff --git a/src/wp-admin/css/l10n.css b/src/wp-admin/css/l10n.css index ea8dc199fb..6c5895a91c 100644 --- a/src/wp-admin/css/l10n.css +++ b/src/wp-admin/css/l10n.css @@ -58,16 +58,20 @@ body.locale-he-il .press-this a.wp-switch-editor { .locale-zh-cn #sort-buttons { font-size: 1em !important; } /* de_DE: Text needs more space for translation */ -.locale-de-de .inline-edit-row fieldset label span.title { +.locale-de-de .inline-edit-row fieldset label span.title, +.locale-de-de-formal .inline-edit-row fieldset label span.title { width: 7em; /* default 5em */ } -.locale-de-de .inline-edit-row fieldset label span.input-text-wrap { +.locale-de-de .inline-edit-row fieldset label span.input-text-wrap, +.locale-de-de-formal .inline-edit-row fieldset label span.input-text-wrap { margin-left: 7em; /* default 5em */ } -.locale-de-de #customize-header-actions .button { +.locale-de-de #customize-header-actions .button, +.locale-de-de-formal #customize-header-actions .button { padding: 0 5px 1px; /* default 0 10px 1px */ } -.locale-de-de #customize-header-actions .spinner { +.locale-de-de #customize-header-actions .spinner, +.locale-de-de-formal #customize-header-actions .spinner { margin: 16px 3px 0; /* default 16px 4px 0 5px */ } diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 8578ad1e6c..bbd3e4bffc 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -1138,7 +1138,7 @@ function remove_accents( $string ) { // Used for locale-specific rules $locale = get_locale(); - if ( 'de_DE' == $locale ) { + if ( 'de_DE' == $locale || 'de_DE_formal' == $locale ) { $chars[ chr(195).chr(132) ] = 'Ae'; $chars[ chr(195).chr(164) ] = 'ae'; $chars[ chr(195).chr(150) ] = 'Oe'; diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 033310a88d..defe76c53c 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -820,7 +820,7 @@ function wp_get_installed_translations( $type ) { if ( substr( $file, -3 ) !== '.po' ) { continue; } - if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) ) { + if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { continue; } if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) { diff --git a/tests/phpunit/tests/formatting/BlogInfo.php b/tests/phpunit/tests/formatting/BlogInfo.php new file mode 100644 index 0000000000..9611bc635b --- /dev/null +++ b/tests/phpunit/tests/formatting/BlogInfo.php @@ -0,0 +1,34 @@ +assertEquals( $expected, get_bloginfo( 'language' ) ); + + $locale = $old_locale; + } + + function locales() { + return array( + // Locale Language code + array( 'en_US', 'en-US' ), + array( 'ar', 'ar' ), + array( 'de_DE', 'de-DE' ), + array( 'de_DE_formal', 'de-DE-formal' ), + array( 'oci', 'oci' ), + array( 'pt_PT_ao1990', 'pt-PT-ao1990' ), + ); + } +}