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

block.json string extraction #210

Merged
merged 17 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 14 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
388 changes: 388 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2458,3 +2458,391 @@ Feature: Generate a POT file of a WordPress project
Success: POT file successfully generated!
"""
And the contents of the result.pot file should match /^msgid/

Scenario: Extract strings from block.json files
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"parent": [ "core/group" ],
"icon": "star",
"description": "Shows warning, error or success notices ...",
"keywords": [ "alert", "message" ],
"textDomain": "foo-plugin",
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
"attributes": {
"message": {
"type": "string",
"source": "html",
"selector": ".message"
}
},
"styleVariations": [
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
],
"editorScript": "build/editor.js",
"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
"""

When I try `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block title"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Notice"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block description"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Shows warning, error or success notices ..."
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block keyword"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "alert"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "message"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block style variation"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Default"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block style variation"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Other"
"""

Scenario: Extract strings from block.json files with styleVariations alias
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"parent": [ "core/group" ],
"icon": "star",
"description": "Shows warning, error or success notices ...",
"keywords": [ "alert", "message" ],
"textDomain": "foo-plugin",
"attributes": {
"message": {
"type": "string",
"source": "html",
"selector": ".message"
}
},
"styles": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
],
"editorScript": "build/editor.js",
"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
"""

When I try `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block title"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Notice"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block description"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Shows warning, error or success notices ..."
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block keyword"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "alert"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "message"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block style variation"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Default"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block style variation"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Other"
"""

Scenario: Ignores block.json files with other text domain
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"parent": [ "core/group" ],
"icon": "star",
"description": "Shows warning, error or success notices ...",
"keywords": [ "alert", "message" ],
"textDomain": "my-plugin",
"attributes": {
"message": {
"type": "string",
"source": "html",
"selector": ".message"
}
},
"styleVariations": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
],
"editorScript": "build/editor.js",
"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
"""

When I try `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "Notice"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "Shows warning, error or success notices ..."
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "alert"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "message"
"""

Scenario: Extract strings from block.json files with no text domain specified
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"parent": [ "core/group" ],
"icon": "star",
"description": "Shows warning, error or success notices ...",
"keywords": [ "alert", "message" ],
"attributes": {
"message": {
"type": "string",
"source": "html",
"selector": ".message"
}
},
"styleVariations": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
],
"editorScript": "build/editor.js",
"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
"""

When I try `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block title"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Notice"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block description"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Shows warning, error or success notices ..."
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgctxt "block keyword"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "alert"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "message"
"""

Scenario: Skips block.json file altogether
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/block.json file:
"""
{
"name": "my-plugin/notice",
"title": "Notice",
"category": "common",
"parent": [ "core/group" ],
"icon": "star",
"description": "Shows warning, error or success notices ...",
"keywords": [ "alert", "message" ],
"attributes": {
"message": {
"type": "string",
"source": "html",
"selector": ".message"
}
},
"styleVariations": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
],
"editorScript": "build/editor.js",
"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
"""

When I try `wp i18n make-pot foo-plugin --skip-block-json`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgctxt "block title"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "Notice"
"""
Loading