Skip to content

Commit

Permalink
Merge branch 'master' into dynamic-import-workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Jul 23, 2019
2 parents 6a30434 + 4f49fe1 commit af1a33b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
],
"require": {
"gettext/gettext": "^4.6",
"gettext/gettext": "^4.6.3",
"mck89/peast": "^1.8",
"wp-cli/wp-cli": "^2"
},
"require-dev": {
"wp-cli/scaffold-command": "^1.2 || ^2",
"wp-cli/wp-cli-tests": "^2.1"
"wp-cli/wp-cli-tests": "^2.1.3"
},
"config": {
"process-timeout": 7200,
Expand Down
57 changes: 55 additions & 2 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ Feature: Generate a POT file of a WordPress project
"""

Scenario: Extract translator comments
Given I run `echo "\t"`
And save STDOUT as {TAB}
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
Expand All @@ -520,9 +522,14 @@ Feature: Generate a POT file of a WordPress project
*/
__( 'off', 'foo-plugin' );
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g ( __( 'bubu', 'foo-plugin' ) );
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
{TAB}/*
{TAB} * translators: this comment block is indented with a tab and should get extracted too.
{TAB} */
{TAB}__( 'yolo', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin`
Expand Down Expand Up @@ -568,6 +575,10 @@ Feature: Generate a POT file of a WordPress project
"""
#. translators: this should get extracted too.
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
#. translators: this comment block is indented with a tab and should get extracted too.
"""

Scenario: Generates a POT file for a child theme with no other files
When I run `wp scaffold child-theme foobar --parent_theme=twentyseventeen --theme_name="Foo Bar" --author="Jane Doe" --author_uri="https://example.com" --theme_uri="https://foobar.example.com"`
Expand Down Expand Up @@ -1666,6 +1677,48 @@ Feature: Generate a POT file of a WordPress project
msgid "__"
"""

Scenario: Parse .js and .jsx files for javascript translations
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
"""
And a foo-plugin/foo-plugin.js file:
"""
__( 'js', 'foo-plugin' );
"""
And a foo-plugin/foo-plugin.jsx file:
"""
__( 'jsx', 'foo-plugin' );
"""
And a foo-plugin/foo-plugin.whatever file:
"""
__( 'whatever', 'foo-plugin' );
"""

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 "js"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "jsx"
"""
And the foo-plugin/foo-plugin.pot file should not contain:
"""
msgid "whatever"
"""

Scenario: Extract translator comments from JavaScript file
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
Expand Down
2 changes: 2 additions & 0 deletions src/IterableCodeExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) {
$filtered_files[] = Utils\normalize_path( $file->getPathname() );
}

sort( $filtered_files, SORT_NATURAL | SORT_FLAG_CASE );

return $filtered_files;
}
}
2 changes: 1 addition & 1 deletion src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected function extract_strings() {
[
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'js' ],
'extensions' => [ 'js', 'jsx' ],
]
);

Expand Down
13 changes: 13 additions & 0 deletions tests/IterableCodeExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,17 @@ public function test_can_override_exclude_by_include() {
$expected = static::$base . 'foo/bar/excluded/ignored.js';
$this->assertContains( $expected, $result );
}

public function test_can_return_all_directory_files_sorted() {
$result = IterableCodeExtractor::getFilesFromDirectory( self::$base, [ '*' ], [], [ 'php', 'js' ] );
$expected = array(
static::$base . 'baz/includes/should_be_included.js',
static::$base . 'foo-plugin/foo-plugin.php',
static::$base . 'foo/bar/excluded/ignored.js',
static::$base . 'foo/bar/foo/bar/foo/bar/deep_directory_also_included.php',
static::$base . 'foo/bar/foofoo/included.js',
static::$base . 'hoge/should_NOT_be_included.js',
);
$this->assertEquals( $expected, $result );
}
}

0 comments on commit af1a33b

Please sign in to comment.