Twig extract tranlations not working - php

Am trying to extract PO files with using twig i18 extension. Following this tutorial http://twig.sensiolabs.org/doc/extensions/i18n.html i try to translate my site.
Problem is when i try to extract translations when i call in terminal:
root#debian:/var/www/html# xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP ./cache/*.php
xgettext: error while opening "./cache/*.php" for reading: No such file or directory
Check screenshot:
Checkig $ xgettext --help i dont see -R recursive search

It's trying to call "./cache/*.php" but your files are in subfolders, within the cache folder, so it should be "./cache/**/*.php".
This command should work, I guess:
root#debian:/var/www/html# xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP ./cache/**/*.php

Related

Wordpress/PHP create a static copy of the page

I need to make a static page from the dynamic one with all assets downloaded and all the links converted to local ones and download it in some tmp folder. Like when you press Ctrl+S in a browser. I tried using wget with shell_exec:
shell_exec("wget -E -H -k -p http://youmightnotneedjquery.com/ 2>&1");
The problem is that it works perfectly when I run it from console, but when I use shell_exec, I get an error
Permission denied youmightnotneedjquery.com/index.html: No such file
or directory Cannot write to 'youmightnotneedjquery.com/index.html'
(No such file or directory).
As I understand, there is some problem with permissions, I tried to create a seperate directory
with some high permissions and www-data as owner and specify it in the command using -O flag, but I get an error that I can't use -k and -O flags at the same time. So I hope to solve that issue with permission, but I still have to specify the destination folder somehow. Or maybe there's a php solution without wget that I can use, as it seems not quite hard but a lot of work to do.
You may try something like
shell_exec("cd some_nice_dir && wget ...")
You may also want to read up on man wget as it has a lot to say about interferences between -O and several of the other options you specify.
Helped using -P flag and creating a folder with owned www-data
shell_exec("wget -E -H -k -p http://mysite.local/ -P some-temp-folder 2>&1")

PHP Exec freeze on run command with "head" modifier

I have a directory with a lot of subdirectories and files in it.
I'm running this command using php's exec function:
exec('find /path/to/dir -type f | head -n 300');
On ssh this commands gives me result faster than eye blink.
When I'm running it using php's exec function script freeze and processes looks like:
sh -c find /path/to/dir [...] | head -n 300
|_ find /path/to/dir [...]
So it's look like script is looking for all files in this directory and after he will just cut and return first 300 of these.
Where is problem? Why it's working well in terminal?

Ffmpeg - Concat two video file - Defining absolute path of video file not working

I am using Ffmpeg to concate three mp4 files.
I am following this article
https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files
Check topic Concat protocol
I have 3 .ts files, now running following command that merges all 3 .ts files properly
ffmpeg -i "concat:video1.ts|video2.ts|video3.ts" -c copy -bsf:a aac_adtstoasc output.mp4
Now same command I want to run from php code, so I am giving absolute path of each file, and the command is as below.
/home/pc-16/bin/ffmpeg -i "concat:|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video1.ts'|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video2.ts'|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video3.ts'" -c copy -bsf:a aac_adtstoasc "/var/temp/rt-web/web/video/iRec/HOKPINzHFS/final.mp4"
This gives following error
concat:|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video1.ts'|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video2.ts'|'/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video3.ts': No such file or directory
Have also tried the same command by removing single quotes from file names
/home/pc-16/bin/ffmpeg -i "concat:|/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video1.ts|/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video2.ts|/var/temp/rt-web/web/video/iRec/HOKPINzHFS/video3.ts" -c copy -bsf:a aac_adtstoasc "/var/temp/rt-web/web/video/iRec/HOKPINzHFS/final.mp4"
but got the same error message.
Can anybody tell me how to specify absolute file names in command.

How to get recursive directory path using inotify-tools in terminal

I'm using inotify-tools where i want a notification of file which has been created in recursive directories
Till here i'm succesfull
Now i want to get directory path where a file is been created/dumped in the recursive folders
for e.g abc.txt file is dumped in data/test folder
i want the path to be data/test/abc.txt
Below is the code im using in .sh file
inotifywait -m -r --format '%f' -e modify -e move -e create -e delete /var/www/cloud/data | while read LINE;
do
php /var/www/cloud/scannner/watcher.php;
done
Kindly please help me to get the path of a dumped file in recursive directories
Cheers
Use the %w modifier:
inotifywait -m -r --format '%w%f' .......
To pass the output of inotifywait as an argument to a php script, which will read it for the argv variable you could do this:
inotifywait -m -r --format '%w%f' ....... | while read -r line
do
php script.php "$line"
done
Otherwise, if you want the php script to read the output of inotifywait from the standard input, then you can just pipe to your script:
inotifywait -m -r --format '%w%f' ....... | php script.php

Recursive xgettext?

How can I compile a .po file using xgettext with PHP files with a single command recursively?
My PHP files exist in a hierarchy, and the straight xgettext command doesn't seem to dig down recursively.
Got it:
find . -iname "*.php" | xargs xgettext
I was trying to use -exec before, but that would only run one file at a time. This runs them on the bunch.
Yay Google!
For WINDOWS command line a simpe solution is:
#echo off
echo Generating file list..
dir html\wp-content\themes\wpt\*.php /L /B /S > %TEMP%\listfile.txt
echo Generating .POT file...
xgettext -k_e -k__ --from-code utf-8 -o html\wp-content\themes\wpt\lang\wpt.pot -L PHP --no-wrap -D html\wp-content\themes\wpt -f %TEMP%\listfile.txt
echo Done.
del %TEMP%\listfile.txt
You cannot achieve this with one single command. The xgettext option --files-from is your friend.
find . -name '*.php' >POTFILES
xgettext --files-from=POTFILES
If you are positive that you do not have too many source files you can also use find with xargs:
find . -name "*.php" -print0 | xargs -0 xgettext
However, if you have too many source files, xargs will invoke xgettext multiple times so that the maximum command-line length of your platform is not exceeded. In order to protect yourself against that case you have to use the xgettext option -j, --join-existing, remove the stale messages file first, and start with an empty one so that xgettext does not bail out:
rm -f messages.po
echo >messages.po
find . -name "*.php" -print0 | xargs -0 xgettext --join-existing
Compare that with the simple solution given first with the list of source files in POTFILES!
Using find with --exec is very inefficient because it will invoke xgettext -j once for every source file to search for translatable strings. In the particular case of xgettext -j it is even more inefficient because xgettext has to read the evergrowing existing output file messages.po with every invocation (that is with every input source file).
Here's a solution for Windows. At first, install gettext and find from the GnuWin32 tools collection.
http://gnuwin32.sourceforge.net/packages/gettext.htm
gnuwin32.sourceforge.net/packages/findutils.htm
You can run the following command afterwards:
find /source/directory -iname "*.php" -exec xgettext -j -o /output/directory/messages.pot {} ;
The output file has to exist prior to running the command, so the new definitions can be merged with it.
This is the solution I found for recursive search on Mac:
xgettext -o translations/messages.pot --keyword=gettext `find . -name "*.php"`
Generates entries for all uses of method gettext in files whose extension is php, including subfolders and inserts them in translations/messages.pot .

Categories