Skip to content

Commit

Permalink
Plural-Forms retained when copying PO to same language
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Whitlock committed Mar 8, 2022
1 parent a7058b0 commit 9d1d854
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 5 additions & 5 deletions languages/loco-translate.pot
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Loco Translate 2.6.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/loco-translate/\n"
"POT-Creation-Date: 2022-03-07 12:16+0000\n"
"POT-Creation-Date: 2022-03-08 12:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -107,7 +107,7 @@ msgstr[0] ""
msgstr[1] ""

#. Where %s is either PO or POT
#: src/gettext/Compiler.php:243 src/admin/file/HeadController.php:80
#: src/gettext/Compiler.php:239 src/admin/file/HeadController.php:80
#, php-format
msgid "%s file saved"
msgstr ""
Expand Down Expand Up @@ -1053,7 +1053,7 @@ msgstr ""
msgid "It needs configuring before you can do any translations"
msgstr ""

#: src/gettext/Compiler.php:136 src/gettext/Compiler.php:198
#: src/gettext/Compiler.php:136 src/gettext/Compiler.php:194
#, php-format
msgid "JSON compilation failed for %s"
msgstr ""
Expand Down Expand Up @@ -1456,11 +1456,11 @@ msgstr ""
msgid "PO file missing"
msgstr ""

#: src/gettext/Compiler.php:239
#: src/gettext/Compiler.php:235
msgid "PO file saved and MO file compiled"
msgstr ""

#: src/gettext/Compiler.php:236
#: src/gettext/Compiler.php:232
msgid "PO file saved and MO/JSON files compiled"
msgstr ""

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -106,6 +106,7 @@ We don't collect your data or snoop on you. See the [plugin privacy notice](http
* Bumped WordPress version to 5.9.1
* Removed Yandex API integration
* Added loco_compile_script_reference filter
* Plural-Forms retained when copying PO to same language

= 2.5.8 =
* Compatible with PHP 8.1
Expand Down
14 changes: 13 additions & 1 deletion src/gettext/Data.php
Expand Up @@ -221,7 +221,7 @@ public function getSourceDigest(){
* @return Loco_gettext_Data
*/
public function localize( Loco_Locale $locale, array $custom = [] ){
$date = gmdate('Y-m-d H:i').'+0000'; // <- forcing UCT
$date = gmdate('Y-m-d H:i').'+0000';
// headers that must always be set if absent
$defaults = [
'Project-Id-Version' => '',
Expand All @@ -241,6 +241,18 @@ public function localize( Loco_Locale $locale, array $custom = [] ){
'X-Generator' => 'Loco https://localise.biz/',
'X-Loco-Version' => sprintf('%s; wp-%s', loco_plugin_version(), $GLOBALS['wp_version'] ),
];
// Allow some existing headers to remain if PO was previously localized to the same language
$headers = $this->getHeaders();
$previous = Loco_Locale::parse( $headers->trimmed('Language') );
if( $previous->lang === $locale->lang ){
$header = $headers->trimmed('Plural-Forms');
if( preg_match('/^\\s*nplurals\\s*=\\s*\\d+\\s*;\\s*plural\\s*=/', $header) ) {
$required['Plural-Forms'] = $header;
}
if( $previous->region === $locale->region && $previous->variant === $locale->variant ){
unset( $required['Language-Team'] );
}
}
// set user's preferred Last-Translator credit if configured
if( function_exists('get_current_user_id') && get_current_user_id() ){
$prefs = Loco_data_Preferences::get();
Expand Down

0 comments on commit 9d1d854

Please sign in to comment.