Automagic new language strings on PHP

When you are playing with a proper framework (no matter background language) you should have a tool to update translation strings. Usually new features comes with new translation strings and it's great to have something able to say "hey mate, you have 37 new translation string, please update your po/mo or wherever you store the messages". Something like this:

(symfony)$ php app/console translation:update
(django) $ python manage.py makemessages -a

The problem is when you are playing with *inappropiate* tools. In this case you have two options: praise or resign yourself.

Well, at least you are running a *nix system, are you?. If your answer is positive... move on, the next requirement is to use a version control system, is it ok?. Next command is Mercurial based, but I think it's easy to port to the other one you are using, take a look:

$ hg diff | grep lang | cut -f2 -d"(" | cut -f1 -d")" | sort | uniq

I'm assuming lang('your-translatable-string') as the php syntax call to the translation's responsible function, so I'm trying to find all that strings in the changes I'll push in next commit.

Now I have what strings to search on my custom translation storage to see if they're missing. Not the best but it works.

About the author

Óscar
has doubledaddy super powers, father of Hugo and Nico, husband of Marta, *nix user, Djangonaut and open source passionate.
blog comments powered by Disqus