[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-i18n-doc
Subject:    Re: Changing the number of plural forms
From:       Chusslove Illich <caslav.ilic () gmx ! net>
Date:       2010-06-11 20:24:12
Message-ID: 201006112224.14909.caslav.ilic () gmx ! net
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


> [: Yuri Chornoivan :]
> Is there any way to change the plural formula to [...]

There is now, attached script (Pology needs to be added to PYTHONPATH, as
mentioned in its setup instructions). To convert to plural forms like for
Serbian (where the fourth form is for exactly n == 1), you would execute:

  $ modplforms.py $KDETRANSLATIONS/uk/messages \
                  'nplurals=4; plural=n==1 ? 3 : n%10==1 && n%100!=11 ? 0 : n%10>=2 \
&& n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;' \  '0>0,1>1,2>2,0>3'

This will convert all PO files in the given path. The third argument is the
mapping of how to copy old forms to new forms: here it says to keep forms 0,
1, 2 where they were, and to copy form 0 to form 3. It will output to
terminal the paths of modified files.

-- 
Chusslove Illich (Часлав Илић)
Serbian KDE translation team


["modplforms.py" (text/x-python)]

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

from pology.file.catalog import Catalog
from pology.misc.fsops import collect_catalogs
from pology.misc.report import report, error

cmd = os.path.basename(sys.argv[0])
args = sys.argv[1:]
if len(args) != 3:
    error("Usage: %(cmd)s PATH PLURALFORMS COPYMAP" % dict(cmd=cmd))
path = args.pop(0)
newplhead = args.pop(0)
copyspec = args.pop(0)

# Process form mapping.
srcforms = set()
dstforms = set()
copymap = {}
for spec1 in copyspec.split(","):
    try:
        sform, dform = map(int, spec1.split(">"))
    except:
        error("Malformed copy map '%(map)s'." % dict(map=copyspec))
    copymap[sform] = dform
    srcforms.add(sform)
    dstforms.add(dform)
if max(srcforms) + 1 != len(srcforms):
    error("Gaps in source forms.")
if max(dstforms) + 1 != len(dstforms):
    error("Gaps in destination forms.")
copyord = [0] * len(dstforms)
for sform, dform in copymap.items():
    copyord[dform] = sform

# Convert catalogs.
for popath in collect_catalogs(path):
    cat = Catalog(popath)
    cat.header.replace_field_value(u"Plural-Forms", unicode(newplhead))
    for msg in cat:
        if msg.msgid_plural is not None:
            msg.msgstr[:] = [msg.msgstr[x] for x in copyord]
    if cat.sync():
        report(cat.filename)

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic