Master i18n fp

Improvements
-------------------

This branch improves the translation mechanism, mostly needed for frontend:

1/ Translation of XML/HTML fields: are managed like arch in ir.ui.view. Splited in smaller goups rather than having to translate the whole field (e.g. a blog, a product description, etc.)

2/ Typos management when translating from the website: if a typo is fixed on an english string, you do not have to translate the whole blog again in all languages. If you completely change a paragraph, it has to be translated again (only the paragraph, not the whole blog). If you just fix a typo, the translated versions remain.

3/ The translation of views is not a specific use case, it's now translate=True on the arch fields on ir.ui.view.

4/ Mark as 'To Translate' translated values of an english field that has been changed (if the distance of the change is higher than 0.9). Exemple:
   'Hello Wrold!' to 'Holy Grail!' --> You have to re-translate the french version
   'Hello Wrold!' to 'Hello World!' --> You do not have to re-translate the french version

More efficient, less lines of code.

Changes
------------

* Fields support not only translate=True, but also translate=CHUNK_METHOD. This method takes a string in argument and return a list of strings to translate.
* From the client side point of view, translate=CHUNK_METHOD is like translate=False. (e.g. you can not modify the french version of the arch field of views)
* The context on translations changed in the exported .PO.   #: view:resource.calendar.leaves:0 is now  #: model:ir.ui.view,arch:resource.view_resource_calendar_leaves_search

Done
-------

- tested to import .PO
- tested to export .PO
- tested in the frontend

Todo
-------

- More tests
- put chunk_xml (in ir_ui_view) in tools/xml.py and use it in blogs, product description, ...
- improve chunk_xml to not split around \<b\>, \<i\> and \<strong\>, \<span\>, \<em\>
- Adapt the frontend to support translation of HTML fields like views
- Re-export .POs in all languages (ask ODO for this, he has his own script to do this)
- check if fields_get() returns translate=False when translate=METHOD on field (I do not remember if I did it or not)



We can't move the _translation_resync on BaseModel.write() Because, from
the backend perspective (or RPC), these fields should be like non
translatable fields: you read and write them in english.

You can not write the french version of such an HTML field. The only way
to translate them is to work on ir.translations directly.

On 07/31/2014 11:21 AM, odony wrote:
> In addons/website/models/ir_ui_view.py:
> 
>>  
>>          view = self.browse(cr, SUPERUSER_ID, res_id, context=context)
>>          if view.model_data_id:
>>              view.model_data_id.write({'noupdate': True})
>> +
>> +    # When the English version of a field is modified, the algorithm tries to
>> +    # resync translation if the distance between modified strings is not too
>> +    # big. It allows to not retranslate data where a typo has been fixed in
>> +    # the English version.
>> +    def __translation_resync(self, cr, uid, model, ids, field, context=None):
>> +        context = context or {}
>> +        model_obj = self.pool.get(model)
>> +        translate = model_obj._all_columns[field].column.translate
>> +        if (not translate) or (translate is True):
> 
> The test on |translate| should be done using |callable()|.
> More generally, why don't we do this in |BaseModel.write()| for all
> translatable fields, rather than only for those edited in the website.
> 
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/odoo/odoo/pull/1464/files#r15632922>.
> 


-- 
Fabien Pinckaers
Odoo Founder

Phone: +32.81.81.37.00
Web: https://www.odoo.com
Twitter: @fpodoo

Instant Demo: https://odoo.com/start