def act_getfile(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang = this.lang if this.lang != NEW_LANG_KEY else False
     mods = map(lambda m: m.name, this.modules) or ['all']
     mods.sort()
     buf = cStringIO.StringIO()
     tools.trans_export(lang, mods, buf, this.format, cr)
     filename = 'new'
     if lang:
         filename = get_iso_codes(lang)
     elif len(mods) == 1:
         filename = mods[0]
     this.name = "%s.%s" % (filename, this.format)
     out = base64.encodestring(buf.getvalue())
     buf.close()
     self.write(cr, uid, ids, {'state': 'get',
                               'data': out,
                               'name':this.name}, context=context)
     return {
         'type': 'ir.actions.act_window',
         'res_model': 'base.language.export',
         'view_mode': 'form',
         'view_type': 'form',
         'res_id': this.id,
         'views': [(False, 'form')],
         'target': 'new',
     }
Beispiel #2
0
 def act_getfile(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang = this.lang if this.lang != NEW_LANG_KEY else False
     mods = map(lambda m: m.name, this.modules) or ['all']
     mods.sort()
     buf = cStringIO.StringIO()
     tools.trans_export(lang, mods, buf, this.format, cr)
     filename = 'new'
     if lang:
         filename = get_iso_codes(lang)
     elif len(mods) == 1:
         filename = mods[0]
     this.name = "%s.%s" % (filename, this.format)
     out = base64.encodestring(buf.getvalue())
     buf.close()
     self.write(cr,
                uid,
                ids, {
                    'state': 'get',
                    'data': out,
                    'name': this.name
                },
                context=context)
     return {
         'type': 'ir.actions.act_window',
         'res_model': 'base.language.export',
         'view_mode': 'form',
         'view_type': 'form',
         'res_id': this.id,
         'views': [(False, 'form')],
         'target': 'new',
     }
 def act_update(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang_name = self._get_lang_name(cr, uid, this.lang)
     buf=cStringIO.StringIO()
     tools.trans_export(this.lang, ['all'], buf, 'csv', dbname=cr.dbname)
     tools.trans_load_data(cr.dbname, buf, 'csv', this.lang, lang_name=lang_name)
     buf.close()
     return {'type': 'ir.actions.act_window_close'}
Beispiel #4
0
 def act_update(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     lang_name = self._get_lang_name(cr, uid, this.lang)
     buf = cStringIO.StringIO()
     tools.trans_export(this.lang, ['all'], buf, 'csv', cr)
     tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name)
     buf.close()
     return {'type': 'ir.actions.act_window_close'}
 def act_getfile(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     mods = map(lambda m: m.name, this.modules) or ['all']
     mods.sort()
     buf=cStringIO.StringIO()
     tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
     if this.format == 'csv':
         this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
     elif this.format == 'po':
         if not this.lang:
             this.format = 'pot'
         this.advice = _("Save this document to a %s file and edit it with a specific software or a text editor. The file encoding is UTF-8.") % ('.'+this.format,)
     elif this.format == 'tgz':
         ext = this.lang and '.po' or '.pot'
         this.advice = _('Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad.') % (ext,)
     filename = _('new')
     if not this.lang and len(mods) == 1:
         filename = mods[0]
     this.name = "%s.%s" % (this.lang or filename, this.format)
     out=base64.encodestring(buf.getvalue())
     buf.close()
     return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context)
Beispiel #6
0
 def act_getfile(self, cr, uid, ids, context=None):
     this = self.browse(cr, uid, ids)[0]
     mods = map(lambda m: m.name, this.modules) or ['all']
     mods.sort()
     buf=cStringIO.StringIO()
     tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
     if this.format == 'csv':
         this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
     elif this.format == 'po':
         if not this.lang:
             this.format = 'pot'
         this.advice = _("Save this document to a %s file and edit it with a specific software or a text editor. The file encoding is UTF-8.") % ('.'+this.format,)
     elif this.format == 'tgz':
         ext = this.lang and '.po' or '.pot'
         this.advice = _('Save this document to a .tgz file. This archive containt UTF-8 %s files and may be uploaded to launchpad.') % (ext,)
     filename = _('new')
     if not this.lang and len(mods) == 1:
         filename = mods[0]
     if this.lang:
         filename = get_iso_codes(this.lang)
     this.name = "%s.%s" % (filename, this.format)
     out=base64.encodestring(buf.getvalue())
     buf.close()
     return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice, 'name':this.name}, context=context)
Beispiel #7
0
    def test_translate_modules(self):
        """
        Test translated strings in the module using the .po and .pot files
        """

        from os.path import join, isdir
        from tools import trans_export
        from cStringIO import StringIO
        from utils import compare_pofiles, TempDir

        if not self.config['testing_langs']:
            logger.warning(
                'Configuration variable "DESTRAL_TESTING_LANGS" has'
                ' not been initialized'
            )
            return

        mod_path = join(
            self.openerp.config['addons_path'], self.config['module']
        )
        trad_path = join(mod_path, 'i18n')

        self.assertTrue(
            isdir(trad_path),
            'Module {} has no translations'.format(self.config['module'])
        )

        logger.info(
            'Checking translations for module %s', self.config['module']
        )
        with Transaction().start(self.database) as txn:
            cursor = txn.cursor

            # Generate POT data from loaded strings
            trans_data = StringIO()
            trans_export(
                False, [self.config['module']],
                trans_data, 'po', dbname=cursor.dbname
            )
            trans_obj = self.openerp.pool.get('wizard.module.lang.export')
            trans_data = trans_obj.append_report_translations(
                txn.cursor, txn.user, [self.config['module']], 'pot', trans_data
            )

        with TempDir() as temp:
            tmp_pot = '{}/{}.pot'.format(temp.dir, self.config['module'])
            # Write POT data into temp file
            with open(tmp_pot, 'w') as pot:
                pot.write(trans_data.getvalue())
            pot_path = join(trad_path, '{}.pot'.format(self.config['module']))
            missing_strings, untranslated_strings = compare_pofiles(
                tmp_pot, pot_path
            )
            # Don't compare untranslated strings in POT
            #   because POT files do not contain translations
            self.assertIsNotNone(
                missing_strings,
                'There is not a POT file for module {}'.format(
                    self.config['module']
                )
            )
            self.assertItemsEqual(
                [],
                missing_strings,
                'There are {} missing strings in the POT file'
                ' of the module {}\nThe missing strings are:\n'
                '\n{}\n'.format(
                    len(missing_strings), self.config['module'],
                    '\n'.join(missing_strings)
                )
            )
            logger.info('Checking translations for langs: {}'.format(
                self.config['testing_langs']
            ))
            for test_lang in self.config['testing_langs']:
                po_path = join(trad_path, '{}.po'.format(test_lang))
                missing_strings, untranslated_strings = compare_pofiles(
                    tmp_pot, po_path
                )
                self.assertIsNotNone(
                    missing_strings,
                    'There is not a PO file for module {}'
                    ' with locale: "{}"'.format(
                        self.config['module'], test_lang
                    )
                )
                self.assertItemsEqual(
                    [],
                    missing_strings,
                    'There are {} missing strings in the PO file'
                    ' of the module {}\nThe missing strings are:\n'
                    '\n{}\n'.format(
                        len(missing_strings), self.config['module'],
                        '\n'.join(missing_strings)
                    )
                )
                self.assertItemsEqual(
                    [],
                    untranslated_strings,
                    'There are {} untranslated strings in the PO file'
                    ' of the module {}\nThe untranslated strings are:\n'
                    '\n{}\n'.format(
                        len(untranslated_strings), self.config['module'],
                        '\n'.join(untranslated_strings)
                    )
                )
Beispiel #8
0
    def test_translate_modules(self):
        """
        Test translated strings in the module using the .po and .pot files
        """

        from os.path import join, isdir
        from tools import trans_export
        from six.moves import StringIO
        from destral.utils import compare_pofiles, TempDir

        if not self.config['testing_langs']:
            logger.warning('Configuration variable "DESTRAL_TESTING_LANGS" has'
                           ' not been initialized')
            return

        mod_path = join(self.openerp.config['addons_path'],
                        self.config['module'])
        trad_path = join(mod_path, 'i18n')

        self.assertTrue(
            isdir(trad_path),
            'Module {} has no translations'.format(self.config['module']))

        logger.info('Checking translations for module %s',
                    self.config['module'])
        with Transaction().start(self.database) as txn:
            cursor = txn.cursor

            # Generate POT data from loaded strings
            trans_data = StringIO()
            trans_export(False, [self.config['module']],
                         trans_data,
                         'po',
                         dbname=cursor.dbname)
            trans_obj = self.openerp.pool.get('wizard.module.lang.export')
            trans_data = trans_obj.append_report_translations(
                txn.cursor, txn.user, [self.config['module']], 'pot',
                trans_data)

        with TempDir() as temp:
            tmp_pot = '{}/{}.pot'.format(temp.dir, self.config['module'])
            # Write POT data into temp file
            with open(tmp_pot, 'w') as pot:
                pot.write(trans_data.getvalue())
            pot_path = join(trad_path, '{}.pot'.format(self.config['module']))
            missing_strings, untranslated_strings = compare_pofiles(
                tmp_pot, pot_path)
            # Don't compare untranslated strings in POT
            #   because POT files do not contain translations
            self.assertIsNotNone(
                missing_strings,
                'There is not a POT file for module {}'.format(
                    self.config['module']))
            self.assertItemsEqual(
                [], missing_strings,
                'There are {} missing strings in the POT file'
                ' of the module {}\nThe missing strings are:\n'
                '\n{}\n'.format(len(missing_strings), self.config['module'],
                                '\n'.join(missing_strings)))
            logger.info('Checking translations for langs: {}'.format(
                self.config['testing_langs']))
            for test_lang in self.config['testing_langs']:
                po_path = join(trad_path, '{}.po'.format(test_lang))
                missing_strings, untranslated_strings = compare_pofiles(
                    tmp_pot, po_path)
                self.assertIsNotNone(
                    missing_strings, 'There is not a PO file for module {}'
                    ' with locale: "{}"'.format(self.config['module'],
                                                test_lang))
                self.assertItemsEqual(
                    [], missing_strings,
                    'There are {} missing strings in the PO file'
                    ' of the module {}\nThe missing strings are:\n'
                    '\n{}\n'.format(len(missing_strings),
                                    self.config['module'],
                                    '\n'.join(missing_strings)))
                self.assertItemsEqual(
                    [], untranslated_strings,
                    'There are {} untranslated strings in the PO file'
                    ' of the module {}\nThe untranslated strings are:\n'
                    '\n{}\n'.format(len(untranslated_strings),
                                    self.config['module'],
                                    '\n'.join(untranslated_strings)))
Beispiel #9
0
    import csv

    if tools.config["language"]:
        msg = "language %s" % (tools.config["language"], )
    else:
        msg = "new language"
    logger.info('writing translation file for %s to %s', msg,
                tools.config["translate_out"])

    fileformat = os.path.splitext(
        tools.config["translate_out"])[-1][1:].lower()
    buf = file(tools.config["translate_out"], "w")
    dbname = tools.config['db_name']
    cr = pooler.get_db(dbname).cursor()
    tools.trans_export(tools.config["language"],
                       tools.config["translate_modules"] or ["all"], buf,
                       fileformat, cr)
    cr.close()
    buf.close()

    logger.info('translation file written successfully')
    sys.exit(0)

if tools.config["translate_in"]:
    context = {'overwrite': tools.config["overwrite_existing_translations"]}
    dbname = tools.config['db_name']
    cr = pooler.get_db(dbname).cursor()
    tools.trans_load(cr,
                     tools.config["translate_in"],
                     tools.config["language"],
                     context=context)
Beispiel #10
0
# translation stuff
#----------------------------------------------------------
if tools.config["translate_out"]:
    import csv

    if tools.config["language"]:
        msg = "language %s" % (tools.config["language"],)
    else:
        msg = "new language"
    logger.notifyChannel("init", netsvc.LOG_INFO, 
                         'writing translation file for %s to %s' % (msg, 
                                                                    tools.config["translate_out"]))

    fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
    buf = file(tools.config["translate_out"], "w")
    tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
    buf.close()

    logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully')
    sys.exit(0)

if tools.config["translate_in"]:
    tools.trans_load(tools.config["db_name"], 
                     tools.config["translate_in"], 
                     tools.config["language"])
    sys.exit(0)

#----------------------------------------------------------------------------------
# if we don't want the server to continue to run after initialization, we quit here
#----------------------------------------------------------------------------------
if tools.config["stop_after_init"]:
Beispiel #11
0
    def _export(self, dbname, uid, ids, context=None):
        #modules = ['account_mcdb']
        modules = 'all_installed'
        try:
            cr = pooler.get_db(dbname).cursor()

            this = self.browse(cr, uid, ids)[0]
            if this.modules:
                modules = map(lambda m: m.name, this.modules)
                modules.sort()

            if this.lang:
                filename = get_iso_codes(this.lang)
            this.name = "%s.%s" % (filename, this.format)
            ignore_name = ['ir.filters,model_id', 'ir.actions.server,copy_object', 'ir.ui.menu,icon', 'ir.sequence,code', 'stock.location,icon']
            if this.format == 'xls':
                trans = tools.trans_generate(this.lang, modules, cr, ignore_name=ignore_name)
                if trans:
                    headers = []
                    for h in trans.pop(0):
                        headers.append([h, 'char'])

                    xml = SpreadsheetCreator(title=this.name, headers=headers, datas=trans)
                    out = base64.encodestring(xml.get_xml(default_filters=['decode.utf8']))
            else:
                buf=cStringIO.StringIO()
                tools.trans_export(this.lang, modules, buf, this.format, cr, ignore_name=ignore_name)
                out = base64.encodestring(buf.getvalue())
                buf.close()

            subject = _("Export translation %s %s ") % (this.lang, this.format)
            summary = _('''Export translation %s %s
    Find the file in attachment in the right panel.''') % (this.lang, this.format)
            request_obj = self.pool.get('res.request')
            req_id = request_obj.create(cr, uid, {
                'name': subject,
                'act_from': uid,
                'act_to': uid,
                'export_trans': True,
                'body': summary,
            })

            if req_id:
                request_obj.request_send(cr, uid, [req_id])

            attachment = self.pool.get('ir.attachment')
            attachment.create(cr, uid, {
                'name': this.name,
                'datas_fname': this.name,
                'description': 'Translations',
                'res_model': 'res.request',
                'res_id': req_id,
                'datas': out,
            })
            cr.commit()
            cr.close(True)
        except Exception, e:
            cr.rollback()
            req_id = self.pool.get('res.request').create(cr, uid, {
                'name': _('Export translation failed'),
                'act_from': uid,
                'act_to': uid,
                'export_trans': True,
                'body': _('''The process to export the translations failed !
                %s
                ''')% (e,),
            })
            cr.commit()
            cr.close(True)
            raise