Conversation
Codecov Report
@@ Coverage Diff @@
## master #96 +/- ##
==========================================
- Coverage 71.42% 64.54% -6.89%
==========================================
Files 38 41 +3
Lines 462 598 +136
Branches 87 118 +31
==========================================
+ Hits 330 386 +56
- Misses 112 170 +58
- Partials 20 42 +22
Continue to review full report at Codecov.
|
@youknowriad thank you for opening this PR! I see codedev complaining about reduced tests, can we add more tests to increase coverage? |
@adamsilverstein I think it's pretty well tested, what's not tested is the Edit: I see some small functions are not tested, I'll add tests for those. |
I added unit tests, the coverage is still decreasing because of |
The usage of String extraction to translate.w.org can be added quite easily once we have identified how and which translations should get extracted. See https://core.trac.wordpress.org/ticket/20491#comment:82. |
That would be great, I'm not aware of the work being done to do so but I believe this PR identifies properly what should be extracted (all the APIs documented in the README). Who can help with this? I'd be happy to remove the |
With "we" you mean Gutenberg? Don't see why that script can't remain there as a standalone script. Since the package should only be published once core and w.org fully supports this proposal for the JS i18n API I don't see the need for the script.
The babel plugin doesn't seem useless since that's what w.org is probably going to use for the extraction. Same for authors that don't host their plugins/themes on w.org. The current extraction for PHP can be found here: https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-code-import.php
How does it handle a JS file with multiple text domains? Can a fixed text domain be passed to the script? Can it handle |
I was thinking "we" as Plugin authors, Core developpers, if we land this package as a generic package we need a way to make these strings translatable. If not, the package is useless.
Yes, it does the domain is the last arg for all these functions.
That's a good point and I don't really know. Right now we use it on unminified files only. The problem with minification... is that we don't control the tool doing it, it'd be hard to come up with a solution that works consistently across tools. Thoughts @aduth |
The Babel plugin itself doesn't make a distinction on domain. It will extract the strings, regardless of the domain passed (if any), but there is only a single output file, so a source file with two separate domains would still be processed into a single Minification could be an issue with "mangling", where minifiers choose a shorter auto-generated variable name to use in place of the original name. Since the plugin relies on the names of the functions ( https://github.com/mishoo/UglifyJS2#cli-mangle-options I expect this may be most problematic for trying to extract strings from the plugin repository. During a plugin's own build process, this is unlikely to occur, since the Babel plugin would apply its transforms before minification is applied. |
@@ -0,0 +1,135 @@ | |||
#!/usr/bin/env node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you run this file through some formatter? It's got all sorts of styling issues which aren't present in the same file from the Gutenberg repository (spaces instead of tabs, double quotes instead of single quotes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably my default prettier setup :P I'll fix it. Btw, we need eslint support :)
packages/babel-plugin-i18n/README.md
Outdated
@@ -0,0 +1,18 @@ | |||
i18n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: Naming. I think the title here should reflect the fact that it's a Babel plugin. Maybe at least "i18n Babel Plugin".
But aside from it being scoped to WordPress, and WordPress using gettext for i18n, I feel a bit odd calling this a "i18n Babel Plugin", since gettext is just one method of internationalizing.
The equivalent PHP tool is called makepot.php
, so maybe babel-plugin-makepot
if we want consistency (whether or not the name on its own is great).
Otherwise some variations of words in babel-plugin-extract-gettext-strings
? -extract-strings
? -extract-gettext
? -gettext-strings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
babel-plugin-makepot
sounds good to me
Feedback addressed, this should be in a better shape. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple suggestions, but looking to be in good shape.
"bugs": { | ||
"url": "https://github.com/WordPress/packages/issues" | ||
}, | ||
"main": "src/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root build configuration is such that a build distributable will be created for this, even if the src/index.js
doesn't require transpilation. We should consider one of:
- Target
build/index.js
asmain
, even if not strictly necessary, merely for consistency with other packages - Introduce a pattern for excluding particular projects from the Babel build step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the build folders right now, let's add this option separately because it seems useful for other packages as well.
packages/i18n/README.md
Outdated
|
||
You can use the [WordPress i18n babel plugin](../babel-plugin-makepot/README.md) to generate a `.pot` file containing all your localized strings. | ||
|
||
The package also includes a `pot-to-php` script used to generate a php files containing the messages listed in a `.pot` file. This is usefull to trick WordPress.org translation strings discovery since at the moment, WordPress.org is not capable of parsing strings directly from JavaScript files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "usefull" -> "useful"
packages/i18n/README.md
Outdated
The package also includes a `pot-to-php` script used to generate a php files containing the messages listed in a `.pot` file. This is usefull to trick WordPress.org translation strings discovery since at the moment, WordPress.org is not capable of parsing strings directly from JavaScript files. | ||
|
||
```sh | ||
node tools/pot-to-php languages/myplugin.pot languages/myplugin-translations.php text-domain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to make this a proper bin
entry in package.json
:
https://docs.npmjs.com/files/package.json#bin
That way, a developer could execute via npx pot-to-php
.
As-is, the code snippet isn't very usable (would need to at least be prefixed with ./node_modules/@wordpress/i18n
).
|
||
See: http://www.diveintojavascript.com/projects/javascript-sprintf | ||
|
||
`setLocaleData( data: Object, domain: string )` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the documentation I keep neglecting to fix 😄
From yesterday's chat, there's no blocking here. So moving forward. |
This pull request seeks to add a new package
@wordpress/i18n
package extracted from Gutenberg.