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

Errors using make-json #146

Closed
mkaz opened this issue Feb 18, 2019 · 10 comments
Closed

Errors using make-json #146

mkaz opened this issue Feb 18, 2019 · 10 comments

Comments

@mkaz
Copy link

mkaz commented Feb 18, 2019

I'm trying to use the make-json command to generate the file from a po file.

Here are the set of commands I'm trying and the error, I think I'm missing a setting somewhere but not sure where.

> wp i18n make-post ./ ./languages/myguten.pot
Plugin file detected.
Success: POT file successfully generated!

I copy the .pot file over to myguten-eo.po and edit to look like:

# Copyright (C) 2019
# This file is distributed under the same license as the Scratch Plugin plugin.
msgid ""
msgstr ""
"Project-Id-Version: Scratch Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/scratch\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-02-18T07:20:46-08:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.1.0\n"
"X-Domain: myguten\n"

#. Plugin Name of the plugin
msgid "Scratch Plugin"
msgstr ""

#: block.js:6
msgid "Simple Block"
msgstr "Simpla bloko"

#: block.js:13
#: block.js:21
msgid "Hello World"
msgstr "Saltuon mundo"

I then try to make the json file using:

> wp i18n make-json ./languages
PHP Fatal error:  Uncaught InvalidArgumentException: The language "" is not valid in phar:///home/mkaz/bin/wp/vendor/gettext/gettext/src/Translations.php:356
Stack trace:
#0 phar:///home/mkaz/bin/wp/vendor/wp-cli/i18n-command/src/MakeJsonCommand.php(158): Gettext\Translations->setLanguage('')
#1 phar:///home/mkaz/bin/wp/vendor/wp-cli/i18n-command/src/MakeJsonCommand.php(97): WP_CLI\I18n\MakeJsonCommand->make_json('/home/mkaz/loca...', '/home/mkaz/loca...')
#2 [internal function]: WP_CLI\I18n\MakeJsonCommand->__invoke(Array, Array)
#3 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(93): call_user_func(Array, Array, Array)
#4 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#5 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(449): call_user_func(Object(Closure), Array, Array)
#6 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(366): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
# in phar:///home/mkaz/bin/wp/vendor/gettext/gettext/src/Translations.php on line 356
@swissspidy
Copy link
Member

Heya 👋

Please make sure that you have an actual Language header set in your PO file according to the spec. Otherwise tools like Poedit or WP-CLI don't know that myguten-eo.po is the Esperanto translation.

We recently fixed this fatal error in #133. You can install the latest version of this package over what's included in WP-CLI by running this:

wp package install git@github.com:wp-cli/i18n-command.git

It's worth noting that we might need to improve that handling a little bit as per the latest comments on #133, especially since I haven't tested the case of missing language headers... So stay tuned!

@mkaz
Copy link
Author

mkaz commented Feb 18, 2019

👋
I hope it's not because I picked Esperanto as my test language, I did check the list of languages you linked to and eo looks to be in it.

I added the Language header and updated the wp-cli as specified, and now getting a new error which looks like missing files in WP-CLI

> wp i18n make-json myguten-eo.po /tmp --no-purge
PHP Warning:  file_get_contents(phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/cldr-data/main/en-US/languages.json): failed to open stream: phar error: "vendor/gettext/languages/src/cldr-data/main/en-US/languages.json" is not a file in phar "/home/mkaz/bin/wp" in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 72
PHP Warning:  Invalid argument supplied for foreach() in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 37
PHP Warning:  file_get_contents(phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/cldr-data/main/en-US/territories.json): failed to open stream: phar error: "vendor/gettext/languages/src/cldr-data/main/en-US/territories.json" is not a file in phar "/home/mkaz/bin/wp" in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 74
PHP Warning:  Invalid argument supplied for foreach() in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 37
PHP Warning:  file_get_contents(phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/cldr-data/supplemental/plurals.json): failed to open stream: phar error: "vendor/gettext/languages/src/cldr-data/supplemental/plurals.json" is not a file in phar "/home/mkaz/bin/wp" in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 76
PHP Warning:  Invalid argument supplied for foreach() in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 37
PHP Warning:  file_get_contents(phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/cldr-data/main/en-US/scripts.json): failed to open stream: phar error: "vendor/gettext/languages/src/cldr-data/main/en-US/scripts.json" is not a file in phar "/home/mkaz/bin/wp" in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 78
PHP Warning:  Invalid argument supplied for foreach() in phar:///home/mkaz/bin/wp/vendor/gettext/languages/src/CldrData.php on line 37
PHP Fatal error:  Uncaught InvalidArgumentException: The language "en" is not valid in phar:///home/mkaz/bin/wp/vendor/gettext/gettext/src/Translations.php:356
Stack trace:
#0 /home/mkaz/.wp-cli/packages/vendor/wp-cli/i18n-command/src/MakeJsonCommand.php(163): Gettext\Translations->setLanguage('en')
#1 /home/mkaz/.wp-cli/packages/vendor/wp-cli/i18n-command/src/MakeJsonCommand.php(97): WP_CLI\I18n\MakeJsonCommand->make_json('/home/mkaz/loca...', '/tmp')
#2 [internal function]: WP_CLI\I18n\MakeJsonCommand->__invoke(Array, Array)
#3 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(93): call_user_func(Array, Array, Array)
#4 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#5 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(449): call_user_func(Object(Closure), Array, Array)
#6 phar:///home/mkaz/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(366): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
#7 ph in phar:///home/mkaz/bin/wp/vendor/gettext/gettext/src/Translations.php on line 356

@swissspidy
Copy link
Member

Ugh, so the same issue as #133 (comment) then. Although the warnings are new it seems.

I'll have a look hopefully later today to fix this once and for all.

@mantismamita
Copy link

Hello, I'm having the same problems here and just wondering if there is a workaround? I've got a fairly basic English to French translation done with Poedit. The language header is correct and I installed the latest version of the package including the fix for #133

Perhaps I could install and earlier version of the package as none of my languages are particularly exotic and are surely on the list?

@swissspidy
Copy link
Member

@mantismamita Thanks for the ping! Once #150 is merged, this issue should go away. You can then update the package (again) and it should work.

@mantismamita
Copy link

Fabulous, I look forward to using the tool rather than doing it by hand (not very fun.) Cheers for your hard work.

@danielbachhuber danielbachhuber added this to the 2.1.1 milestone Mar 31, 2019
@markhowellsmead
Copy link

markhowellsmead commented Apr 15, 2019

@swissspidy I've updated the package and the JSON generation now works as expected 🎉 However, after the cli command has been run, the .po and .mo files are reset to a previous version and the latest translations are lost.

My workflow:

  • Create POT using CLI
  • Create new language using Loco Translate
  • Translate all strings using Loco Translate
  • Make JSON using CLI
  • Add new strings to the JavaScript
  • Update POT using Loco Translate
  • Update PO using Loco Translate
  • Make JSON using CLI
  • Latest edits to PO are now lost

@markhowellsmead
Copy link

Additional note: the generated JSON is correct: only the PO file is reset.

@swissspidy
Copy link
Member

@markhowellsmead What you mean with reset? When you run make-json, all the JavaScript-only strings are removed from the PO files as they're not needed in there. You can disable that using the --nopurge argument.

@markhowellsmead
Copy link

Sorry for the delayed response, @swissspidy. I missed the --no-purge option, which is where the problem lay. My issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants