Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions features/makephp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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:
"""
[,
"""

4 changes: 4 additions & 0 deletions src/PhpArrayGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down