How to generate translation file (.po, .xliff, .yml,...) from a Symfony2/Silex project? - symfony

Im going to build a Silex/Symfony2 project and I have been looking around for a method to generate XLIFF/PO/YAML translation files based on texts-to-be-translated inside the project but not found any instruction or documentation on it.
My question is: Is there an automated way to generate translation file(s) in specific format for a Symfony2/Silex project?
If yes, please tell me how to generate the file then update the translation after that.
If no, please tell me how to create translation file(s) then adding up more text for my project? I am looking for an editor desktop based or web-based instead of using normal editor such as Transifex, GetLocalization (but they dont have option to create a new file or add more text)

After a long time searching the internet, I found a good one:
https://github.com/schmittjoh/JMSTranslationBundle

I see you've found a converter, but to answer your first question about generating your initial translation file -
If you have Gettext installed on your system you could generate a PO file from your "texts-to-be-translated inside the project". The command line program xgettext will scan the source files looking for whatever function you're using.
Example:
To scan PHP files for instances of the trans method call as shown here you could use the following command -
find . -name "*.php" | xargs xgettext --language=PHP --keyword=trans --output=messages.pot
To your question about editors:
You could use any PO editor, such as POEdit, to manage your translations, but as you say you eventually need to convert the PO file to either an XLIFF or YAML language pack for Symfony.
I see you've already found a converter tool. You may also like to try the one I wrote for Loco. It supports PO to YAML, and PO to XLIFF

Workaround for busy people (UNIX)
You can run the following command in the Terminal:
$ grep -rEo --no-filename "'.+'\|\btrans\b" templates/ > output.txt
This will output the list of messages to translate:
'Please provide your email'|trans
'Phone'|trans
'Please provide your phone number'|trans
...
I mean almost.. But you can usually do some work from here...
Obviously you must tweak the command to your liking (transchoice, double-quotes instead of single...).
Not ideal but can help!
grep options
grep -R, -r, --recursive: Read all files under each directory, recursively this is equivalent to the -d recurse option.
grep -E, --extended-regexp: Interpret PATTERN as an extended regular expression.
grep -o, --only-matching: Show only the part of a matching line that matches PATTERN.
grep -h, --no-filename: Suppress the prefixing of filenames on output when multiple files are searched.
(source)

Related

What's the best way to extract a list of i18n strings from a meteor app?

I'm using this i18n package to internationalise my meteor app and I'm looking for a tool to automatically create a i18n json file from the strings surrounded by "{{_" and "}}" in my meteor folder.
Do you know a script for this or alternatively is there a way to do it using Sublime Text / Notepad++ ?
I would just use grep to find all strings, copy to a new file, and then format accordingly.
grep -r "{{_.*}}" . > output.txt
I can't remember, but you might have to escape the curly braces in the search string.
Unfortunately, not all versions of grep support recursive searching, and some use different switches, so if you're running into problems, check your man pages.

UNIX: How to change all instances of a string within all files in a directory

My question is basically the same as this previous question...
How to change all occurrences of a word in all files in a directory
...except I'm trying to change the reference to a header file.
For example,I'm trying to change [lessthan]abc/filename.h[greaterthan] to "filename.h", is this even possible using the same syntax, or should I be looking to whip myself up a quick program to do it?
Thanks
You can do it easily with sed:
sed -i -e 's,<abc/filename.h>,"filename.h",' *

How can I use backreferences to add (not change) strings in the same line with BSD sed?

To make recurring tasks easier, I like to code shell scripts which (mostly) perform them for me. One of my latest scripts is for creating ed2k links with included http download URLs.
One example of what I want to achieve: Given that I want to download a specified version of Notepad++ to my "Shared" folder, I just type:
./dl-notepadpp.sh 6.0.0
I made it to the point where it downloads all files and passes them to the alcc command; which, however, prints plain ed2k links without any references.
I basically need a piped sed command which turns the alcc output
ed2k://|file|npp.6.0.0.bin.7z|7631311|8b8298915a2670c3f11416ba95f78a88|/
into
ed2k://|file|npp.6.0.0.bin.7z|7631311|8b8298915a2670c3f11416ba95f78a88|s=http://download.tuxfamily.org/notepadplus/6.0.0/npp.6.0.0.bin.7z|/
automatically.
(Of course I don't just want N++ and not just one file, so, technically, I need a sed command to add "s=http..." with a file name from an earlier part of the line.)
I tried using $1 in the replacement string for sed which doesn't work.
Any clues?

change file extension in unix

I am taking a intro to Unix class and am stuck on the final assignment. I need to write a script to change the file extension of a filename that is input when the script is run. The new file extension is also input when the script is run. The script is call chExt1.sh . Our first trial of the script is run as follows
./chExt1.sh cpp aardvark.CPP
The script is suppose to change the second input file extension to the file extension given in the first input. It is not suppose to matter what file extension is given with the file name or what file extension is given as the new extension, nor is it only for changing uppercase to lowercase. In hope to make this very clear if given the following:
./chExt1.sh istink helpme.plEaSe
The script would change helpme.plEaSe to helpme.istink . I have searched on this forum and in google and have had no look with trying the different examples I found. Below is some of the examples I have tried and what I currently have.
Current
#!/bin/sh
fileExtension="$1"
shift
oldName="$2"
shift
newName=${oldName%%.*}${fileExtension}
echo $newName
The echo is just to see if it works, and if I get it working I'm going to add an mv to save it.
Others that I have tried:
newName=`${oldName%.*}`
newName=`${oldName#.*}`
sed 's/\.*//' $oldName > $newName
I can't seem to find some of the other sed I have used but they involved alot of backslashes and () with .* in there. I did not try the basename command cause I don't know the file extension to be entered and all I the examples I saw required that you specify what you wanted removed and I can't. I did not list all the different quote variations that I used but I have tried alot. My instructions say to use the sed command since we should know how to use that from class but when I try to do it I don't isolate just the ending of the file and I believe (cause it takes so long to finish) that it is going through the whole file and looking for .'s and anything after cause I kept doing .* as the pattern. Thanks for anyhelp you can give.
shift shifts the positional parameters, so after calling shift the second parameter ($2) is now the first ($1). The second shift is not necessary, because you are done accessing the parameters. You need to either remove the shift
#!/bin/sh
fileExtension="$1"
oldName="$2"
newName=${oldName%%.*}${fileExtension}
echo $newName
or change $2 to $1.
#!/bin/sh
fileExtension="$1"
shift
oldName="$1"
newName=${oldName%%.*}${fileExtension}
echo $newName
However, you are still missing a dot from your new file name. That is left as an exercise for the reader.

Memorizing *nix command line arguments

For my developer work I reside in the *nix shell environment pretty much all day, but still can't seem to memorize the name and argument specifics of programs I don't use daily. I wonder how other 'casual amnesiacs' handle this. Do you maintain an big cheat sheet? Do you rehearse the emacs shortcuts when you take your weekly shower? Or is your desk covered under sticky notes?
Using bash_completion is one way of not having to remember the precise syntax of program arguments.
> svn [tab][tab]
--help checkout delete lock pdel propget revert
--version ci diff log pedit proplist rm
-h cleanup export ls pget propset status
add co help merge plist pset switch
annotate commit import mkdir praise remove unlock
blame copy info move propdel rename update
cat cp list mv propedit resolved
If I don't use a command regularly enough to remember what I want, I tend to just use --help or the man pages when I need to.
Or, if I'm lucky, I use CTRL+R and let bash's history search find when I last used it.
Eventually you just remember them, well the set that you use anyway. I used to maintain a README in my home directory when I was starting out but that disappeared many years ago.
One useful command is man -k which you pass a word to and it will return a list of all commands whose man page summary contains that word.
'apropos' is also a very useful command. It will list all commands whose man pages contain the keyword.

Resources