Пример #1
0
def merge(arguments):
    # Determine final argument values.
    pot_fn = arguments.pot_fn
    merge_fn = arguments.merge_fn
    merge2_fn = arguments.merge2_fn
    if merge2_fn == merge_fn:
        merge2_fn = False

    if not pot_fn:
        short_usage(1, u"No pot file specified as target with --pot.")
    if not merge_fn:
        short_usage(1, u"No potfile specified as source with --merge.")

    try:
        orig_ctl = catalog.MessageCatalog(filename=pot_fn)
        merge_ctl = catalog.MessageCatalog(filename=merge_fn)
        if merge2_fn:
            merge2_ctl = catalog.MessageCatalog(filename=merge2_fn)
    except IOError as e:
        short_usage(0, 'I/O Error: %s' % e)

    # merge
    orig_ctl.add_missing(merge_ctl, '', 1)
    if merge2_fn:
        orig_ctl.add_missing(merge2_ctl, '', 1)
    orig_ctl.mime_header['POT-Creation-Date'] = catalog.now()
    file = open(pot_fn, 'w')
    writer = catalog.POWriter(file, orig_ctl)
    writer.write(msgstrToComment=True)
Пример #2
0
def merge():
    try:
        opts, files = getopt.getopt(sys.argv[2:], 'sm:p:',
                                    ('pot=', 'merge=', 'merge2='))
    except:
        usage(1)

    pot_fn = None
    merge_fn = None
    for opt, arg in opts:
        if opt in ('-p', '--pot'):
            pot_fn = arg
        if opt in ('-m', '--merge'):
            merge_fn = arg
        if opt in ('--merge2'):
            merge2_fn = arg

    if not pot_fn:
        short_usage(1, u"No pot file specified as target with --pot.")
    if not merge_fn:
        short_usage(1, u"No potfile specified as source with --merge.")

    try:
        orig_ctl = catalog.MessageCatalog(filename=pot_fn)
        merge_ctl = catalog.MessageCatalog(filename=merge_fn)
        if merge2_fn:
            merge2_ctl = catalog.MessageCatalog(filename=merge2_fn)
    except IOError, e:
        short_usage(0, 'I/O Error: %s' % e)
Пример #3
0
def main():
    os.chdir('..')
    os.chdir('i18n')

    poFilesPlone = getPoFiles('plone')
    if not poFilesPlone:
        print 'No po-files were found for Plone.'
        sys.exit(2)

    poFilesATCT = getPoFiles('atcontenttypes')
    if not poFilesATCT:
        print 'No po-files were found for ATContentTypes.'
        sys.exit(3)

    # format: 'old-domain' : ['msgid1', 'msgid2', ...]
    relocated = {'plone' :
                  ['Changes saved.', 'Please correct the indicated errors.',
                   'Rotate 180', 'help_boolean_criteria_bool',
                   'help_criteria_field_name', 'help_custom_view',
                   'help_custom_view_fields', 'help_date_range_criteria_end',
                   'help_date_range_criteria_start', 'help_exclude_from_nav',
                   'help_limit_number', 'help_news_image', 'help_shortname',
                   'help_path_criteria_value', 'help_string_criteria_value',
                   'help_portal_type_criteria_value', 'help_url',
                   'label_body_text', 'label_boolean_criteria_bool',
                   'label_contact_email', 'label_contact_name',
                   'label_contact_phone', 'label_criteria_field_name',
                   'label_custom_view', 'label_custom_view_fields',
                   'label_date_range_criteria_end', 'label_event_announcement',
                   'label_date_range_criteria_start', 'label_event_attendees',
                   'label_event_end', 'label_event_location',
                   'label_event_start', 'label_event_type',
                   'label_exclude_from_nav', 'label_file', 'label_image',
                   'label_image_caption', 'label_inherit_criteria',
                   'label_item_count', 'label_limit_number', 'label_news_image',
                   'label_path_criteria_recurse', 'label_path_criteria_value',
                   'label_related_items', 'label_short_name',
                   'label_string_criteria_value', 'label_url',
                  ]
                }

    # make sure we only try on languages for which both po files exist
    ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
    atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]

    languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
    changes = {'plone' : False, 'atcontenttypes' : False}

    for lang in languages:
        po_ctl = {}
        try:
            po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
        try:
            po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
Пример #4
0
def filter(arguments):
    f1_ctl = catalog.MessageCatalog(filename=arguments.file1)
    f2_ctl = catalog.MessageCatalog(filename=arguments.file2)

    for msgid in f1_ctl.keys():
        if msgid in f2_ctl:
            del f1_ctl[msgid]

    writer = catalog.POWriter(sys.stdout, f1_ctl)
    writer.write(sort=False, msgstrToComment=True)
Пример #5
0
def arg_list(arguments):
    table = arguments.table
    products = arguments.products
    tiered = arguments.tiered

    # get all the files
    pos = {}
    pots = {}
    for product in products:
        if not pos.get(product, False):
            pos[product] = []
        pos[product].extend(utils.getPoFiles(product=product))
        if not pots.get(product, False):
            pots[product] = []
        pots[product].extend(utils.getPotFiles(product=product))

    # create catalogs of them
    pot_ctl = None
    for product in pots:
        for file in pots[product]:
            ctl = catalog.MessageCatalog(filename=file)
            if pot_ctl is None:
                pot_ctl = ctl
            else:
                pot_ctl.merge(ctl)

    if not pot_ctl:
        short_usage(1, 'Error: No pot files found.')

    po_ctls = {}
    for product in pos:
        for file in pos[product]:
            ctl = catalog.MessageCatalog(filename=file)
            language = utils.getLanguage(product, file)
            lang_ctl = po_ctls.get(language, None)
            if lang_ctl is None:
                po_ctls[language] = ctl
            else:
                po_ctls[language].merge(ctl)

    if not po_ctls:
        short_usage(1, 'Error: No po files found.')

    po_catalogs = []
    # flatten to list and sort
    keys = sorted(po_ctls.keys())
    for key in keys:
        po_catalogs.append(po_ctls[key])

    visualisation.make_listing(
        pot_ctl, po_catalogs, table=table, tiered=tiered)
Пример #6
0
def admix(arguments):
    base_ctl = catalog.MessageCatalog(filename=arguments.file1)
    mixin_ctl = catalog.MessageCatalog(filename=arguments.file2)

    for msgid in mixin_ctl:
        mixin_msgstr = mixin_ctl[msgid].msgstr

        if mixin_msgstr and msgid in base_ctl and not base_ctl[msgid].msgstr:
            entry = base_ctl[msgid]
            entry.msgstr = mixin_ctl[msgid].msgstr
            base_ctl[msgid] = entry

    writer = catalog.POWriter(sys.stdout, base_ctl)
    writer.write(sort=False)
Пример #7
0
def rebuild_pot():
    try:
        opts, files = getopt.getopt(
            sys.argv[2:], 'mp:c:',
            ('pot=', 'create=', 'merge=', 'merge2=', 'exclude='))
    except:
        usage(1)

    pot_fn = None
    merge_fn = None
    merge2_fn = None
    create_domain = None
    exclude = ()
    for opt, arg in opts:
        if opt in ('-p', '--pot'):
            pot_fn = arg
        if opt in ('-c', '--create'):
            create_domain = arg
        if opt in ('-m', '--merge'):
            merge_fn = arg
        if opt in ('--merge2'):
            merge2_fn = arg
        if opt in ('--exclude'):
            exclude = tuple(arg.split())

    if not pot_fn:
        short_usage(1, u"No pot file specified as target with --pot.")

    if merge2_fn == merge_fn:
        merge2_fn = False

    path = files
    merge_ctl = None

    try:
        if create_domain is not None:
            orig_ctl = catalog.MessageCatalog(domain=create_domain)
        else:
            orig_ctl = catalog.MessageCatalog(filename=pot_fn)
        if merge_fn:
            merge_ctl = catalog.MessageCatalog(filename=merge_fn)
        if merge2_fn:
            merge2_ctl = catalog.MessageCatalog(filename=merge2_fn)
        ptreader = catalog.PTReader(path, create_domain, exclude=exclude)
        pyreader = catalog.PYReader(path, create_domain, exclude=exclude)
        gsreader = catalog.GSReader(path, create_domain, exclude=exclude)
    except IOError, e:
        short_usage(0, 'I/O Error: %s' % e)
Пример #8
0
def filter(arguments):
    f1_ctl = catalog.MessageCatalog(filename=arguments.file1)
    f2_ctl = catalog.MessageCatalog(filename=arguments.file2)

    # On Python 3.7 we can get an error if we delete immediately:
    # RuntimeError: OrderedDict mutated during iteration
    # So first gather items in a list.  That is better anyway.
    to_delete = []
    for msgid in f1_ctl.keys():
        if msgid in f2_ctl:
            to_delete.append(msgid)
    for msgid in to_delete:
        del f1_ctl[msgid]

    writer = catalog.POWriter(sys.stdout, f1_ctl)
    writer.write(sort=False, msgstrToComment=True)
Пример #9
0
def main():
    if len(sys.argv) < 3:
        print('You have to specify the product and the new text for domain.')
        sys.exit(1)

    product = getLongProductName(sys.argv[1])
    domain = sys.argv[2]

    os.chdir('..')
    os.chdir('i18n')

    poFiles = getPoFiles(product, all=True)
    if poFiles == []:
        print('No po-files were found for the given product.')
        sys.exit(2)

    for poFile in poFiles:
        try:
            po_ctl = catalog.MessageCatalog(filename=poFile)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)
        po_ctl.mime_header['Domain'] = domain
        file = open(poFile, 'w')
        writer = catalog.POWriter(file, po_ctl)
        writer.write(sort=False)
Пример #10
0
def main():
    if len(sys.argv) < 3:
        print 'You have to specify the product and the new text for projectid.'
        sys.exit(1)

    product = getLongProductName(sys.argv[1])
    projectid = sys.argv[2]

    os.chdir('..')
    os.chdir('i18n')

    poFiles = getPoFiles(product, all=True)
    if poFiles == []:
        print 'No po-files were found for the given product.'
        sys.exit(2)

    for poFile in poFiles:
        try:
            po_ctl = catalog.MessageCatalog(filename=poFile)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
        po_ctl.mime_header['Project-Id-Version'] = projectid
        file = open(poFile, 'w')
        writer = catalog.POWriter(file, po_ctl)
        writer.write(sort=False)
Пример #11
0
def main():
    if len(sys.argv) < 2:
        print('You have to specify the product.')
        sys.exit(1)

    product = getLongProductName(sys.argv[1])

    os.chdir('..')
    os.chdir('i18n')

    poFiles = getPoFiles(product, all=True)
    if poFiles == []:
        print('No po-files were found for the given product.')
        sys.exit(2)

    for poFile in poFiles:
        try:
            po_ctl = catalog.MessageCatalog(filename=poFile)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)

        try:
            language = po_ctl.commentary_header[0].split('to ')[1:][0]
            po_ctl.commentary_header[
                0] = 'Translation of ' + product + '.pot to ' + language
        except IndexError:
            print(poFile)

        file = open(poFile + '-new', 'w')
        writer = catalog.POWriter(file, po_ctl)
        writer.write(sort=False)
Пример #12
0
def filter():
    if len(sys.argv[2:]) != 2:
        usage(1)

    file1 = sys.argv[2]
    file2 = sys.argv[3]

    f1_ctl = catalog.MessageCatalog(filename=file1)
    f2_ctl = catalog.MessageCatalog(filename=file2)

    for msgid in f1_ctl.keys():
        if msgid in f2_ctl:
            del f1_ctl[msgid]

    writer = catalog.POWriter(sys.stdout, f1_ctl)
    writer.write(sort=False, msgstrToComment=True)
Пример #13
0
 def test_init(self):
     failing = False
     try:
         catalog.MessageCatalog()
     except AssertionError:
         failing = True
     self.assertTrue(failing,
                     'Init without parameters should not be allowed.')
Пример #14
0
def admix():
    if len(sys.argv) != 4:
        usage(1)

    fn = sys.argv[2]
    base_ctl = catalog.MessageCatalog(filename=fn)

    fn = sys.argv[3]
    mixin_ctl = catalog.MessageCatalog(filename=fn)

    for msgid in mixin_ctl:
        mixin_msgstr = mixin_ctl[msgid].msgstr

        if mixin_msgstr and msgid in base_ctl and not base_ctl[msgid].msgstr:
            entry = base_ctl[msgid]
            entry.msgstr = mixin_ctl[msgid].msgstr
            base_ctl[msgid] = entry

    writer = catalog.POWriter(sys.stdout, base_ctl)
    writer.write(sort=False)
Пример #15
0
def trmerge():
    if len(sys.argv) != 4:
        usage(1)

    fn = sys.argv[2]
    base_ctl = catalog.MessageCatalog(filename=fn)

    fn = sys.argv[3]
    mixin_ctl = catalog.MessageCatalog(filename=fn)

    for msgid in mixin_ctl:
        mixin_msgstr = mixin_ctl[msgid].msgstr

        if mixin_msgstr:
            entry = base_ctl.get(msgid, mixin_ctl[msgid])
            entry.msgstr = mixin_msgstr
            if ', fuzzy' in entry.comments:
                entry.comments.remove(', fuzzy')
            base_ctl[msgid] = entry

    writer = catalog.POWriter(sys.stdout, base_ctl)
    writer.write(sort=False)
Пример #16
0
def sync(arguments):
    pot_fn = arguments.pot_fn
    if not pot_fn:
        short_usage(1, u"No pot file specified as target with --pot.")

    files = filter_isfile(arguments.files)

    try:
        pot_ctl = catalog.MessageCatalog(filename=pot_fn)
        po_ctls = [catalog.MessageCatalog(filename=fn) for fn in files]
    except IOError as e:
        short_usage(1, 'I/O Error: %s' % e)

    for po in po_ctls:
        added_msgids, removed_msgids = po.sync(pot_ctl)

        file = open(po.filename, 'w')
        writer = catalog.POWriter(file, po)
        writer.write(msgstrToComment=False, sync=True)

        print('%s: %s added, %s removed' %
              (po.filename, len(added_msgids), len(removed_msgids)))
        file.close()
Пример #17
0
def trmerge(arguments):
    base_ctl = catalog.MessageCatalog(filename=arguments.file1)
    mixin_ctl = catalog.MessageCatalog(filename=arguments.file2)

    for msgid in mixin_ctl:
        base_entry = base_ctl.get(msgid)
        if base_entry is None and arguments.ignore_extra:
            # This msgid is not in the original po-file and the user
            # has chosen to ignore it.
            continue
        mixin_entry = mixin_ctl[msgid]
        mixin_msgstr = mixin_entry.msgstr
        if not mixin_msgstr:
            # The mixin translation is empty.
            continue
        if ', fuzzy' in mixin_entry.comments:
            # The mixin translation is fuzzy.
            continue
        if (arguments.no_override
                and base_entry is not None
                and base_entry.msgstr
                and ', fuzzy' not in base_entry.comments):
            # The user does not want to override and we have an
            # existing, non-fuzzy translation.
            continue
        # Okay, we have a fine new translation.
        entry = base_entry or mixin_entry
        entry.msgstr = mixin_msgstr
        if ', fuzzy' in entry.comments:
            # The base entry was fuzzy, but the mixin has a different
            # or non-fuzzy translation.
            entry.comments.remove(', fuzzy')
        # Finally store the new entry
        base_ctl[msgid] = entry

    writer = catalog.POWriter(sys.stdout, base_ctl)
    writer.write(sort=False)
Пример #18
0
 def setUp(self):
     self.domain = 'testing'
     self.mc = catalog.MessageCatalog(domain=self.domain)
     self.msgid = 'test msgid'
     self.msgstr = 'test text'
     self.references = ['test1.pt', 'test2.pt']
     self.default_text = 'test default'
     self.default_comment = '%s"%s"' % (
         catalog.DEFAULT_COMMENT, self.default_text)  # noqa
     self.automatic_comments = [
         'first line', 'second line', self.default_comment
     ]  # noqa
     self.orig_text = 'test original'
     self.orig_comment = '%s"%s"' % (
         catalog.ORIGINAL_COMMENT, self.orig_text)  # noqa
     self.comments = ['A comment', self.orig_comment]
Пример #19
0
def list():
    try:
        opts, files = getopt.getopt(sys.argv[2:], 'tp:',
                                    ('products=', 'table='))
    except:
        usage(1)

    table = False
    products = []
    for opt, arg in opts:
        if opt in ('-p', '--products'):
            products.append(arg)
        if opt in ('-t', '--table'):
            table = True

    if not products:
        short_usage(1, u"No products specified with --products.")

    products.extend(files)

    # get all the files
    pos = {}
    pots = {}
    for product in products:
        if not pos.get(product, False):
            pos[product] = []
        pos[product].extend(utils.getPoFiles(product=product))
        if not pots.get(product, False):
            pots[product] = []
        pots[product].extend(utils.getPotFiles(product=product))

    # create catalogs of them
    pot_ctl = None
    for product in pots:
        for file in pots[product]:
            ctl = catalog.MessageCatalog(filename=file)
            if pot_ctl is None:
                pot_ctl = ctl
            else:
                pot_ctl.merge(ctl)

    if not pot_ctl:
        short_usage(1, 'Error: No pot files found.')

    po_ctls = {}
    for product in pos:
        for file in pos[product]:
            ctl = catalog.MessageCatalog(filename=file)
            language = utils.getLanguage(product, file)
            lang_ctl = po_ctls.get(language, None)
            if lang_ctl is None:
                po_ctls[language] = ctl
            else:
                po_ctls[language].merge(ctl)

    if not po_ctls:
        short_usage(1, 'Error: No po files found.')

    po_catalogs = []
    # flatten to list and sort
    keys = po_ctls.keys()
    keys.sort()
    for key in keys:
        po_catalogs.append(po_ctls[key])

    visualisation.make_listing(pot_ctl, po_catalogs, table=table)
Пример #20
0
    def testPoFile(self):
        """ Testing po file """
        po = self.po
        product = self.product
        pot_cat = self.pot_cat
        pot_len = self.pot_len
        poName = getFileFromPath(po)
        localesLayout = False
        if 'LC_MESSAGES' in po:
            localesLayout = True

        file = open(po, 'r')
        try:
            lines = file.readlines()
        except IOError as msg:
            self.fail('Can\'t read po file %s:\n%s' % (poName, msg))
        file.close()
        try:
            mo = msgfmt.Msgfmt(lines)
        except msgfmt.PoSyntaxError as msg:
            self.fail('PoSyntaxError: Invalid po data syntax in file %s:\n%s' %
                      (poName, msg))
        except SyntaxError as msg:
            self.fail(
                'SyntaxError: Invalid po data syntax in file %s (Can\'t parse file with eval():\n%s'
                % (poName, msg))
        except Exception as msg:
            self.fail('Unknown error while parsing the po file %s:\n%s' %
                      (poName, msg))
        try:
            tro = GNUTranslations(mo.getAsFile())
        except UnicodeDecodeError as msg:
            self.fail('UnicodeDecodeError in file %s:\n%s' % (poName, msg))
        except msgfmt.PoSyntaxError as msg:
            self.fail('PoSyntaxError: Invalid po data syntax in file %s:\n%s' %
                      (poName, msg))

        domain = tro._info.get('domain', None)
        if localesLayout:
            self.failIf(domain,
                        'Po file %s has a domain set inside the file!' % po)
        else:
            self.failUnless(domain, 'Po file %s has no domain!' % po)

        language = tro._info.get('language-code', None)
        if localesLayout:
            self.failIf(language, 'Po file %s has a language set inside!' % po)
        else:
            self.failUnless(language, 'Po file %s has no language!' % po)

        if localesLayout:
            fileLang = getLanguageFromLocalesPath(po)
        else:
            fileLang = getLanguageFromPath(po)
            language = language.replace('_', '-')
            self.failUnless(
                fileLang == language,
                'The file %s has the wrong name or wrong language code. expected: %s, got: %s'
                % (poName, fileLang, language))

        if fileLang != 'en':
            po_cat = catalog.MessageCatalog(filename=po)

            if pot_len != len(po_cat):
                missing = [msg for msg in pot_cat if msg not in po_cat]
                additional = [msg for msg in po_cat if msg not in pot_cat]

                self.fail(
                    '%s missing and %s additional messages in %s:\nmissing: %s\nadditional: %s'
                    % (len(missing), len(additional), poName, missing,
                       additional))

        msgcatalog = [(msg, tro._catalog.get(msg)) for msg in tro._catalog
                      if msg]

        for msg, msgstr in msgcatalog:
            # every ${foo} is properly closed
            if '${' in msgstr:
                status, error = self.isMalformedMessageVariable(msgstr)
                self.failIf(status,
                            '%s in file %s:\n %s' % (error, poName, msg))
            # no html-entities in msgstr
            if '&' in msgstr and ';' in msgstr:
                status, error = self.isEntity(msgstr)
                self.failIf(status,
                            '%s in file %s:\n %s' % (error, poName, msg))
            # all ${foo}'s from the default should be present in the translation
            default = pot_cat.getDefault(msg)
            default_vars = self.getMessageVariables(msg, default)
            if not default_vars is []:
                status, error = self.isMessageVariablesMissing(
                    msgstr, default_vars=default_vars)
                self.failIf(status, '%s in file %s: %s' % (error, poName, msg))
Пример #21
0
def rebuild_pot(arguments):
    merge_ctl = None

    # Determine final argument values.
    create_domain = arguments.create_domain
    exclude = arguments.exclude and tuple(arguments.exclude.split()) or ()
    pot_fn = arguments.pot_fn
    merge_fn = arguments.merge_fn
    merge2_fn = arguments.merge2_fn
    if merge2_fn == merge_fn:
        merge2_fn = False
    path = arguments.path

    try:
        if create_domain is not None:
            orig_ctl = catalog.MessageCatalog(domain=create_domain)
        else:
            orig_ctl = catalog.MessageCatalog(filename=pot_fn)
            create_domain = orig_ctl.domain
        if merge_fn:
            merge_ctl = catalog.MessageCatalog(filename=merge_fn)
        if merge2_fn:
            merge2_ctl = catalog.MessageCatalog(filename=merge2_fn)
        ptreader = catalog.PTReader(path, create_domain, exclude=exclude)
        pyreader = catalog.PYReader(path, create_domain, exclude=exclude)
        gsreader = catalog.GSReader(path, create_domain, exclude=exclude)
        zcmlreader = catalog.ZCMLReader(path, create_domain, exclude=exclude)
    except IOError as e:
        short_usage(0, 'I/O Error: %s' % e)

    # Read the data.
    ptreader.read()
    pyreader.read()
    gsreader.read()
    zcmlreader.read()

    domain = orig_ctl.domain

    ptctl = pyctl = gsctl = zcmlctl = {}
    if domain in ptreader.catalogs:
        ptctl = ptreader.catalogs[domain]
        for key in orig_ctl.keys():
            if key in ptctl:
                # preserve comments
                ptctl[key].comments = ptctl[
                    key].comments + orig_ctl.getComments(key)

    if domain in pyreader.catalogs:
        pyctl = pyreader.catalogs[domain]
        for key in orig_ctl.keys():
            if key in pyctl:
                # preserve comments
                pyctl[key].comments = pyctl[
                    key].comments + orig_ctl.getComments(key)

    if domain in gsreader.catalogs:
        gsctl = gsreader.catalogs[domain]
        # XXX Preserve comments?

    if domain in zcmlreader.catalogs:
        zcmlctl = zcmlreader.catalogs[domain]
        # XXX Preserve comments?

    if not (ptctl or pyctl or gsctl or zcmlctl):
        short_usage(0, 'No entries for domain "%s".' % domain)

    ctl = ptctl or pyctl or gsctl or zcmlctl
    if pyctl and pyctl is not ctl:
        ctl.merge(pyctl)
    if gsctl and gsctl is not ctl:
        ctl.merge(gsctl)
    if zcmlctl and zcmlctl is not ctl:
        ctl.merge(zcmlctl)

    if merge_ctl is not None:
        # use headers from merge-catalog
        ctl.commentary_header = merge_ctl.commentary_header
        ctl.mime_header = merge_ctl.mime_header
        # merge
        ctl.add_missing(merge_ctl, mergewarn=True)
    else:
        # use headers from orig-catalog
        ctl.commentary_header = orig_ctl.commentary_header
        ctl.mime_header = orig_ctl.mime_header

    if merge2_fn:
        ctl.add_missing(merge2_ctl, mergewarn=True)

    ctl.mime_header['POT-Creation-Date'] = catalog.now()
    file = open(pot_fn, 'w')
    writer = catalog.POWriter(file, ctl)
    writer.write(msgstrToComment=True)
Пример #22
0
        opts, files = getopt.getopt(sys.argv[2:], 'p:', ('pot='))
    except getopt.GetoptError, e:
        usage(1)

    pot_fn = None
    for opt, arg in opts:
        if opt in ('-p', '--pot'):
            pot_fn = arg

    if not pot_fn:
        short_usage(1, u"No pot file specified as target with --pot.")

    files = filter_isfile(files)

    try:
        pot_ctl = catalog.MessageCatalog(filename=pot_fn)
        po_ctls = [catalog.MessageCatalog(filename=fn) for fn in files]
    except IOError, e:
        short_usage(1, 'I/O Error: %s' % e)

    for po in po_ctls:
        added_msgids, removed_msgids = po.sync(pot_ctl)

        file = open(po.filename, 'w')
        writer = catalog.POWriter(file, po)
        writer.write(msgstrToComment=False, sync=True)

        print '%s: %s added, %s removed' % (po.filename, len(added_msgids),
                                            len(removed_msgids))
        file.close()
Пример #23
0
i18ndir = os.path.normpath(PACKAGE_HOME)

tests = []
products = []
pots = {}
pot_catalogs = {}
pot_lens = {}

if HAVE_i18n:

    for potFile in getPotFiles(path=i18ndir):
        product = getProductFromPath(potFile)
        if product not in products:
            products.append(product)
        if product not in pot_catalogs:
            cat = catalog.MessageCatalog(filename=potFile)
            cat_len = len(cat)
            pots.update({product: potFile})
            pot_catalogs.update({product: cat})
            pot_lens.update({product: cat_len})

    for product in products:

        class TestOnePOT(PotTestCase.PotTestCase):
            product = product
            pot = pots[product]

        tests.append(TestOnePOT)

        for poFile in getPoFiles(path=i18ndir, product=product):
Пример #24
0
def main():
    os.chdir('..')
    os.chdir('i18n')

    poFilesPlone = getPoFiles('plone')
    if not poFilesPlone:
        print('No po-files were found for Plone.')
        sys.exit(2)

    poFilesATCT = getPoFiles('atcontenttypes')
    if not poFilesATCT:
        print('No po-files were found for ATContentTypes.')
        sys.exit(3)

    # format: 'old-domain' : ['msgid1', 'msgid2', ...]
    relocated = {'plone' :
                  ['Changes saved.', 'Please correct the indicated errors.',
                   'Rotate 180', 'help_boolean_criteria_bool',
                   'help_criteria_field_name', 'help_custom_view',
                   'help_custom_view_fields', 'help_date_range_criteria_end',
                   'help_date_range_criteria_start', 'help_exclude_from_nav',
                   'help_limit_number', 'help_news_image', 'help_shortname',
                   'help_path_criteria_value', 'help_string_criteria_value',
                   'help_portal_type_criteria_value', 'help_url',
                   'label_body_text', 'label_boolean_criteria_bool',
                   'label_contact_email', 'label_contact_name',
                   'label_contact_phone', 'label_criteria_field_name',
                   'label_custom_view', 'label_custom_view_fields',
                   'label_date_range_criteria_end', 'label_event_announcement',
                   'label_date_range_criteria_start', 'label_event_attendees',
                   'label_event_end', 'label_event_location',
                   'label_event_start', 'label_event_type',
                   'label_exclude_from_nav', 'label_file', 'label_image',
                   'label_image_caption', 'label_inherit_criteria',
                   'label_item_count', 'label_limit_number', 'label_news_image',
                   'label_path_criteria_recurse', 'label_path_criteria_value',
                   'label_related_items', 'label_short_name',
                   'label_string_criteria_value', 'label_url',
                  ]
                }

    # make sure we only try on languages for which both po files exist
    ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
    atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]

    languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
    changes = {'plone' : False, 'atcontenttypes' : False}

    for lang in languages:
        po_ctl = {}
        try:
            po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)
        try:
            po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)

        changes = {'plone' : False, 'atcontenttypes' : False}

        relocate_domain = {'plone' : 'atcontenttypes', 'atcontenttypes' : 'plone'}

        msgids = {}
        msgids['plone'] = list(po_ctl['plone'].keys())
        msgids['atcontenttypes'] = list(po_ctl['atcontenttypes'].keys())

        for old_domain in relocated:
            relocate_msgids = relocated.get(old_domain)
            for relocate_msgid in relocate_msgids:
                if relocate_msgid in msgids[old_domain]:
                    msgstr = po_ctl[old_domain].get(relocate_msgid)
                    # We copy over messages for now
                    # del po_ctl[old_domain][relocate_msgid]
                    changes[old_domain] = True

                    new_domain = relocate_domain.get(old_domain)
                    if relocate_msgid in msgids[new_domain]:
                        old_msgstr = po_ctl[new_domain].get(relocate_msgid)
                        if old_msgstr.msgstr == '' and msgstr:
                            po_ctl[new_domain][relocate_msgid] = msgstr
                            changes[new_domain] = True
                            print('copied msgstr for %s' % relocate_msgid)
                        #else:
                        #    print '%s was already there' % relocate_msgid
                    else:
                        po_ctl[new_domain][relocate_msgid] = msgstr
                        changes[new_domain] = True
                        print('copied %s to %s-%s.po' % (relocate_msgid, new_domain, lang))
                #else:
                #    print '%s was not found anymore' % relocate_msgid

        for domain in changes:
            if changes[domain]:
                file = open('%s-%s.po' % (domain, lang), 'w')
                writer = catalog.POWriter(file, po_ctl[domain])
                writer.write(sort=True)