Translation Scanner and Translate SQL Adapter

1 message Options
Embed this post
Permalink
Christian Fraunholz

Translation Scanner and Translate SQL Adapter

Reply Threaded More More options
Print post
Permalink
Hello everybody,

I am working on a I18n scanner for the Zend Framework. It finds translatable strings in JavaScript and PHP files and writes them to a database via a custom translate SQL adapter. It's written quite generic and abstract, by using the scanner a developer should never ever worry about translations anymore.

In detail:
- I18n_Scanner_Js: scans JS files to find strings in a specified method, e.g. _(). Uses a regular expression and ignores backslashes in the string, line breaks and whitespaces between string and bracket. Simple.
- I18n_Scanner_Php: scans given filetypes to find translatable strings in a specified method, the default method is _(). Uses the fast Tokenizer instead of a regular expression. If it finds a class, the form scanner und model scanner are also loaded.
- I18n_Scanner_Form. Uses reflection to check if a subclass of type Zend_Form. Then it reads the message templates of the used validators and writes them into the database.
- I18n_Scanner_Model: this one is the most individual scanner and only makes sense if you are using standard filtering and validation for custom objects. If the scanner finds that the class is a subclass of the abstract model class we use in our ZF application (e.g. the user model class) it loads the class and executes the isValid() method (Zend_Filter_Input), retrieves the validation messages and writes them into the database. The original string, the model class name and the validator class name build the key for this translatable string.

Now that we have all translations in the databse and we know where we use them, a translator (person) can translate the strings that are being used in the application. He can also chooes to translate for a global scope or module/object scope. The developer does neither have to customize arrays with translation strings nor add custom validator messages.

Does anyone want to talk about this solution? I thought maybe this could be useful for the framework in general.