Reputation: 1649
i don't figure out a way to extract automaticaly string to be translated in files.
For instance, you've got in your layout and views some echo $this->translate('my_string');
and I want to created the files 'en_US.php', 'fr_FR.php', 'es_ES.php' with the comparative array :
<?php return array('my_string' => 'translation of my string'); ?>
Is it possible ?
Thanks.
Upvotes: 0
Views: 933
Reputation: 40685
Look at the Zend_Translate adapters and choose one. I warmly recommend the gettext adapter.
Here is how to implement i18n in your Zend Framework application:
Upvotes: 1
Reputation: 16045
Yes, it is.
Put in your application.ini
:
resources.translate.adapter = Array
resources.translate.locale = fr_FR
resources.translate.disableNotices = true
resources.translate.data = APPLICATION_PATH "/data"
And put file fr_FR.php
in your APPLICATION_PATH "/data"
directory. It should work.
The file must be something like this:
return array (
'Good day' => 'Bojour',
);
Upvotes: 1
Reputation: 47604
Using PHP to translate a project is handy for small project, and consequently you shouldn't need such tools.
There are such tools for gettext, like poedit, which will parse your project and search for the given function/method (translate()
). POedit will generate .po file which basicly consists of plain/text file which looks like:
#: src/name.c:36
msgid "My name is %s.\n"
msgstr ""
If you really need to use a PHP file for your translation, you may try some grep
, sed
, awk
, something like this should give a starting point (not tested):
echo "return array(" > mytranslation.php | \
grep "translate(" * | \
cut -f1 | \
sed -r 's@.*translate\((.*)\).*@\1 => "Not translated yet",@' >> mytranslation.php && \
echo ");" >> mytranslation.php
Upvotes: 0