## 國際化
每個模塊可以在i18n目錄提供自己的翻譯,通過文件命名為lang.po,郎是語言區域設置代碼,或語言和國家的不同組合時(如pt.po或pt_br。PO)。翻譯將自動加載的所有可用語言Odoo。開發商總是用英語創造一個模塊時,然后出口模塊上使用的鍋口特征Odoo gettext(設置翻譯進出口出口翻譯不指定語言),以創建模塊模板鍋文件,然后導出翻譯PO文件。許多IDE的編輯和合并訂單/鍋文件插件或模式。
Tip
GNU gettext格式(便攜式 對象)用Odoo集成到發射臺,使其成為一個在線協同翻譯平臺。
~~~ tree
|- idea/ # The module directory
|- i18n/ # Translation files
| - idea.pot # Translation Template (exported from Odoo)
| - fr.po # French translation
| - pt_BR.po # Brazilian Portuguese translation
| (...)
~~~
Tip
默認情況下,Odoo鍋出口僅提取物在Python代碼在XML文件或內部字段定義的標簽,但任何Python字符串可以翻譯這種方式,它與周圍的` OpenERP功能。_() `(例如` _(“Label”)`)
練習
翻譯模塊
選擇你的Odoo安裝第二語言。翻譯你的模塊利用Odoo設施。
1. 創建一個目錄 `openacademy/i18n/`
2. 安裝任何你想要的語言 ( 行政翻譯的官方翻譯)
3. 同步翻譯的術語(行政翻譯應用同步翻譯)
4. 創建一個模板翻譯文件,通過導出(管理翻譯-導入/導出翻譯)而不指定語言,保存在 `openacademy/i18n/`
5. 通過導出(行政管理翻譯、導入/導出翻譯)和指定一個翻譯文件,創建一個翻譯文件。把它保存在 `openacademy/i18n/`
6. 打開輸出文件(翻譯有一個基本的文本編輯器或專用PO文件編輯器如[ poedit ](http://poedit.net/)和翻譯失蹤
7. 在 `models.py`,為函數添加一個導入語句 `openerp._` 標記丟失字符串翻譯
8. 重復3-6步驟
*openacademy/models.py*
~~~ python
# -*- coding: utf-8 -*-
from datetime import timedelta
from openerp import models, fields, api, exceptions, _
class Course(models.Model):
_name = 'openacademy.course'
~~~
~~~
default = dict(default or {})
copied_count = self.search_count(
[('name', '=like', _(u"Copy of {}%").format(self.name))])
if not copied_count:
new_name = _(u"Copy of {}").format(self.name)
else:
new_name = _(u"Copy of {} ({})").format(self.name, copied_count)
default['name'] = new_name
return super(Course, self).copy(default)
~~~
~~~
if self.seats < 0:
return {
'warning': {
'title': _("Incorrect 'seats' value"),
'message': _("The number of available seats may not be negative"),
},
}
if self.seats < len(self.attendee_ids):
return {
'warning': {
'title': _("Too many attendees"),
'message': _("Increase seats or remove excess attendees"),
},
}
~~~
~~~
def _check_instructor_not_in_attendees(self):
for r in self:
if r.instructor_id and r.instructor_id in r.attendee_ids:
raise exceptions.ValidationError(_("A session's instructor can't be an attendee"))
~~~