i18n-command/features/makemo.feature
copilot-swe-agent[bot] 7acb9fdfe0 Add validation tests for make-mo, make-php, and make-json commands
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
2026-02-14 22:41:36 +00:00

304 lines
9.7 KiB
Gherkin

Feature: Generate MO files from PO files
Background:
Given an empty directory
Scenario: Bail for invalid source directories
When I try `wp i18n make-mo foo`
Then STDERR should contain:
"""
Error: Source file or directory does not exist.
"""
And the return code should be 1
Scenario: Bail for destination being a file when source is a folder
Given an empty foo directory
And a foo/foo.po file:
"""
"""
When I try `wp i18n make-mo foo test.mo `
Then STDERR should contain:
"""
Error: Destination file not supported when source is a directory.
"""
And the return code should be 1
Scenario: Uses source folder as destination by default
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"
#: foo-plugin.js:15
msgid "Foo Plugin"
msgstr "Foo Plugin"
"""
When I run `wp i18n make-mo 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.mo file should exist
Scenario: Uses the provided destination file name
Given a foo.po file:
"""
"""
When I run `wp i18n make-mo foo.po bar.mo`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the bar.mo file should exist
Scenario: Uses the provided destination file name with no extension
Given a foo.po file:
"""
"""
When I run `wp i18n make-mo foo.po bar`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the bar file should exist
Scenario: Preserves the provided source name with no destination
Given a foo.po file:
"""
"""
When I run `wp i18n make-mo foo.po`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the foo.mo file should exist
Scenario: Allows setting custom destination directory
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"
#: foo-plugin.js:15
msgid "Foo Plugin"
msgstr "Foo Plugin"
"""
When I run `wp i18n make-mo foo-plugin result`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And the return code should be 0
And the result/foo-plugin-de_DE.mo file should exist
Scenario: Does include headers
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"
#: foo-plugin.js:15
msgid "Foo Plugin"
msgstr "Foo Plugin"
"""
When I run `wp i18n make-mo 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.mo file should contain:
"""
Language: de_DE
"""
And the foo-plugin/foo-plugin-de_DE.mo file should contain:
"""
X-Domain: foo-plugin
"""
Scenario: Does include 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"
#: foo-plugin.php:15
msgid "Foo Plugin"
msgstr "Bar Plugin"
"""
When I run `wp i18n make-mo 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.mo file should contain:
"""
Bar Plugin
"""
Scenario: Excludes JS-only strings from MO files
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"
#: foo-plugin.js:15
msgid "JS Only String"
msgstr "JS Only Translation"
#: foo-plugin.php:10
msgid "PHP String"
msgstr "PHP Translation"
#: foo-plugin.js:20
#: foo-plugin.php:15
msgid "Both JS and PHP"
msgstr "Both Translation"
"""
When I run `wp i18n make-mo 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.mo file should exist
And the foo-plugin/foo-plugin-de_DE.mo file should contain:
"""
PHP Translation
"""
And the foo-plugin/foo-plugin-de_DE.mo file should contain:
"""
Both Translation
"""
And the foo-plugin/foo-plugin-de_DE.mo file should not contain:
"""
JS Only Translation
"""
Scenario: Prints validation warnings for strings with placeholders
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"
#: foo-plugin.php:10
msgid "Hello, %s"
msgstr "Hallo, %s"
#: foo-plugin.php:15
msgid "One Comment"
msgid_plural "%s Comments"
msgstr[0] "Ein Kommentar"
msgstr[1] "%s Kommentare"
"""
When I try `wp i18n make-mo foo-plugin`
Then STDOUT should contain:
"""
Success: Created 1 file.
"""
And STDERR should contain:
"""
Warning: The string "Hello, %s" contains placeholders but has no "translators:" comment to clarify their meaning. (foo-plugin.php:10)
"""
And STDERR should contain:
"""
Warning: Missing singular placeholder, needed for some languages. See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plurals (foo-plugin.php:15)
"""
And the return code should be 0
And the foo-plugin/foo-plugin-de_DE.mo file should exist