From 85d00fba33c13c33defd24b40ef741b2ff940ecd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 19:36:56 +0000 Subject: [PATCH 1/2] Initial plan From e65f9e06ea950a7445a5ff8c4824448b39c84bf0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 20:24:09 +0000 Subject: [PATCH 2/2] Fix make-php --pretty-print producing invalid PHP for empty messages array Agent-Logs-Url: https://github.com/wp-cli/i18n-command/sessions/ca6cbde1-7e55-4c9f-a0d0-6ef18f8bcfb5 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/makephp.feature | 37 +++++++++++++++++++++++++++++++++++++ src/PhpArrayGenerator.php | 4 ++++ 2 files changed, 41 insertions(+) diff --git a/features/makephp.feature b/features/makephp.feature index 49967a11..eda279cc 100644 --- a/features/makephp.feature +++ b/features/makephp.feature @@ -363,3 +363,40 @@ Feature: Generate PHP files from PO files JS Only Translation """ + Scenario: Should create valid PHP files with pretty-print when there are no translations + Given an empty foo-plugin directory + 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 \n" + "Language-Team: LANGUAGE \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" + """ + + When I run `wp i18n make-php foo-plugin --pretty-print` + Then STDOUT should contain: + """ + Success: Created 1 file. + """ + And the return code should be 0 + And the foo-plugin/foo-plugin-de_DE.l10n.php file should contain: + """ + 'messages' => [], + """ + And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain: + """ + [, + """ + diff --git a/src/PhpArrayGenerator.php b/src/PhpArrayGenerator.php index ddfc824d..b757b9df 100644 --- a/src/PhpArrayGenerator.php +++ b/src/PhpArrayGenerator.php @@ -174,6 +174,10 @@ private static function var_export( $value, $pretty_print = false, $indent_level } } + if ( empty( $entries ) ) { + return '[]'; + } + return '[' . PHP_EOL . implode( $separator, $entries ) . ',' . PHP_EOL . $closing_indent . ']'; } else { foreach ( $value as $key => $val ) {