From 54c016786bde5f40ddcbc9055e06797ba9cca9d7 Mon Sep 17 00:00:00 2001 From: Sylvain Calador Date: Tue, 9 Feb 2016 12:16:40 +0100 Subject: [PATCH] [IMP] Add 'save_translation_file' module --- save_translation_file/README.rst | 70 ++++++++++++++++++ save_translation_file/__init__.py | 4 + save_translation_file/__openerp__.py | 28 +++++++ .../save_translation_file.py | 40 ++++++++++ .../save_translation_file_view.xml | 37 +++++++++ .../static/description/icon.png | Bin 0 -> 1652 bytes 6 files changed, 179 insertions(+) create mode 100644 save_translation_file/README.rst create mode 100644 save_translation_file/__init__.py create mode 100644 save_translation_file/__openerp__.py create mode 100644 save_translation_file/save_translation_file.py create mode 100644 save_translation_file/save_translation_file_view.xml create mode 100644 save_translation_file/static/description/icon.png diff --git a/save_translation_file/README.rst b/save_translation_file/README.rst new file mode 100644 index 000000000..916956ae3 --- /dev/null +++ b/save_translation_file/README.rst @@ -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 +`_. 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 +`_. + +Credits +======= + +Akretion (http://www.akretion.com) + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Sylvain Calador + +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 diff --git a/save_translation_file/__init__.py b/save_translation_file/__init__.py new file mode 100644 index 000000000..2eaf61e7d --- /dev/null +++ b/save_translation_file/__init__.py @@ -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 diff --git a/save_translation_file/__openerp__.py b/save_translation_file/__openerp__.py new file mode 100644 index 000000000..0eecf1bdd --- /dev/null +++ b/save_translation_file/__openerp__.py @@ -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": [ + ] +} diff --git a/save_translation_file/save_translation_file.py b/save_translation_file/save_translation_file.py new file mode 100644 index 000000000..b1308225e --- /dev/null +++ b/save_translation_file/save_translation_file.py @@ -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 diff --git a/save_translation_file/save_translation_file_view.xml b/save_translation_file/save_translation_file_view.xml new file mode 100644 index 000000000..9772666e0 --- /dev/null +++ b/save_translation_file/save_translation_file_view.xml @@ -0,0 +1,37 @@ + + + + + ir.module.module.form + ir.module.module + + + + + + + ir.module.module.tree + ir.module.module + + + +