# Theme Localization problem with yarn pot

**URL:** https://discourse.roots.io/t/theme-localization-problem-with-yarn-pot/12410
**Category:** sage
**Created:** 2018-05-08T06:10:03Z
**Posts:** 31

## Post 1 by @manalyse — 2018-05-08T06:10:03Z

I am trying to translate Sage 9 by [following the documentation](https://roots.io/sage/docs/theme-localization/).

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?

---

## Post 2 by @justinpicard — 2018-05-09T09:35:17Z

Stuck on this as well. Syntax error somewhere?

---

## Post 3 by @manalyse — 2018-05-10T09:43:37Z

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…

---

## Post 4 by @manalyse — 2018-05-10T12:48:21Z

> [@manalyse](#):
>
> xargs: xgettext: No such file or directory

Ok, I think the issue could be that gettext is potentially not installed but needed. There seems to be a similar error described [here](http://develobert.blogspot.de/2009/09/wordpress-xargs-xgettext-no-such-file.html).

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.

---

## Post 5 by @knowler — 2018-05-10T13:09:22Z

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.

---

## Post 6 by @manalyse — 2018-05-10T13:13:34Z

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](https://stackoverflow.com/a/8404714/9697190):

> 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.

---

## Post 7 by @knowler — 2018-05-10T13:15:51Z

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`](https://github.com/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.

---

## Post 8 by @manalyse — 2018-05-10T13:24:12Z

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

---

## Post 9 by @knowler — 2018-05-10T13:29:56Z

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

---

## Post 10 by @knowler — 2018-05-10T13:35:46Z

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.

---

## Post 11 by @manalyse — 2018-05-10T13:39:17Z

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

> [@knowler](#):
>
> add `export PATH="/usr/local/opt/gettext/bin:$PATH"` to your run commands.

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.

---

## Post 12 by @knowler — 2018-05-10T13:45:22Z

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"
```

---

## Post 13 by @manalyse — 2018-05-10T13:47:50Z

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](https://github.com/roots/docs/pull/146)

---

## Post 14 by @jasonbaciulis — 2018-06-04T10:38:05Z

Any advice how I could run this script on windows?

---

## Post 15 by @strarsis — 2018-06-04T12:38:36Z

> [@[Guide] Developing on Windows 10 using WSL](https://discourse.roots.io/t/guide-developing-on-windows-10-using-wsl/9380):
>
> With the release of the Creators update, WSL now has proper networking, 60%+ better support for Linux system calls, and the best feature of all: the ability to execute Windows native executables. You can read more about this [here](https://blogs.msdn.microsoft.com/commandline/2017/04/11/windows-10-creators-update-whats-new-in-bashwsl-windows-console/). Here’s a couple tips on settings this up for web development, including Trellis. mintty First of all, I recommend using mintty as a terminal. You can install it using the instructions on the [wsltty](https://github.com/mintty/wsltty) repo. You can check out various other terminals such as [cmder](http://cmder.net/) and [H…](https://github.com/zeit/hyper)

---

## Post 16 by @justinpicard — 2018-09-22T11:24:50Z

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

---

## Post 17 by @strarsis — 2018-09-22T15:54:46Z

> [@justinpicard](#):
>
> xargs: xgettext: No such file or directory

> **[Wordpress xargs: xgettext: No such file](http://develobert.blogspot.com/2009/09/wordpress-xargs-xgettext-no-such-file.html)**
>
> I was getting the following error when trying to use the Wordpress i18n-tools to generate POT files for a Wordpress plugin. xargs: xgettext:...

---

## Post 18 by @justinpicard — 2018-09-22T17:06:58Z

@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
```

---

## Post 19 by @ben — 2018-09-24T15:34:46Z

`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”

---

## Post 20 by @justinpicard — 2018-09-24T15:50:56Z

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!

---

## Post 21 by @knowler — 2018-09-24T20:59:04Z

> [@justinpicard](#):
>
> 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!

You might have just needed to reload your terminal.

---

## Post 22 by @legraindeweb — 2018-10-30T13:40:28Z

Did you finely made it on windows ?  
I still have an error “The syntax of the command is incorrect” even after installing coreutils, findutils and gettext

Thanks

---

## Post 23 by @jasonbaciulis — 2018-10-30T16:58:02Z

No, I’m using Polylang so it wasn’t necessary. But in the long run I’ll setup Hackintosh because there is just too much trouble with Roots and windows or web dev in general.

---

## Post 24 by @legraindeweb — 2018-10-30T17:01:30Z

Thanks for yout feedback.  
Well, any help from the community would be appreciated to make it work on windows :slight_smile:

---

## Post 25 by @stuartcusackie — 2019-05-07T12:31:28Z

I’m getting the same error message on WSL:  
**xargs: xgettext: No such file or directory**

Now I don’t really know my way around Linux but this seems to work:

I noticed that:  
**/usr/local/opt/gettext/bin**  
Doesn’t exist on my Ubuntu 18.04 WSL Installation. In fact, there is no ‘/opt/’ directory at all.

The closest thing folder I could find is here:  
**/home/linuxbrew/.linuxbrew/Cellar/gettext/0.19.8.1\_1/bin**

So I ran this command instead of the above PATH command:  
**echo ‘export PATH="/home/linuxbrew/.linuxbrew/Cellar/gettext/0.19.8.1\_1/bin:$PATH"’ \>\> ~/.bash\_profile**  
And then restarted the WSL terminal.

Now **yarn pot** seems to run fine, asides from a couple of ‘unterminated string’ warnings in my blade files.

It’s probably not a great solution so if anyone can figure out why I don’t have ‘/opt/gettext/bin/’ then please let me know.

---

## Post 26 by @Lefevre_Christophe — 2019-05-22T09:38:32Z

I’m running into the same issue on Windows. Yarn pot script fails with an exit code 1 (Incorrect syntax).

Any help would be greatly appreciated. Thanks.

---

## Post 27 by @trainoasis — 2019-08-16T10:24:59Z

For me, this still returns

```
xargs: xgettext: No such file or directory
error Command failed with exit code 127.
```

Any help appreciated.

ps: tried

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

(using oh my zsh)

and reloading, it works.

---

## Post 28 by @Tolia35 — 2020-11-02T12:32:30Z

Hi, I’m on Windows and I do have the same problem.  
Did you find a solution ?

---

## Post 29 by @strarsis — 2020-11-02T12:37:14Z

I use WSL 2 now, hence all \*nix/Ubuntu tools can be used.

---

## Post 30 by @Tolia35 — 2020-11-02T13:34:35Z

Ok thx, I used Wp-cli

My script : “pot”: “wp i18n make-pot . resources/my-theme.pot”  
Every yarn pot launch an update on my-theme.pot and generate my translation automaticly.  
That my client can then used in locotranslate plugin.

---

## Post 31 by @strarsis — 2020-11-02T13:46:41Z

I also use VSCode with WSL 2 remote extension. The build is much faster, and the site (Docker) also runs much faster on native WSL 2 \*nix file system.
