view export_weblate.py @ 248:83bf42767d85 default tip

Update version in sao.js after release issue11852
author Cédric Krier <ced@b2ck.com>
date Tue, 01 Nov 2022 16:39:45 +0100
parents eb75bb0a5498
children
line wrap: on
line source

#!/usr/bin/env python
import os
import shutil
from optparse import OptionParser

from proteus import config, Model, Wizard


def main(repository, tryton, sao, options):
    config.set_trytond(database=options.database, user='root')

    Lang = Model.get('ir.lang')
    Module = Model.get('ir.module')
    Translation = Model.get('ir.translation')
    Menu = Model.get('ir.ui.menu')

    Wizard('ir.translation.set', [Menu()]).execute('set_')
    Wizard('ir.translation.clean').execute('clean')

    languages = Lang.find([
            ('translatable', '=', True),
            ('code', '!=', 'en'),
            ])
    english, = Lang.find([
            ('code', '=', 'en'),
            ])

    for language in languages:
        update_wizard = Wizard('ir.translation.update')
        update_wizard.start.language = language
        update_wizard.execute('update')

    translations = Translation.find([
            ('value', '!=', None),
            ('value', '!=', ''),
            ])
    Translation.write(translations, {'value': ''}, {})

    for language in (languages + [english]):
        if language == english:
            code = 'templates'
        else:
            code = language.code
        try:
            os.mkdir(os.path.join(repository, code))
        except OSError:
            pass
    for module in Module.find([('state', '=', 'activated')]):
        for language in (languages + [english]):
            export_wizard = Wizard('ir.translation.export')
            export_wizard.form.language = language
            export_wizard.form.module = module
            export_wizard.execute('export')
            if not export_wizard.form.file:
                continue
            if language == english:
                poname = '%s.pot' % module.name
                path = 'templates'
            elif module.name in {'ir', 'res'}:
                poname = '%s.po' % language.code
                path = os.path.join(
                    'trytond', 'trytond', module.name, 'locale')
            else:
                poname = '%s.po' % language.code
                path = os.path.join('modules', module.name, 'locale')
            pofile = os.path.join(repository, path, poname)
            with open(pofile, 'w') as f:
                f.write(export_wizard.form.file.decode('utf-8'))

    locale = os.path.join(tryton, 'tryton', 'data', 'locale')
    for language in (languages + [english]):
        lang = language.code
        if lang.startswith('.'):
            continue
        if not os.path.isdir(os.path.join(locale, lang)):
            continue
        src = os.path.join(locale, lang, 'LC_MESSAGES', 'tryton.po')
        if not os.path.isfile(src):
            continue
        dst = os.path.join(
            repository, 'tryton', 'tryton', 'data', 'locale', lang,
            'LC_MESSAGES', 'tryton.po')
        try:
            os.makedirs(os.path.dirname(dst))
        except OSError:
            pass
        shutil.copyfile(src, dst)
    src = os.path.join(locale, 'tryton.pot')
    dst = os.path.join(repository, 'templates', 'tryton.pot')
    try:
        os.makedirs(os.path.dirname(dst))
    except OSError:
        pass
    shutil.copyfile(src, dst)

    locale = os.path.join(sao, 'locale')
    for language in (languages + [english]):
        lang = language.code
        src = os.path.join(locale, lang + '.po')
        if not os.path.isfile(src):
            continue
        dst = os.path.join(repository, 'sao', 'locale', lang + '.po')
        try:
            os.makedirs(os.path.dirname(dst))
        except OSError:
            pass
        shutil.copyfile(src, dst)
    src = os.path.join(locale, 'messages.pot')
    dst = os.path.join(repository, 'templates', 'sao.pot')
    try:
        os.makedirs(os.path.dirname(dst))
    except OSError:
        pass
    shutil.copyfile(src, dst)


if __name__ == '__main__':
    parser = OptionParser("%prog [option] tryton sao repository")
    parser.add_option('-d', '--database', dest='database')

    options, arguments = parser.parse_args()

    if not len(arguments) == 3:
        parser.error('Missing arguments')
    tryton, sao, repository = arguments
    if not os.path.isdir(repository):
        parser.error('repository must be a directory')
    if not options.database:
        parser.error('Missing database')

    main(repository, tryton, sao, options)

Repository Layout

/ Tryton top level repositories
modules Modules
public Public repositories
tpf Tryton Foundation repositories
sandbox Sandbox