umpirsky / Twig-Gettext-Extractor

The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.
MIT License
113 stars 32 forks source link

Permissions issues? Missing folders? #12

Open Saeven opened 10 years ago

Saeven commented 10 years ago

Any of you developers using this on OSX? I'm running into an issue where the call to your library:

<project>/vendor/bin/twig-gettext-extractor --sort-output --force-po -o "/var/folders/lw/0f57k9dj617_ntr760qw2lcr0000fgp/T/poedit1nmsrR/3extracted.pot" --from-code=UTF-8  -k_ -ktranslate -ksetLabel -ksetValue -ksetLegend -k_refresh -L PHP --files  "vendor/mylibrary/core/view/ldp/forgot/email.twig" "vendor/mylibrary/core/view/ldp/forgot/index.twig" "vendor/mylibrary/core/view/ldp/login/index.twig" "vendor/mylibrary/core/view/ldp/main/index.twig" "vendor/mylibrary/core/view/ldp/register/index.twig"

Fails with this error message:

Fatal error: Uncaught exception 'RuntimeException' with message 'Gettext command "xgettext --sort-output --force-po -o /var/folders/lw/0f57k9dj617_ntr760qw2lcr0000fgp/T/poedit1nmsrR/3extracted.pot --from-code=UTF-8 -k_ -ktranslate -ksetLabel -ksetValue -ksetLegend -k_refresh -L PHP /tmp/cache/5279bc643f96f/8c/e1/c60ddc5ef854138efa25631b4b6d.php /tmp/cache/5279bc643f96f/d3/37/bf84f1be48ed8fd950ff618fba22.php /tmp/cache/5279bc643f96f/a7/e7/56cec92524ceab7ab465d688f936.php /tmp/cache/5279bc643f96f/73/df/2a5e4848ca69cb43dc05818ce5b0.php /tmp/cache/5279bc643f96f/82/0b/167d3083d340e123ea9742944113.php" failed with error code 1 and output: ' in <project>/vendor/umpirsky/twig-gettext-extractor/Twig/Gettext/Extractor.php:90

So attempting to run that command directly leads to:

xgettext: cannot create output file "/var/folders/lw/0f57k9dj617_ntr760qw2lcr0000fgp/T/poedit1nmsrR/3extracted.pot": No such file or directory

All PHP these PHP scripts are owned by Me:admin on my filesystem. Seen this before?

Saeven commented 10 years ago

Looks like there might be a bug in Poedit, so I have just another quick question for you. Which version of poedit have you successfully used with your script?

umpirsky commented 10 years ago

@Saeven Hehum...strange. I used it with 1.5.4-1.

Saeven commented 10 years ago

Sorry to be daft, I'm partway trying to ascertain that I'm not crazy. Can you tell me what you have in your catalog preferences in the sources path section?

Saeven commented 10 years ago

Also, what OS were you using 1.5.4-1 with?

umpirsky commented 10 years ago

I suggest to test with simplest data possible, one simple string.

I'm using Ubuntu 13.04.

Saeven commented 10 years ago

Sorry to be a pain, but could you share a sample catalog config in sources path?

umpirsky commented 10 years ago

Unfortunately, I have no. But you can try with one string catalog.

aeneasr commented 10 years ago

Same issue here - I'm on Mac OS X

umpirsky commented 10 years ago

@arekkas Can you debug it?

aeneasr commented 10 years ago

it seems like poedit is telling xgettext to use a file that is inside a directory, poedit has not created yet. Which is weird, because the other parsers work.

aeneasr commented 10 years ago

The problem is, I can't really see why the command fails in poedit, only when executing it directly from cmd I see the error messages. However, when I modify the -o parameter to an existing directory, the script is working fine

umpirsky commented 10 years ago

You can go into Twig-Gettext-Extractor code and log information you need to see if files exist at that moment and all data you are inetrested in, right @arekkas? For example in https://github.com/umpirsky/Twig-Gettext-Extractor/blob/master/Twig/Gettext/Extractor.php#L70-L88

aeneasr commented 10 years ago

True, I'll have a closer look tomorrow

feedmeastraycat commented 10 years ago

I had the same, or similar issues, as described here (and in other issues here). I'm on OSX. After picking Twig-Gettext-Extractor apart and rebuilding it again I found out that I only had to do three things (2 of them not described in the readme.md file).

  1. Copy the vendor/bin/twig-gettext-extractor and add some extensions (as described in readme.md)
  2. Setup poedit with the following parser command: ./twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F I don't know if is meant to be literarily "" or your project path. But doing ./twig-gettext-extractor seems to work to use the po-files project location which would be nicer then changing the parser every time you switch project.
  3. Put this line first in my copied twig-gettext-extractor file: putenv('PATH='.getenv('PATH').':/opt/local/bin');

It seemed that PHP didnt find "gettext" because PHP wasn't allowed to look in /opt/local/bin. That caused all other issues I had basically. But it was very hard to debug.

Ping @umpirsky FYI. :)

It would be nice though if the twig-gettext-extractor could run as a service in a symfony/console command instead though. I tried to do that but I have yet to solve how that could be done. Or maybe if you could create a twig-gettext-extractor file that included the vendor/bin/twig-gettext-extractor file and only had to contain your custom extensions. This way makes it a bit less easy to keep up to date if/when Twig-Gettext-Extractor updates. But, well. It works now at least... I think. :)

umpirsky commented 10 years ago

@feedmeastraycat Thanks for sharing this man!

I didn't understand point 2. Did you copy extractor to poedits dir?

I would like to keep this decoupled from Symfony. People use it with other frameworks too. But I would like to see people integrating it with frameworks too.

feedmeastraycat commented 10 years ago

@umpirsky No. My .pot file is located in /src/locale/ inside the project so I put base path to "../../" in Catalog > Properties > Sources path within Poedit. Then I have added "./src/views" in "Paths". And then I have "./twig-gettext-extractor" when I setup the twig parser. It seems that Poedit (1.6.5) understands that "./twig-gettext-extractor" is within the base path.

I had to copy twig-gettext-extractor from /vendor/bin/ because I needed to add some more extensions.

Here is a screenshot of my parser setup: https://www.dropbox.com/s/jc0svmt4wxmgepm/Screenshot%202014-05-21%2011.08.39.png

Here is a screenshot of my pot-file catalog properties: https://www.dropbox.com/s/fuwcury2w4az86q/Screenshot%202014-05-21%2011.09.53.png

Im still unsure if the example of <project>/vendor/bin/twig-gettext-extractor/ ... is meant to be taken literarily. Or if I should replace <project> with the full path to where my project is. But that seemed like a bad solution because that would make the twig parser project specific. But either way. Replacing <project>/ with ./ did the trick anyway. :)

The only problem I have now is that I want to use the {% trans %} tag the way Symfony sets it up so I can use, for example {% trans with {'%name%':'David'} %}Hello %name%!{% endtrans %} ... But I havent figured that out yet. If it even can be done. :)

I understand that you wanna keep it decoupled from Symfony though. Makes sense. I will probably revisit that again and see if I can put it into the console.

umpirsky commented 10 years ago

You should replace with the full path to where your project lives. :smile_cat:

But I agree, it is not handy for project switching.

Thanks for the effort, really appreciate it.

feedmeastraycat commented 10 years ago

@umpirsky Ok. Thanks. :) I wasn't sure from the readme if it was a placeholder or some poedit var. :D But cool. Now I know. But I'll keep ./ because I like to keep it not project specific. I know that Im gonna forget about that if else, and Im gonna spend weeks trying to figure out why it doesn't use my twig-gettext-extractor on my next project! ;)

aeneasr commented 10 years ago

I finally got it working, you need to execute POEdit (on Mac) like this: WXTRACE=poedit,poedit.tmp,poedit.execute /Applications/Poedit.app/Contents/MacOS/Poedit --verbose --keep-temp-files

Source: http://circlical.com/blog/2013/11/5/localizing-your-twig-using-zend-framework-2-applications

aeneasr commented 10 years ago

Works like a charm now, even with ZF2 :)

umpirsky commented 10 years ago

@arekkas Thanks for sharing. If this works on Mac I will accept PR with MacOS section instruction.

barmarko27 commented 9 years ago

I'm on OSX Yosemite and the issue of missing folder under "/var" still continue. There are many OSX users that have same problem? Thank so much!

umpirsky commented 9 years ago

@barmarko27 Have you tried https://github.com/umpirsky/Twig-Gettext-Extractor/issues/12#issuecomment-44317644?

barmarko27 commented 9 years ago

@umpirsky Yes, but don't work! It seems that Poedit can't delete the temp file.

Poedit parser configuration: schermata 2015-05-26 alle 12 28 41

Poedit Command Line Execution: schermata 2015-05-26 alle 12 31 23

Poedit Error: schermata 2015-05-26 alle 12 31 07

Thanks for your support!

umpirsky commented 9 years ago

@arekkas Any idea why it does not work for @barmarko27? Thanks.

aeneasr commented 9 years ago

With the latest POedit version, you don't need WXTRACE=poedit,poedit.tmp,poedit.execute /Applications/Poedit.app/Contents/MacOS/Poedit --verbose --keep-temp-files any more. Just start PoEdit regularly.

You'll also need to make sure that the path to twig-gettext-extractor is correct by running it in the console.

barmarko27 commented 9 years ago

@arekkas Yes the path to twig-gettext-extractor is correct. It seems that Poedit can't delete temporary folder after execution of Twig Parser. Thanks for helping me!

umpirsky commented 9 years ago

Is it a permission problem?

aeneasr commented 9 years ago

@barmarko27 did you start POEdit without --keep-temp-files?

saadhre commented 9 years ago

Platform: MacOS Yosemite 10.10.4 (14E46) Poeditor: 1.8.3 (3998) with xgettext 0.19.4.

When I starting Poeditor without parameters and trying to update translation from source, poeditor throws described error. With --keep-temp-files or with WXTRACE=poedit,poedit.tmp,poedit.execute exception is different:

Can't remove directory '/var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditQ3Mdg2' (error 66: Directory not empty) Can't run application: PATH_TO_PROJECT/vendor/bin/twig-gettext-extractor --sort-output --force-po -o "/var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditQ3Mdg2/14extracted.pot" --from-code=UTF-8 -ktranslate -L PHP --files "Application/view/application/index/index.twig"

Any idea?

aeneasr commented 9 years ago

Can't run application: PATH_TO_PROJECT/vendor/bin/twig-gettext-extractor --sort-output --force-po -o "/var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditQ3Mdg2/14extracted.pot" --from-code=UTF-8 -ktranslate -L PHP --files "Application/view/application/index/index.twig"

Doesn't look like a real path to me ;)

saadhre commented 9 years ago

Yes, real path has sensitive client data in names. But trust me - path is correct.

aeneasr commented 9 years ago

I see :) Does verbose give useful info?

saadhre commented 9 years ago

In trace everything looks fine... Trace data before exception:

Trace: (poedit.tmp) new temp file /var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditmG51sW/14extracted.pot Trace: (poedit.execute) /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin//Users/urfin/Public/www/xxxx/xxxx/vendor/bin/twig-gettext-extractor doesn't exist, falling back to /Users/urfin/Public/www/xxxx/xxxx/vendor/bin/twig-gettext-extractor Trace: (poedit.execute) executing: /Users/urfin/Public/www/xxxx/xxxx/vendor/bin/twig-gettext-extractor --sort-output --force-po -o "/var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditmG51sW/14extracted.pot" --from-code=UTF-8 -ktranslate -L PHP --files "Application/view/application/index/index.twig" Trace: (poedit.tmp) keeping temp files in /var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditmG51sW Trace: (poedit.tmp) removing temp dir /var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditmG51sW

saadhre commented 9 years ago

Just checked content of /var/folders/7f/hv40gb8x4cgg0v7wsbkm4djr0000gn/T/poeditmG51sW/ directory and 14extracted.pot not exists in there.

ternes3 commented 9 years ago

same problem here. start with --keep-temp-files ends in error 66# without --keep-temp-files ends in

Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/0extracted.pot Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/1extracted.pot Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/2extracted.pot Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/3extracted.pot Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/4extracted.pot Trace: (poedit.tmp) removing temp file /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08/5merged.pot Trace: (poedit.tmp) removing temp dir /var/folders/cz/3_w92y755tg8ksbss737427m0000gn/T/poeditwRmF08

jeremyzahner commented 8 years ago

Having the same problem:

Trace: (poedit.tmp) new temp file /var/folders/nw/qt8p5kc174dfrw4r5pf3c67h0000gn/T/poeditZoZrEQ/0extracted.pot
Trace: (poedit.execute) /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin//Users/jzahner/Sites/joshmartin-website/vendor/bin/twig-gettext-extractor doesn't exist, falling back to /Users/jzahner/Sites/joshmartin-website/vendor/bin/twig-gettext-extractor
Trace: (poedit.execute) executing: /Users/jzahner/Sites/joshmartin-website/vendor/bin/twig-gettext-extractor --sort-output --force-po -o "/var/folders/nw/qt8p5kc174dfrw4r5pf3c67h0000gn/T/poeditZoZrEQ/0extracted.pot" --from-code=UTF-8  -L PHP --files  "_angebot.twig" "_index.twig" "_kontakt.twig" "_team.twig" "_technologie.twig" "_werte.twig" "baselayout.twig"
Trace: (poedit.tmp) keeping temp files in /var/folders/nw/qt8p5kc174dfrw4r5pf3c67h0000gn/T/poeditZoZrEQ
Trace: (poedit.tmp) removing temp dir /var/folders/nw/qt8p5kc174dfrw4r5pf3c67h0000gn/T/poeditZoZrEQ

Any Updates on this?

umpirsky commented 8 years ago

@jeremyzahner MacOS?

jeremyzahner commented 8 years ago

Yes! Sorry for leaving out that detail ^^

umpirsky commented 8 years ago

@jeremyzahner The problem is that I am a Linux user myself and project is tested on OSX by other users. Have you tried @arekkas suggestion from https://github.com/umpirsky/Twig-Gettext-Extractor/issues/12#issuecomment-44317644 ?

aeneasr commented 8 years ago

I can confirm this issue with recent POEdit versions. It works neither with --keep-temp-files nor without. My best guess is to rollback your POEdit version.

umpirsky commented 8 years ago

Thanks for the update @arekkas. Let's try to ping Mr. @vslavik the author of Poedit, maybe he can give us some inside information about Poedit and how it handles files.

vslavik commented 8 years ago

Let's try to ping Mr. @vslavik the author of Poedit, maybe he can give us some inside information about Poedit and how it handles files.

Sorry, it’s not really clear what you’re asking about — this issue is a bit of a mess to read through and I can’t quite make sense of all it. If you have a reproducible test case (one that doesn’t take half an eternity to setup), by all means, send it to me to have a look.

Without that, just a few assorted observations:

  1. The original issue doesn’t seem related to Poedit: it’s clearly some extractor failure. The subsequent complain about manual xgettext command failing is bogus: of course it fails if you didn’t create the output directory (as Poedit would before invoking the command).
  2. The advice to always use --keep-temp-files doesn’t make sense to me — that’s for debugging only!
  3. The errors about failing to delete the temp directory are caused by the use of --keep-temp-files (due to a minor bug where Poedit would still try to delete the dir despite the flag — I’ll fix that right away).
  4. If some *extracted.pot file is not created and not kept with --keep-temp-files (this is the only valid use for it: debugging if some files were created or not), then the only explanation is that the extractor tool that was supposed to create it didn't. Notice how the builtin extractors use the --force-po to always create an output file, even if empty. If twig-gettext-extractor doesn’t create an empty-but-valid POT file (i.e. with header, but no other msgids) when it doesn’t encounter any translatable strings, that would certainly cause this.
  5. The use of relative paths to extractor executable was never supported and if it worked at some point, it was by pure accident. It’s not really clear to me why would you want to do that (instead of having a copy of twig-gettext-extractor somewhere in PATH to use with all your projects), but I assume I must be missing something, and would welcome education (probably at help@poedit.net as it would be offtopic here).

(BTW, I’m reworking extractors completely for the next major version (don’t worry, there will be “legacy” compatibility) and am soliciting any extractors-related feedback from, you know, real users of custom extractors — feel free to ping me at the above email address).

aeneasr commented 8 years ago

The errors about failing to delete the temp directory are caused by the use of --keep-temp-files (due to a minor bug where Poedit would still try to delete the dir despite the flag — I’ll fix that right away).

This will fix our issue 100%. It would be great if you could implement that!

vslavik commented 8 years ago

This will fix our issue 100%. It would be great if you could implement that!

I feel like I might have not been as clear as I thought I was, so let me repeat myself in the interest of being absolutely clear:

DO NOT EVER USE --keep-temp-files!

It doesn’t solve anything and is not meant to be used by end users! If it does seem to help you with something, please show me a reproducible test case of what it solves, using the latest Poedit version, and I’ll fix that, because that would uncover some serious issue — but to be frank, I simply don’t see how could anything of the sorts be possible.

aeneasr commented 8 years ago

Well I believe that the issue is as follows:

twig-gettext-extractor converts .twig (no native POEdit/xgettext support) files to .php files. These get stored in a temp dir and then iterated by xgettext. Somewhere inbetween, these files get deleted which is why xgettext is saying that they don't exist. This issue was "resolved" by telling POEdit to keep the files.

That's at least what I think is happening.

vslavik commented 8 years ago

I see two problems with that theory:

  1. Why do you think twig-gettext-extractor’s private temp files are stored in Poedit’s private temporary directory? Poedit creates a temp (sub)directory of its own, doesn’t change any environment variables and doesn’t change CWD to the tempdir either. Unless the extractor goes to extra pain to set the cache directory to Poedit’s temp one (i.e. the location of the output file, not the input twig files), I’m not sure how could that happen? If it does happen, it would indeed be problematic for Poedit (and I’ll address that too, because there’s no reason why Poedit shouldn’t survive some leftover temp files), but is it happening?
  2. Looking at the code, the extractor generates PHP files, runs xgettext and only exits after that. Poedit doesn’t, and cannot, delete the temp folder before twig-gettext-extractor returns. There’s no way for it to delete files from under the extractor’s hands, even if they were located in Poedit’s temp directory.

I’m more and more confused by the minute :-/

aeneasr commented 8 years ago

I'm sorry but I'm not sure if I can help you further. I ran into this issue some years ago and found the --keep-temp-files fix in some blog. It worked back then but at some point I upgraded POEdit and it stopped working. It has not been working ever since. I also think that this issue is Mac only. Maybe Mac manages its temp directory in a different way than Linux. No idea.

umpirsky commented 8 years ago

Thanks for your response and willing to help @vslavik, I really appreciate it.

One thing is sure. I am 100% sure cache directories of Twig and Poedit are not shared. No doubt about that.

I never encouraged people to use --keep-temp-files it was never in readme. I see they use it for debug purposes.

I agree this issue is too verbose and hard to read, so for the sake of sanity let's just wait for some Mac user to come up with proper and easy to reproduce test case.

Now we have @vslavik who is willing to take a look and I am very thankful. :+1:

vslavik commented 8 years ago

One thing is sure. I am 100% sure cache directories of Twig and Poedit are not shared.

Still a mystery, then. Let’s wait for more details as you say, then.

I never encouraged people to use --keep-temp-files

Of course! I just wanted to clarify this for readers of this issue.