You must first sign up to be able to contribute.

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 ?

  1. first it creates an empty file for the destination-language if not already exists
  2. then it goes through all your application's *.php files looking for __() method
  3. then it goes through all the modules' generator.yml files for admin crud name and title yaml fields
  4. then it goes through all the modules' validator/*.yml files for validation form *_msg and *_error fields
  5. I've manually added some admin crud i18n fields lie yes yes or no ...
  6. 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

Thanks benoitm

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 :
  • 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!