Skip to content

Commit

Permalink
update-po: merge X-Domain header
Browse files Browse the repository at this point in the history
Adds the header if missing or overrides existing one
  • Loading branch information
swissspidy committed Feb 20, 2025
1 parent bf6720f commit d230603
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions features/updatepo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,80 @@ Feature: Update existing PO files from a POT file
Error: Destination file/folder does not exist.
"""
And the return code should be 1

Scenario: Empty target PO file
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.pot file:
"""
# Copyright (C) 2018 Foo Plugin
# This file is distributed under the same license as the Foo Plugin package.
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
"X-Domain: foo-plugin\n"
#. translators: New Comment.
#: foo-plugin.php:1
msgid "Some string"
msgstr ""
#: foo-plugin.php:15
msgid "Another new string"
msgstr ""
"""
And a foo-plugin/foo-plugin-de_DE.po file:
"""
# Copyright (C) 2018 Foo Plugin
# This file is distributed under the same license as the Foo Plugin package.
msgid ""
msgstr ""
"Project-Id-Version: Foo Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
"X-Domain: foo-plugin\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. translators: Old Comment.
#: foo-plugin.php:10
msgid "Some string"
msgstr "Some translated string"
"""
And a foo-plugin/foo-plugin-es_ES.po file:
"""
"""

When I run `wp i18n update-po foo-plugin/foo-plugin.pot foo-plugin/foo-plugin-de_DE.po`
Then STDOUT should be:
"""
Success: Updated 1 file.
"""
And the foo-plugin/foo-plugin-de_DE.po file should contain:
"""
#. translators: New Comment.
#: foo-plugin.php:1
msgid "Some string"
msgstr "Some translated string"
#: foo-plugin.php:15
msgid "Another new string"
msgstr ""
"""
And the foo-plugin/foo-plugin-de_DE.po file should contain:
"""
"X-Domain: foo-plugin\n"
"""
2 changes: 1 addition & 1 deletion src/UpdatePoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __invoke( $args, $assoc_args ) {
$po_translations = Translations::fromPoFile( $file->getPathname() );
$po_translations->mergeWith(
$pot_translations,
Merge::ADD | Merge::REMOVE | Merge::COMMENTS_THEIRS | Merge::EXTRACTED_COMMENTS_THEIRS | Merge::REFERENCES_THEIRS
Merge::ADD | Merge::REMOVE | Merge::COMMENTS_THEIRS | Merge::EXTRACTED_COMMENTS_THEIRS | Merge::REFERENCES_THEIRS | Merge::DOMAIN_OVERRIDE
);

if ( ! $po_translations->toPoFile( $file->getPathname() ) ) {
Expand Down

0 comments on commit d230603

Please sign in to comment.