Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Avoid using Babel for plural tags #3762

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements/optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ vobject==0.9.5 # iCal (ical2po)
# aeidon not available through pip/PyPI,
# so recording this dependency here is pointless except as a comment

Babel==2.5.0 # Android plurals
l20n==4.0.0a1 # l20n (l20n2po)
PyYAML==3.12 # yaml
210 changes: 210 additions & 0 deletions translate/lang/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,216 @@
'other',
]

"""List of plural tags generated from CLDR 32.0.1 using
https://github.com/WeblateOrg/language-data
"""
plural_tags = {
'af': ['one', 'other'],
'ak': ['one', 'other'],
'am': ['one', 'other'],
'ar': ['zero', 'one', 'two', 'few', 'many', 'other'],
'ars': ['zero', 'one', 'two', 'few', 'many', 'other'],
'as': ['one', 'other'],
'asa': ['one', 'other'],
'ast': ['one', 'other'],
'az': ['one', 'other'],
'be': ['one', 'few', 'many'],
'bem': ['one', 'other'],
'bez': ['one', 'other'],
'bg': ['one', 'other'],
'bh': ['one', 'other'],
'bm': ['other'],
'bn': ['one', 'other'],
'bo': ['other'],
'br': ['one', 'two', 'few', 'many', 'other'],
'brx': ['one', 'other'],
'bs': ['one', 'few', 'other'],
'ca': ['one', 'other'],
'ce': ['one', 'other'],
'cgg': ['one', 'other'],
'chr': ['one', 'other'],
'ckb': ['one', 'other'],
'cs': ['one', 'few', 'other'],
'cy': ['zero', 'one', 'two', 'few', 'many', 'other'],
'da': ['one', 'other'],
'de': ['one', 'other'],
'dsb': ['one', 'two', 'few', 'other'],
'dv': ['one', 'other'],
'dz': ['other'],
'ee': ['one', 'other'],
'el': ['one', 'other'],
'en': ['one', 'other'],
'eo': ['one', 'other'],
'es': ['one', 'other'],
'et': ['one', 'other'],
'eu': ['one', 'other'],
'fa': ['one', 'other'],
'ff': ['one', 'other'],
'fi': ['one', 'other'],
'fil': ['one', 'other'],
'fo': ['one', 'other'],
'fr': ['one', 'other'],
'fur': ['one', 'other'],
'fy': ['one', 'other'],
'ga': ['one', 'two', 'few', 'many', 'other'],
'gd': ['one', 'two', 'few', 'other'],
'gl': ['one', 'other'],
'gsw': ['one', 'other'],
'gu': ['one', 'other'],
'guw': ['one', 'other'],
'gv': ['one', 'two', 'few', 'other'],
'ha': ['one', 'other'],
'haw': ['one', 'other'],
'he': ['one', 'two', 'many', 'other'],
'hi': ['one', 'other'],
'hr': ['one', 'few', 'other'],
'hsb': ['one', 'two', 'few', 'other'],
'hu': ['one', 'other'],
'hy': ['one', 'other'],
'id': ['other'],
'ig': ['other'],
'ii': ['other'],
'in': ['other'],
'io': ['one', 'other'],
'is': ['one', 'other'],
'it': ['one', 'other'],
'iu': ['one', 'two', 'other'],
'iw': ['one', 'two', 'many', 'other'],
'ja': ['other'],
'jbo': ['other'],
'jgo': ['one', 'other'],
'ji': ['one', 'other'],
'jmc': ['one', 'other'],
'jv': ['other'],
'jw': ['other'],
'ka': ['one', 'other'],
'kab': ['one', 'other'],
'kaj': ['one', 'other'],
'kcg': ['one', 'other'],
'kde': ['other'],
'kea': ['other'],
'kk': ['one', 'other'],
'kkj': ['one', 'other'],
'kl': ['one', 'other'],
'km': ['other'],
'kn': ['one', 'other'],
'ko': ['other'],
'ks': ['one', 'other'],
'ksb': ['one', 'other'],
'ksh': ['zero', 'one', 'other'],
'ku': ['one', 'other'],
'kw': ['one', 'two', 'other'],
'ky': ['one', 'other'],
'lag': ['zero', 'one', 'other'],
'lb': ['one', 'other'],
'lg': ['one', 'other'],
'lkt': ['other'],
'ln': ['one', 'other'],
'lo': ['other'],
'lt': ['one', 'few', 'other'],
'lv': ['zero', 'one', 'other'],
'mas': ['one', 'other'],
'mg': ['one', 'other'],
'mgo': ['one', 'other'],
'mk': ['one', 'other'],
'ml': ['one', 'other'],
'mn': ['one', 'other'],
'mo': ['one', 'few', 'other'],
'mr': ['one', 'other'],
'ms': ['other'],
'mt': ['one', 'few', 'many', 'other'],
'my': ['other'],
'nah': ['one', 'other'],
'naq': ['one', 'two', 'other'],
'nb': ['one', 'other'],
'nd': ['one', 'other'],
'ne': ['one', 'other'],
'nl': ['one', 'other'],
'nn': ['one', 'other'],
'nnh': ['one', 'other'],
'no': ['one', 'other'],
'nqo': ['other'],
'nr': ['one', 'other'],
'nso': ['one', 'other'],
'ny': ['one', 'other'],
'nyn': ['one', 'other'],
'om': ['one', 'other'],
'or': ['one', 'other'],
'os': ['one', 'other'],
'pa': ['one', 'other'],
'pap': ['one', 'other'],
'pl': ['one', 'few', 'many'],
'prg': ['zero', 'one', 'other'],
'ps': ['one', 'other'],
'pt': ['one', 'other'],
'pt_PT': ['one', 'other'],
'rm': ['one', 'other'],
'ro': ['one', 'few', 'other'],
'rof': ['one', 'other'],
'root': ['other'],
'ru': ['one', 'few', 'many'],
'rwk': ['one', 'other'],
'sah': ['other'],
'saq': ['one', 'other'],
'sd': ['one', 'other'],
'sdh': ['one', 'other'],
'se': ['one', 'two', 'other'],
'seh': ['one', 'other'],
'ses': ['other'],
'sg': ['other'],
'sh': ['one', 'few', 'other'],
'shi': ['one', 'few', 'other'],
'si': ['one', 'other'],
'sk': ['one', 'few', 'other'],
'sl': ['one', 'two', 'few', 'other'],
'sma': ['one', 'two', 'other'],
'smi': ['one', 'two', 'other'],
'smj': ['one', 'two', 'other'],
'smn': ['one', 'two', 'other'],
'sms': ['one', 'two', 'other'],
'sn': ['one', 'other'],
'so': ['one', 'other'],
'sq': ['one', 'other'],
'sr': ['one', 'few', 'other'],
'ss': ['one', 'other'],
'ssy': ['one', 'other'],
'st': ['one', 'other'],
'sv': ['one', 'other'],
'sw': ['one', 'other'],
'syr': ['one', 'other'],
'ta': ['one', 'other'],
'te': ['one', 'other'],
'teo': ['one', 'other'],
'th': ['other'],
'ti': ['one', 'other'],
'tig': ['one', 'other'],
'tk': ['one', 'other'],
'tl': ['one', 'other'],
'tn': ['one', 'other'],
'to': ['other'],
'tr': ['one', 'other'],
'ts': ['one', 'other'],
'tzm': ['one', 'other'],
'ug': ['one', 'other'],
'uk': ['one', 'few', 'many'],
'ur': ['one', 'other'],
'uz': ['one', 'other'],
've': ['one', 'other'],
'vi': ['other'],
'vo': ['one', 'other'],
'vun': ['one', 'other'],
'wa': ['one', 'other'],
'wae': ['one', 'other'],
'wo': ['other'],
'xh': ['one', 'other'],
'xog': ['one', 'other'],
'yi': ['one', 'other'],
'yo': ['other'],
'yue': ['other'],
'zh': ['other'],
'zu': ['one', 'other']
}


def simplercode(code):
"""This attempts to simplify the given language code by ignoring country
Expand Down
11 changes: 4 additions & 7 deletions translate/storage/aresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
from translate.storage import base, lisa
from translate.misc.multistring import multistring

from babel.core import Locale, UnknownLocaleError

EOF = None
WHITESPACE = ' \n\t' # Whitespace that we collapse.
MULTIWHITESPACE = re.compile('[ \n\t]{2}(?!\\\\n)')
Expand Down Expand Up @@ -302,12 +300,11 @@ def settarget(self, target):
self.xmlelement.tail = '\n'
self.setid(old_id)

locale = self.gettargetlanguage().replace('_', '-').split('-')[0]
try:
lang_tags = set(Locale(self.gettargetlanguage()).plural_form.tags)
except UnknownLocaleError:
lang_tags = set(Locale('en').plural_form.tags)
# Ensure that the implicit default "other" rule is present (usually omitted by Babel)
lang_tags.add('other')
lang_tags = data.plural_tags[locale]
except KeyError:
lang_tags = data.plural_tags['en']

# Get plural tags in the right order.
plural_tags = [tag for tag in ['zero', 'one', 'two', 'few', 'many', 'other'] if tag in lang_tags]
Expand Down