Roots Discourse

Theme Localization problem with yarn pot

#1

I am trying to translate Sage 9 by following the documentation.

First of all, when I try to add the suggested code

"pot": "mkdir -p ./resources/lang && find ./resources ./app -iname "*.php" | xargs [...]

And use yarn pot, I get an error:

error An unexpected error occurred: "/site/web/app/themes/sage/package.json: Unexpected token * in JSON at position 1935".

So I thought it was an escape issue (if it is, you could think about editing the code on the documentation), and tried again with \" and ', but this time I get the following error (with both versions):

yarn run v1.5.0
$ mkdir -p ./resources/lang && find ./resources ./app -iname "*.php" | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/sage.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/sage.pot
xargs: xgettext: No such file or directory
error An unexpected error occurred: "Command failed.
Exit code: 127
Command: sh
Arguments: -c mkdir -p ./resources/lang && find ./resources ./app -iname \"*.php\" | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/sage.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/sage.pot
Directory: /site/web/app/themes/sage
Output:
".

Is there something simple I am not getting here?

2 Likes

Theme Localization problem
#2

Stuck on this as well. Syntax error somewhere?

0 Likes

#3

Weird, this issue does not seem to create much interest. A workaround would at least be appreciated, we are talking about a central feature of any theme and potentially an error that is in the official documentation…

0 Likes

#4

Ok, I think the issue could be that gettext is potentially not installed but needed. There seems to be a similar error described here.

Does anyone know how and where gettext should be installed if one is using the Trellis + Bedrock + Sage stack?

EDIT:

I just tried installing gettext and gettext-parser through yarn and it did not help.

0 Likes

#5

Hey @manalyse. I’m testing this issue right now. Are you on macOS? It looks like xgettext isn’t there. Installing gettext instead seems to be just as problematic.

0 Likes

#6

Hey @knowler, yes I am on macOS. And yes, installing gettext doesn’t help. I was just searching more about this on the web and found this:

Ok, here’s the answer ( deduced from Internationalisation Django (on OSX) )

The real xgettext for PHP is available as a tool that come with the gettext extension.

As I’ve installed gettext with brew ( brew install gettext ), it’s located here: /usr/local/Cellar/gettext/0.18.1.1/bin/xgettext

This version of xgettext support the PHP function.

I don’t really understand what that means, however.

0 Likes

#7

I got it to work by upgrading coreutils (which I already had installed). Install it via Homebrew with:

brew install coreutils

or, in my case:

brew upgrade coreutils

Then make sure the yarn script corrects the unescaped double quotes that you mentioned above:

"pot": "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php' | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/sage.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/sage.pot"

You should submit a PR at roots/docs to fix the typo in the script and maybe add a note about installing/upgrading coreutils. I would recommend changing the double quotes to single quotes like I did to match how the .blade.php is formatted in the same script.

1 Like

#8

I just installed coreutils (version 8.29) and tried yarn pot again, but it gives the same error.

0 Likes

#9

Hm, maybe try brew install findutils? Make sure you are resourcing/reloading your shell.

0 Likes

#10

Oh. Also, I guess I neglected that I’ve installed gettext via Homebrew and manually symlinked the path to the binaries. So similar to the post you quoted above, brew install gettext and then add export PATH="/usr/local/opt/gettext/bin:$PATH" to your run commands.

3 Likes

#11

Ok, thanks a lot! I installed gettext now via Homebrew.

What does it mean to add this to my “run commands”? I should just execute it once in the terminal in my theme folder? I’m sorry if the question is dumb, I am not a professional developer and just learning all of this.

EDIT:

It worked! Thank you very much @knowler!

I would love to contribute by doing a pull request with the fix, but as I have never done this before, I’m not sure it will turn out to be correct. I will do my best.

1 Like

#12

Hey, no problem at all, we’re all learning — I don’t know if I’m doing it the best way haha. Do you know what shell you are using? If it’s the default — bash — then you can add it in ~/.bash_profile:

# Maybe near the top
export PATH="/usr/local/opt/gettext/bin:$PATH"
1 Like

#13

Thanks for the kind words! Yes, it was the default, and actually homebrew provided a simple way to do what you said:

echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

I think this gets the job done in the same way.

EDIT:

Created a pull request for single quotes and a notice here

1 Like

#14

Any advice how I could run this script on windows?

0 Likes

#15
0 Likes

#16

I installed coreutils, findutils, gettext, and added it to .bash_profile, but I still get the error

xargs: xgettext: No such file or directory

I also added

"pot": "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php' | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/sage.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/sage.pot"

to my package.json

0 Likes

#17
0 Likes

#18

@strarsis Does one execute this command in the theme folder? Or just generally on mac? When I try to execute the command in my mac’s home folder or in my theme folder I get:

sudo: apt-get: command not found
0 Likes

#19

apt-get is not going to exist for you on mac… Have you looked into what you need to do to install the utilities for macOS?

Search Google for “xgettext macos”

0 Likes

#20

Yes I installed coreutils, findutils and gettext via brew with the instructions in this topic.

$ brew install coreutils && brew install findutils && brew install gettext

And then

$ echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

Then in my theme directory

$ yarn pot

UPDATE: I tried $ yarn pot in another project, and it worked straight away… also tried it on the project I tried to translate in the first place, and it works!

0 Likes