models.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models
  4. class BaseModel(models.AbstractModel):
  5. _inherit = 'base'
  6. def get_field_translations(self, field_name, langs=None):
  7. """ get model/model_term translations for records with transifex url
  8. :param str field_name: field name
  9. :param list langs: languages
  10. :return: (translations, context) where
  11. translations: list of dicts like [{"lang": lang, "source": source_term, "value": value_term,
  12. "module": module, "transifexURL": transifex_url}]
  13. context: {"translation_type": "text"/"char", "translation_show_source": True/False}
  14. """
  15. translations, context = super().get_field_translations(field_name, langs=langs)
  16. external_id = self.get_external_id().get(self.id)
  17. if not external_id:
  18. return translations, context
  19. module = external_id.split('.')[0]
  20. if module not in self.pool._init_modules:
  21. return translations, context
  22. for translation in translations:
  23. translation['module'] = module
  24. self.env['transifex.translation']._update_transifex_url(translations)
  25. return translations, context