Hi,

I've all the Strings for catalan and Spanish in pootle translated (Thanks Jordi and all how contributed), so I developed some script to get all the translations on a local instance so I can test that all are correct.

I attach this script so if somebody finds it usefull. The usage is quite easy:

python pootle2tryton.py locale environment_directory

For example:

python pootle2tryton.py ca_ES . (from environemt root)
python pootle2tryton.py es_ES /home/sergi/trytond/

Hope it helps!
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/5710D19E.3000308%40koolpi.com.
import os
import requests
import StringIO
from optparse import OptionParser
from zipfile import ZipFile

import polib

from trytond.ir.translation import TrytonPOFile


class PootlePoFile(TrytonPOFile):

    def obsolete_entries(self):
        # Don't import obsolete entries, leave them in pootle
        return []


def main(lang, directory):
    url = 'https://pootle.tryton.org/export/?path=/%s/tryton/' % locale
    r = requests.get(url, stream=True)
    zipfile = ZipFile(StringIO.StringIO(r.content))
    for file_name in zipfile.namelist():
        name = file_name.split('/')[-1][:-3]
        pofile = polib.pofile(zipfile.open(file_name).read().decode('utf-8'),
            klass=PootlePoFile)
        pofile.metadata = {
            'Content-Type': 'text/plain; charset=utf-8',
            }

        if name == 'tryton':
            output = os.path.join(
                directory, 'tryton', 'tryton', 'data', 'locale',
                lang, 'LC_MESSAGES', 'tryton.po')
        elif name == 'sao':
            output = os.path.join(
                directory, 'sao', 'locale', lang + '.po')
        elif name in ['ir', 'res']:
            output = os.path.join(
                directory, 'trytond', 'trytond',
                name, 'locale', lang + '.po')
        else:
            output = os.path.join(
                directory, 'trytond', 'trytond', 'modules',
                name, 'locale', lang + '.po')
        if not os.path.exists(os.path.dirname(output)):
            continue
        with open(output, 'w') as f:
            f.write(unicode(pofile).encode('utf-8'))

if __name__ == '__main__':
    parser = OptionParser('%prog locale tryton_directory')

    _, args = parser.parse_args()

    if not len(args) == 2:
        parser.error('Missing arguments')
    locale, directory = args
    main(locale, directory)

Reply via email to