You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016-TODAY Akretion
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import os
  5. from openerp import models, api, tools
  6. from openerp.modules import get_module_path
  7. from openerp.tools.misc import get_iso_codes
  8. class IrModuleModule(models.Model):
  9. _inherit = 'ir.module.module'
  10. @api.one
  11. def button_save_translation(self):
  12. format_ = 'po'
  13. i18n_path = os.path.join(get_module_path(self.name), 'i18n')
  14. if not os.path.isdir(i18n_path):
  15. os.mkdir(i18n_path)
  16. lang_obj = self.env['res.lang']
  17. condition = [('translatable', '=', True), ('code', '!=', 'en_US')]
  18. langs = lang_obj.search(condition)
  19. files = [('%s.pot' % self.name, False)]
  20. for lang in langs:
  21. iso_code = get_iso_codes(lang.code)
  22. filename = '%s.%s' % (iso_code, format_)
  23. files.append((filename, lang.code))
  24. for filename, lang in files:
  25. path = os.path.join(i18n_path, filename)
  26. with open(path, 'w') as buf:
  27. tools.trans_export(lang, [self.name], buf, format_,
  28. self.env.cr)
  29. return True