A Dimarts, 17 d'abril de 2012 13:29:38, Sergi Almacellas Abellana va escriure:
> >> Me encargo yo de esta parte, os mando los ficheros para que lo 
> >> podáis subir entre el jueves i el viernes.
> > 
> > Ok, gracias. Mírate este hilo:
> > 
> >
> > http://groups.google.com/group/tryton-dev/browse_thread/thread/49f9993008
> > b7f27c
> 
> Muchas gracias. Os adjunto los ficheros.
> 
> ¿Os parece bien que me encargue también de la parte del cliente para el 
> ca_ES?

La versión catalana la hice yo a partir de un script de traducción automática 
que cree y que utiliza apertium. Te adjunto el script por si lo quieres hacer 
tu mismo. Después solamente hay que repasarlo pero el resultado es bastante 
bueno. En el caso del servidor sobretodo habrá que sustituir "seient" por 
"assentament" :-)

-- 
Albert Cervera i Areny
http://www.NaN-tic.com
Tel: +34 93 553 18 03

http://twitter.com/albertnan 
http://www.nan-tic.com/blog

-- 
[email protected] mailing list
#!/usr/bin/python

import os
import sys
import glob
import subprocess
import polib
import shutil

def check_output(app, stdin=''):
    process = subprocess.Popen(app, stdout=subprocess.PIPE, 
            stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    stdout, stderr = process.communicate( stdin.encode('utf-8') )
    print "SENT: ", stdin
    print "GOT: ", stdout
    process.wait()
    return unicode(stdout, 'utf-8')

class Translator:
    def __init__(self, source, destination):
        """
        Creates a Translator object with 'source' and 'destination' as 
        languages. Languages should be a two letter name such as 'ca' 
        or 'es'.
        """
        self._source = source
        self._destination = destination
        
    def translate(self, text):
        lang = '%s-%s' % (self._source, self._destination)
        translation = check_output(['apertium','-u','es-ca'], text)
        return translation

def translate_po(translator, filename, entries='missing'):
    """
    entries may be 'missing'
    """
    assert entries in ('missing', 'all'), 'entries parameter must be '\
            '"missing" or "all"'
    po = polib.pofile( filename )
    if entries == 'missing':
        # Includes fuzzy entries
        entries = po.untranslated_entries
    else:
        po
    for entry in po:
        entry.msgstr = translator.translate( entry.msgstr )
        if not 'fuzzy' in entry.flags:
            entry.flags.append('fuzzy')
    po.save()


def translate_all():
    """
    Translates all files in a directory tree from Spanish to Catalan.
    Statistics from all trytond and trytond/modules messages show that
    only 6.8358985 % of messages had to be changed. There were 5003 
    messages and 4661 were not changed after user review of all strings.
    """
    glob_path = os.path.join('*', 'locale', 'es_ES.po')

    translator = Translator('es','ca')

    tryton_only = False

    file_count = 0
    string_count = 0
    for src_file in glob.glob(glob_path):
        file_count += 1
        dst_file = src_file.split(os.path.sep)
        print 'Module %s' % dst_file[-3]
        dst_file = dst_file[:-1] + ['ca_ES.po']
        if tryton_only:
            tryton_config = dst_file[:-2] + ['__tryton__.py']
            tryton_config = os.path.join(*tryton_config)
            data = open(tryton_config, 'r').read()
            rep = 'locale/de_DE.po'
            data = data.replace(rep,"locale/ca_ES.po',\n        '%s" % rep)
            print "DATA: ", data
            f = open(tryton_config, 'w')
            f.write( data )
            f.close()
            continue

        dst_file = os.path.join(*dst_file)
        #if not os.path.exists(dst_file):
        if True:
            print 'Creating...'
            po = polib.pofile(src_file)
            string_count += len(po)
            shutil.copyfile(src_file, dst_file)
            translate_po(translator, dst_file, 'all')
        else:
            print 'Merging...'
            pot = polib.pofile(src_file)
            po = polib.pofile(dst_file)
            po.merge(pot)
            po.save()
            #check_output(['msgfmt', src_file, '-o', dst_file])
            translate_po(translator, dst_file, 'missing')

        string_count += len(po)

        print "PATH: ", dst_file

    print 
    print 'Statistics'
    print '----------'
    print
    print 'Files: %d' % file_count
    print 'Messages: %d' % string_count
    print

translate_all()

def clear_fuzzy_flags():
    glob_path = os.path.join('*', 'locale', 'es_ES.po')

    translator = Translator('es','ca')

    tryton_only = False

    file_count = 0
    string_count = 0
    for src_file in glob.glob(glob_path):
        file_count += 1
        dst_file = src_file.split(os.path.sep)
        print 'Module %s' % dst_file[-3]
        dst_file = dst_file[:-1] + ['ca_ES.po']
        if tryton_only:
            tryton_config = dst_file[:-2] + ['__tryton__.py']
            tryton_config = os.path.join(*tryton_config)
            data = open(tryton_config, 'r').read()
            rep = 'locale/de_DE.po'
            data = data.replace(rep,"locale/ca_ES.po',\n        '%s" % rep)
            print "DATA: ", data
            f = open(tryton_config, 'w')
            f.write( data )
            f.close()
            continue

        dst_file = os.path.join(*dst_file)
        #if not os.path.exists(dst_file):
        if True:
            print 'Creating...'
            po = polib.pofile(src_file)
            string_count += len(po)
            shutil.copyfile(src_file, dst_file)
            translate_po(translator, dst_file, 'all')
        else:
            print 'Merging...'
            pot = polib.pofile(src_file)
            po = polib.pofile(dst_file)
            po.merge(pot)
            po.save()
            #check_output(['msgfmt', src_file, '-o', dst_file])
            translate_po(translator, dst_file, 'missing')

        string_count += len(po)

        print "PATH: ", dst_file

    print 
    print 'Statistics'
    print '----------'
    print
    print 'Files: %d' % file_count
    print 'Messages: %d' % string_count
    print

Responder a