Browse Source
Merge pull request #160 from akretion/8.0-save-translation-file
Merge pull request #160 from akretion/8.0-save-translation-file
[IMP] Add 'save_translation_file' modulepull/369/head
beau sebastien
9 years ago
8 changed files with 216 additions and 0 deletions
-
70save_translation_file/README.rst
-
4save_translation_file/__init__.py
-
28save_translation_file/__openerp__.py
-
40save_translation_file/save_translation_file.py
-
37save_translation_file/save_translation_file_view.xml
-
BINsave_translation_file/static/description/icon.png
-
5save_translation_file/tests/__init__.py
-
32save_translation_file/tests/test_save_translation_file.py
@ -0,0 +1,70 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
===================== |
||||
|
Save translation file |
||||
|
===================== |
||||
|
|
||||
|
This module was written for **developpers** to easily generate i18n files (.po and .pot) from the list of modules, |
||||
|
instead of using the native configuration "Export Translation" wizard. |
||||
|
|
||||
|
- The i18n subdirectory is created if missing in the module. |
||||
|
- A ".po" file is generated for each installed languages. |
||||
|
- If a ".po" file exists it is **overwritten** (use with caution). |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
To use this module, you need to: |
||||
|
|
||||
|
* Go to the view list (or form) of installed modules and click the button 'Save translation file' |
||||
|
|
||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
||||
|
:alt: Try me on Runbot |
||||
|
:target: https://runbot.odoo-community.org/runbot/149/8.0 |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues |
||||
|
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please |
||||
|
check there if your issue has already been reported. If you spotted it first, |
||||
|
help us smashing it by providing a detailed and welcomed `feedback |
||||
|
<https://github.com/OCA/ |
||||
|
server-tools/issues/new?body=module:%20 |
||||
|
save_translation_file%0Aversion:%20 |
||||
|
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Akretion (http://www.akretion.com) |
||||
|
|
||||
|
Images |
||||
|
------ |
||||
|
|
||||
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Sylvain Calador <sylvain.calador@akretion.com> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit https://odoo-community.org. |
||||
|
|
||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:alt: License: AGPL-3 |
@ -0,0 +1,4 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016-TODAY Akretion |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from . import save_translation_file |
@ -0,0 +1,28 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016-TODAY Akretion |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
{ |
||||
|
"name": "Save translation file", |
||||
|
"summary": "Allows developpers to easily generate i18n files", |
||||
|
"version": "8.0.1.0.0", |
||||
|
"category": "Tools", |
||||
|
"website": "https://www.akretion.com/", |
||||
|
"author": "Akretion, Odoo Community Association (OCA)", |
||||
|
"license": "AGPL-3", |
||||
|
"application": False, |
||||
|
"installable": True, |
||||
|
"external_dependencies": { |
||||
|
"python": [], |
||||
|
"bin": [], |
||||
|
}, |
||||
|
"depends": [ |
||||
|
"base", |
||||
|
], |
||||
|
"data": [ |
||||
|
"save_translation_file_view.xml", |
||||
|
], |
||||
|
"demo": [ |
||||
|
], |
||||
|
"qweb": [ |
||||
|
] |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016-TODAY Akretion |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import os |
||||
|
|
||||
|
from openerp import models, api, tools |
||||
|
from openerp.modules import get_module_path |
||||
|
from openerp.tools.misc import get_iso_codes |
||||
|
|
||||
|
|
||||
|
class IrModuleModule(models.Model): |
||||
|
_inherit = 'ir.module.module' |
||||
|
|
||||
|
@api.one |
||||
|
def button_save_translation(self): |
||||
|
|
||||
|
format_ = 'po' |
||||
|
|
||||
|
i18n_path = os.path.join(get_module_path(self.name), 'i18n') |
||||
|
if not os.path.isdir(i18n_path): |
||||
|
os.mkdir(i18n_path) |
||||
|
|
||||
|
lang_obj = self.env['res.lang'] |
||||
|
condition = [('translatable', '=', True), ('code', '!=', 'en_US')] |
||||
|
langs = lang_obj.search(condition) |
||||
|
|
||||
|
files = [('%s.pot' % self.name, False)] |
||||
|
for lang in langs: |
||||
|
iso_code = get_iso_codes(lang.code) |
||||
|
filename = '%s.%s' % (iso_code, format_) |
||||
|
files.append((filename, lang.code)) |
||||
|
|
||||
|
for filename, lang in files: |
||||
|
path = os.path.join(i18n_path, filename) |
||||
|
with open(path, 'w') as buf: |
||||
|
tools.trans_export(lang, [self.name], buf, format_, |
||||
|
self.env.cr) |
||||
|
|
||||
|
return True |
@ -0,0 +1,37 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="module_form" model="ir.ui.view"> |
||||
|
<field name="name">ir.module.module.form</field> |
||||
|
<field name="model">ir.module.module</field> |
||||
|
<field name="inherit_id" ref="base.module_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<button name="button_install_cancel" position="after"> |
||||
|
<button name="button_save_translation" |
||||
|
string="Save translation file" |
||||
|
confirm="Overwrite all i18n files for this module ?" |
||||
|
type="object" |
||||
|
states="installed" |
||||
|
icon="terp-translate" |
||||
|
/> |
||||
|
</button> |
||||
|
</field> |
||||
|
</record> |
||||
|
<record id="module_tree" model="ir.ui.view"> |
||||
|
<field name="name">ir.module.module.tree</field> |
||||
|
<field name="model">ir.module.module</field> |
||||
|
<field name="inherit_id" ref="base.module_tree"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="state" position="after"> |
||||
|
<button name="button_save_translation" |
||||
|
string="Save translation file" |
||||
|
confirm="Overwrite all i18n files for this module ?" |
||||
|
type="object" |
||||
|
states="installed" |
||||
|
icon="terp-translate" |
||||
|
/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
After Width: 64 | Height: 64 | Size: 1.6 KiB |
@ -0,0 +1,5 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016-TODAY Akretion |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from . import test_save_translation_file |
@ -0,0 +1,32 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016-TODAY Akretion |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import os |
||||
|
|
||||
|
from openerp.modules import get_module_path |
||||
|
from openerp.tools.misc import get_iso_codes |
||||
|
from openerp.tools.translate import load_language |
||||
|
import openerp.tests.common as common |
||||
|
|
||||
|
|
||||
|
class TestIrModuleModule(common.TransactionCase): |
||||
|
|
||||
|
def test_button_save_translation(self): |
||||
|
|
||||
|
load_language(self.cr, 'fr_FR') |
||||
|
|
||||
|
condition = [('name', '=', 'save_translation_file')] |
||||
|
record = self.env['ir.module.module'].search(condition) |
||||
|
record.button_save_translation() |
||||
|
|
||||
|
i18n_path = os.path.join(get_module_path(record.name), 'i18n') |
||||
|
lang_obj = self.env['res.lang'] |
||||
|
condition = [('translatable', '=', True), ('code', '!=', 'en_US')] |
||||
|
langs = lang_obj.search(condition) |
||||
|
|
||||
|
for lang in langs: |
||||
|
iso_code = get_iso_codes(lang.code) |
||||
|
path = os.path.join(i18n_path, '%s.po' % iso_code) |
||||
|
self.assertEqual(os.path.isfile(path), True, |
||||
|
'%s.po must exists' % iso_code) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue