Closed Beee4life closed 7 years ago
Maybe this info helps. When i ran twig-gettext-extractor from /usr/local/bin I got this error.
Here is one idea. You can try to debug (log) command here then run it from terminal and see what happens, troubleshoot etc..
Thanks, I appreciate the answer, but I don't understand what you mean exactly. I do use terminal for some things, but here I don't know what you mean.
I meant add file_put_contents('path_to_file.txt', $command,)
in https://github.com/umpirsky/Twig-Gettext-Extractor/blob/master/Twig/Gettext/Extractor.php#L77 then run command found in path_to_file.txt
from terminal to see what happens.
Thanks for the pointer. I added it to my project files, but there was no difference and I couldn't find an output file.
I'd like to remove the global installation and then just try the local version. I already removed it from /usr/local/bin and symfony, twig and umpirsky from .composer/vendor. Is that 'enough' ?
If not can you help me with clearing it so I can start fresh with a local version ?
@Beee4life Just copy https://github.com/umpirsky/Twig-Gettext-Extractor/blob/master/twig-gettext-extractor where you want it to be (e.g. bin
directory) and use it from there. You still need vendors.
I used this command on terminal again
$ sudo wget https://github.com/umpirsky/Twig-Gettext-Extractor/releases/download/1.2.0/twig-gettext-extractor.phar -O /usr/local/bin/twig-gettext-extractor
$ sudo chmod a+x /usr/local/bin/twig-gettext-extractor
I removed it from my project but now I'm without the vendors.... How can I get them back :( I expected they would be reinstalled but no luck....
Just install it with composer.
I added it to my project with composer require umpirsky/twig-gettext-extractor
.
I added the Twig processor with the following command: /Users/Me/HTML/sitename/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F
If I click update from sources, it indexes, doesn't show Twig translations but also I don't get an error or so.
I'm really stumped what to do...
Debugging like described in https://github.com/umpirsky/Twig-Gettext-Extractor/issues/50#issuecomment-263827023 will give you more info.
Like this ?
$error = 0;
$output = system($command, $error);
file_put_contents( 'output.txt', $command );
if (0 !== $error) {
Sorry for my non-understanding, but would really like to fix this. I appreciate your help.
I used it as above.. but I can't find any file named output.txt.
@Beee4life Use absolute path, just to be sure you are looking at right location, also make sure to set write privileges.
use it like this ? file_put_contents( '/Users/Beee/html/project/output.txt', $command );
Can you confirm these setting are good in my Twig processor ??
This is the full setting of the extractor since it's partially out of view:
/Users/Me/HTML/sitename/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F
@Beee4life Yes, you can find setup instructions on https://github.com/umpirsky/Twig-Gettext-Extractor#setup.
i didn't think I did the setup wrong.. but just checking...
To set read/write/execute privileges/rights do I use this
sudo chmod r+w /Users/Beee/html/project/output.txt
?
I would use sudo chmod a+w /Users/Beee/html/project/output.txt
Thanks for all your help but I made the decision to move all the translation strings to a php file, which can be indexed and I include all strings through a twig value.
Like this $context['label_saturday'] = __( 'Saturday', 'text-domain' );
I then echo it in my template as {{ label_saturday }}
.
Since I already knew this worked I switched back to this, also looking to the future, to prevent other editors from having the same issue. I got too frustrated with it and wanted to fix it :)
This might not be the best solution but it does the trick.
@Beee4life You can also generate PHP files from your twig templates, see http://twig.sensiolabs.org/doc/extensions/i18n.html#extracting-template-strings
Closing this issue since I bought Poedit Pro, which now handles Twig/Timber.
Wow, didn't know there is a Pro version. Good to know!
It costs 30 bucks or so, but it is sooooooooo worth it. See https://poedit.net/pro.
No disrespect to your plugin of course but native code almost always wins it from 'external' code.
Sure, they know their tool. :)
I first had all my translatable converted into labels, so I could put all the string in PHP so they would be recognised.
When I found this plugin, I installed it by command line(I think globally) and it worked, because I changed all my labels back to translatable twig strings but somewhere something must have gone wrong because PoEdit can't seem to pick up one single string from my templates anymore.
I have now installed it globally as well as locally in a project's composer.json file. I set up Twig in Poedit according to your instructions.
The command I used to extract translations is
/Users/username/HTML/project-folder/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F
I set up my templates files according to this explanation.
I first added
export PATH="$PATH:$HOME/.composer/vendor/bin"
to .bashrc. I then read somewhere you should never add stuff to bashrc but to bash_profile instead so I tried both options, but I don't seem to notice a difference.Can it be that something in my bash_profile is conflicting ? See this screenshot of my bash_profile.
I have spent the entire afternoon on it and I'm literally stumped... I don't know anymore where to look.
I hope you can provide some help because I'm working a lot more with Twig and this would save me a lot of time as you can understand.