Skip to content

Commit 011035c

Browse files
Copilotswissspidy
andcommitted
Add automatic PO-Revision-Date update in update-po command
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 3ae4010 commit 011035c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

features/updatepo.feature

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,61 @@ Feature: Update existing PO files from a POT file
465465
"""
466466
"X-Domain: foo-plugin\n"
467467
"""
468+
469+
Scenario: Updates PO-Revision-Date when updating a PO file
470+
Given an empty foo-plugin directory
471+
And a foo-plugin/foo-plugin.pot file:
472+
"""
473+
# Copyright (C) 2018 Foo Plugin
474+
# This file is distributed under the same license as the Foo Plugin package.
475+
msgid ""
476+
msgstr ""
477+
"Project-Id-Version: Foo Plugin\n"
478+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
479+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
480+
"Language-Team: LANGUAGE <LL@li.org>\n"
481+
"MIME-Version: 1.0\n"
482+
"Content-Type: text/plain; charset=UTF-8\n"
483+
"Content-Transfer-Encoding: 8bit\n"
484+
"POT-Creation-Date: 2023-05-02T22:06:24+00:00\n"
485+
"PO-Revision-Date: 2023-05-02T22:06:24+00:00\n"
486+
"X-Domain: foo-plugin\n"
487+
488+
#: foo-plugin.php:1
489+
msgid "Some string"
490+
msgstr ""
491+
"""
492+
And a foo-plugin/foo-plugin-de_DE.po file:
493+
"""
494+
# Copyright (C) 2018 Foo Plugin
495+
# This file is distributed under the same license as the Foo Plugin package.
496+
msgid ""
497+
msgstr ""
498+
"Project-Id-Version: Foo Plugin\n"
499+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/foo-plugin\n"
500+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
501+
"Language-Team: LANGUAGE <LL@li.org>\n"
502+
"Language: de_DE\n"
503+
"MIME-Version: 1.0\n"
504+
"Content-Type: text/plain; charset=UTF-8\n"
505+
"Content-Transfer-Encoding: 8bit\n"
506+
"POT-Creation-Date: 2018-05-02T22:06:24+00:00\n"
507+
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
508+
"X-Domain: foo-plugin\n"
509+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
510+
511+
#: foo-plugin.php:1
512+
msgid "Some string"
513+
msgstr "Some translated string"
514+
"""
515+
516+
When I run `wp i18n update-po foo-plugin/foo-plugin.pot`
517+
Then STDOUT should be:
518+
"""
519+
Success: Updated 1 file.
520+
"""
521+
And STDERR should be empty
522+
And the foo-plugin/foo-plugin-de_DE.po file should not contain:
523+
"""
524+
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
525+
"""

src/UpdatePoCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public function __invoke( $args, $assoc_args ) {
8787
Merge::ADD | Merge::REMOVE | Merge::COMMENTS_THEIRS | Merge::EXTRACTED_COMMENTS_THEIRS | Merge::REFERENCES_THEIRS | Merge::DOMAIN_OVERRIDE
8888
);
8989

90+
// Update PO-Revision-Date to current date and time.
91+
$po_translations->setHeader( 'PO-Revision-Date', gmdate( 'Y-m-d\TH:i:sP' ) );
92+
9093
if ( ! $po_translations->toPoFile( $file->getPathname() ) ) {
9194
WP_CLI::warning( sprintf( 'Could not update file %s', $file->getPathname() ) );
9295
continue;

0 commit comments

Comments
 (0)