Hi, following the ticket #253 I've tried to build a solution considering i18n internationalization files creation.
The solution is composed of:
- a new pake task
- a modified Version of the sfIMessageSource.class.php to add an init method to the MessageSource class for creating empty variant files if not already exists
- the implementation of the above init method in sfMessageSource_XLIFF and sfMessageSource_gettext (but all methods use sfIMessageSource interface so implementing init method in other MessageSource(s) should just do the trick)
How do I use it?
symfony init-i18n <application> <destination-language> <char encoding>
How does this work ?
- first it creates an empty file for the destination-language if not already exists
- then it goes through all your application's *.php files looking for __() method
- then it goes through all the modules' generator.yml files for admin crud name and title yaml fields
- then it goes through all the modules' validator/*.yml files for validation form *_msg and *_error fields
- I've manually added some admin crud i18n fields lie yes yes or no ...
- and lastly it checks if there is no translation already exists and add the message to the file in that case
Maybe I missed some aspects about the global/local thing of i18N BUT my work only export to global messageSource not considering module i18n yet. This should just be some (if/else) couples to add but I'd like to get more feedback from users and the way it works now should be ok for the symfony community before going any further.
- Place sfPakeI18n.php in /php/PEAR/data/symfony/tasks
- Place(or overwrite) sfIMessageSource.class.php and sfMessageSource_XLIFF.class.php in /php/PEAR/symfony/i18n
Notes for use with gettext
- Create directories for the languages you want to translate to in the i18n dir.
PS(not related to i18n generation):
By the way for understanding i18n stuff I started reverse engineering PHP i18n packge to UML class diagrams using these tools:
- php2xmi from great guys : http://tech.motion-twin.com/php_php2xmi.html
- umbrello UML modeler for KDE on Linux (hope one day I can get this working on mac os X <- I got it through fink package unstable but when they say unstable believe them ... :( !)
class diagram as attachement.
Hints and tips on using this Pake task
Paketask working with single modules
I added a modified Paketask and a modified XLIFF-MessageSource? (sfMessageSource_XLIFF.class.php_module and sfPakeI18n.php_module). It's still a somewhat dirty Hack, but it will create desired i18n-files for each module you want. Because i had some problems with updating files, files are now deleted and recreated everytime for the modules the task is called. This means updating of i18n-files for modules is (still) not possible. To use this modified pake task with any other MessageSource? than (the modified) XLIFF you need to modify that MessageSource? in order to run.
symfony init-i18n <application> <destination-language> <char encoding> <optional module (or use 'all' for all modules)>
If this task is called without a module parameter a global file will be created as before. To create a i18n-file for one of your modules add the name of the module as 4th parameter. The i18n-file will be created in the subdirectory i18n of your module directory. Note that the directory i18n already needs to be existent! To create all i18n-files for all modules of an application call the task with the 'all' Parameter.
I encourage you to modify the code i wrote in order to gain a more usable and functional richer version with more features for everyone.
i hope my approach is usefull for someone, greetings Ovaron from ETS_DIDACTIC_MEDIA(Munich)
PS: Thx to Benoit for the great work he has done!
- sfPakeI18n.php (6.3 kB) - added by benoit on 03/24/06 12:13:20.
- sfIMessageSource.class.php (4.2 kB) - added by benoitm on 03/24/06 12:15:02.
- sfMessageSource_XLIFF.class.php (13.5 kB) - added by benoitm on 03/24/06 12:15:31.
- i18n diagram.gif (255.0 kB) - added by benoitm on 03/24/06 12:19:16.
- sfPakeI18n.php_patch01 (6.3 kB) -
pacthed with irc fabpot/hartym/rovert collaboration for () regexp, added by benoitm <firstname.lastname@example.org> on 03/29/06 17:03:59.
- sfMessageSource_XLIFF.class.php_patch01.php (13.5 kB) -
PHP 5.1 only! prevent PHP strict message and empty tag collapsing (i.e. <target></target> became <target />), added by email@example.com on 06/30/06 16:42:39.
- sfMessageSource_gettext.class.php (11.4 kB) - added by firstname.lastname@example.org on 01/22/07 19:58:10.
- sfMessageSource_XLIFF.class.php_module (18.0 kB) -
Modified sfMessageSource_XLIFF.class.php for use with Modules, added by ETS_DIDACTIC_MEDIA(MUNICH) on 01/02/08 10:35:47.
- sfPakeI18n.php_module (8.2 kB) -
Modified sfPakeI18n.php; MessageSources? need to be modified in Order to use with this one (works for already modified XLIFF-MessageSource?)., added by ETS_DIDACTIC_MEDIA(MUNICH) on 01/02/08 10:38:33.