Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make-php: skip strings without translation #389

Merged
merged 1 commit into from
Feb 28, 2024
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
55 changes: 55 additions & 0 deletions features/makephp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,58 @@ Feature: Generate PHP files from PO files
"""
return ['domain'=>'foo-plugin','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Foo Plugin','pot-creation-date'=>'2018-05-02T22:06:24+00:00','po-revision-date'=>'2018-05-02T22:06:24+00:00','messages'=>['Plugin NameFoo Plugin (EN)'=>'Foo Plugin (DE)','Foo Plugin'=>'Bar Plugin','You have %d new message'=>'Sie haben %d neue Nachricht' . "\0" . 'Sie haben %d neue Nachrichten']];
"""

Scenario: Excludes strings without 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 <[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"

#: foo-plugin.php:10
msgid "I exist"
msgstr "I exist (DE)"

#: foo-plugin.php:20
msgid "I am empty"
msgstr ""

#: foo-plugin.php:30
msgid "You have %d new message"
msgid_plural "You have %d new messages"
msgstr[0] ""
msgstr[1] ""
"""

When I run `wp i18n make-php foo-plugin`
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:
"""
I exist
"""
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
"""
I am empty
"""
And the foo-plugin/foo-plugin-de_DE.l10n.php file should not contain:
"""
new message
"""
2 changes: 1 addition & 1 deletion src/PhpArrayGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected static function toArray( Translations $translations, $include_headers,
* @var Translation $translation
*/
foreach ( $translations as $translation ) {
if ( $translation->isDisabled() ) {
if ( $translation->isDisabled() || ! $translation->hasTranslation() ) {
continue;
}

Expand Down