Question

I'm developing a web app in Kohana 3.2. I use the __() function in message files, views, etc. because I want to make my app available in multiple languages.

Is there a fast and easy way to collect all the strings I have to translate? For example a code editor that can do this for me (on windows)?

So I want a list with all the strings from all my files, used for calling the __() function. How you handle this problem, or what you suggest?

Thank you!

Was it helpful?

Solution

There is a simple drop-in module (kohana-i18nget, kohana-i18nget on github) that lets you collect all your __() enclosed strings from a module or the application folder and outputs the appropriate language arrays (specify all the needed languages in the config file) to your i18n folders.

Any already existing translation keys are kept intact. It is invoked from your project root via the commandline:

php index.php --uri=i18nget/generate/mymodule/mymodule
or
php index.php --uri=i18nget/generate/application/application

The first command generates language files for strings found in mymodule to mymodule/i18n/, the second generates the files for the application folder in application/i18n/

It also points out orphaned translation keys which are not used in the source files.

OTHER TIPS

Kohana uses its own system to handle translations, you can find more about it here. Unfortunately, they don't provide any tool to extract the strings from the PHP files so you'll have to do it manually.

If you want automatic string extraction, you should consider a more complete solution like gettext, and use Poedit to extract the strings.

You can also use some shell scripting to extract these strings:

grep -or "__\((.*)\)" .

From your app folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top