Reputation: 7448
I'm developing on Symfony2 in PHP and I'd like to find all my translation keys in my different twig views to easily list them in my message file.
Basically, in my twig templates, a translated key / text looks like:
{{ "my text" | trans }} or {{ "my_key" | trans }} or {{"my_key"|trans}} or {{"my text"|trans}}
I'd like to run a .sh script that could list all these keys/texts to be translated in my different template files.
On another project, I had to identify something like lang('MY_KEY') and a command that worked pretty much is the following one:
find . -type f -name '*.php' -execdir egrep -o -- "->lang\('[^']*" {} \; | sed -e "s/^.*->lang('//g"
Maybe with this same base, how could I easily find my different translations in my files?
Thx a lot for your help!
Upvotes: 1
Views: 208
Reputation: 10020
I would suggest something to the tune of find . -type f -name '*.php' | xargs egrep -Ho '\{\{[^|]*\|[^}]*\}\}'
. This will allow you to find the occurences of your key/text pairs in particular files. Once you've got this list, you can further process it if you want to e.g. normalize the uses and somehow match e.g. {{ "my text" | trans }}
and {{ "my_key" | trans }}
together as different uses of the same key (I don't know symphony so I don't know if this really is equivalent or not and if such 'collapsing' of keys would make sense).
Upvotes: 1