Commit af742ac9 authored by Michal Čihař's avatar Michal Čihař

Move plural definitions to data

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent a873dc45
......@@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.utils.translation import pgettext_lazy
# Extra languages not included in ttkit
EXTRALANGS = (
......@@ -322,3 +324,91 @@ ONE_FEW_MANY_OTHER_PLURALS = (
ONE_OTHER_ZERO_PLURALS = (
'n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2'
)
# Plural types definition
PLURAL_NONE = 0
PLURAL_ONE_OTHER = 1
PLURAL_ONE_FEW_OTHER = 2
PLURAL_ARABIC = 3
PLURAL_ONE_TWO_OTHER = 4
PLURAL_ONE_TWO_THREE_OTHER = 5
PLURAL_ONE_TWO_FEW_OTHER = 6
PLURAL_ONE_OTHER_ZERO = 7
PLURAL_ONE_FEW_MANY_OTHER = 8
PLURAL_TWO_OTHER = 9
PLURAL_ONE_TWO_FEW_MANY_OTHER = 10
PLURAL_UNKNOWN = 666
# Plural equation - type mappings
PLURAL_MAPPINGS = (
(ONE_OTHER_PLURALS, PLURAL_ONE_OTHER),
(ONE_FEW_OTHER_PLURALS, PLURAL_ONE_FEW_OTHER),
(ONE_TWO_OTHER_PLURALS, PLURAL_ONE_TWO_OTHER),
(ONE_TWO_FEW_OTHER_PLURALS, PLURAL_ONE_TWO_FEW_OTHER),
(ONE_TWO_THREE_OTHER_PLURALS, PLURAL_ONE_TWO_THREE_OTHER),
(ONE_OTHER_ZERO_PLURALS, PLURAL_ONE_OTHER_ZERO),
(ONE_FEW_MANY_OTHER_PLURALS, PLURAL_ONE_FEW_MANY_OTHER),
(TWO_OTHER_PLURALS, PLURAL_TWO_OTHER),
(ONE_TWO_FEW_MANY_OTHER_PLURALS, PLURAL_ONE_TWO_FEW_MANY_OTHER),
)
# Plural names mapping
PLURAL_NAMES = {
PLURAL_NONE: ('',),
PLURAL_ONE_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_FEW_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ARABIC: (
pgettext_lazy('Plural form description', 'Zero'),
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_THREE_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Three'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_FEW_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_OTHER_ZERO: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Other'),
pgettext_lazy('Plural form description', 'Zero'),
),
PLURAL_ONE_FEW_MANY_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_FEW_MANY_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_TWO_OTHER: (
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Other'),
),
}
......@@ -19,7 +19,7 @@
#
from django.db import models
from django.utils.translation import ugettext as _, pgettext_lazy
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from translate.lang.data import languages
from weblate.lang import data
......@@ -31,33 +31,6 @@ from django.dispatch import receiver
from weblate.appsettings import SIMPLIFY_LANGUAGES
import weblate
# Plural types definition
PLURAL_NONE = 0
PLURAL_ONE_OTHER = 1
PLURAL_ONE_FEW_OTHER = 2
PLURAL_ARABIC = 3
PLURAL_ONE_TWO_OTHER = 4
PLURAL_ONE_TWO_THREE_OTHER = 5
PLURAL_ONE_TWO_FEW_OTHER = 6
PLURAL_ONE_OTHER_ZERO = 7
PLURAL_ONE_FEW_MANY_OTHER = 8
PLURAL_TWO_OTHER = 9
PLURAL_ONE_TWO_FEW_MANY_OTHER = 10
PLURAL_UNKNOWN = 666
# Plural equation - type mappings
PLURAL_MAPPINGS = (
(data.ONE_OTHER_PLURALS, PLURAL_ONE_OTHER),
(data.ONE_FEW_OTHER_PLURALS, PLURAL_ONE_FEW_OTHER),
(data.ONE_TWO_OTHER_PLURALS, PLURAL_ONE_TWO_OTHER),
(data.ONE_TWO_FEW_OTHER_PLURALS, PLURAL_ONE_TWO_FEW_OTHER),
(data.ONE_TWO_THREE_OTHER_PLURALS, PLURAL_ONE_TWO_THREE_OTHER),
(data.ONE_OTHER_ZERO_PLURALS, PLURAL_ONE_OTHER_ZERO),
(data.ONE_FEW_MANY_OTHER_PLURALS, PLURAL_ONE_FEW_MANY_OTHER),
(data.TWO_OTHER_PLURALS, PLURAL_TWO_OTHER),
(data.ONE_TWO_FEW_MANY_OTHER_PLURALS, PLURAL_ONE_TWO_FEW_MANY_OTHER),
)
def get_plural_type(code, pluralequation):
'''
......@@ -74,23 +47,23 @@ def get_plural_type(code, pluralequation):
# No plural
if pluralequation == '0':
return PLURAL_NONE
return data.PLURAL_NONE
# Standard plural equations
for mapping in PLURAL_MAPPINGS:
for mapping in data.PLURAL_MAPPINGS:
if pluralequation in mapping[0]:
return mapping[1]
# Arabic special case
if base_code in ('ar',):
return PLURAL_ARABIC
return data.PLURAL_ARABIC
# Log error in case of uknown mapping
weblate.logger.error(
'Can not guess type of plural for %s: %s', code, pluralequation
)
return PLURAL_UNKNOWN
return data.PLURAL_UNKNOWN
class LanguageManager(models.Manager):
......@@ -283,82 +256,20 @@ def setup_lang(sender, app, **kwargs):
Language.objects.setup(False)
# Plural names mapping
PLURAL_NAMES = {
PLURAL_NONE: ('',),
PLURAL_ONE_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_FEW_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ARABIC: (
pgettext_lazy('Plural form description', 'Zero'),
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_THREE_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Three'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_FEW_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_OTHER_ZERO: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Other'),
pgettext_lazy('Plural form description', 'Zero'),
),
PLURAL_ONE_FEW_MANY_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_ONE_TWO_FEW_MANY_OTHER: (
pgettext_lazy('Plural form description', 'One'),
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Few'),
pgettext_lazy('Plural form description', 'Many'),
pgettext_lazy('Plural form description', 'Other'),
),
PLURAL_TWO_OTHER: (
pgettext_lazy('Plural form description', 'Two'),
pgettext_lazy('Plural form description', 'Other'),
),
}
class Language(models.Model, PercentMixin):
PLURAL_CHOICES = (
(PLURAL_NONE, 'None'),
(PLURAL_ONE_OTHER, 'One/other (classic plural)'),
(PLURAL_ONE_FEW_OTHER, 'One/few/other (Slavic languages)'),
(PLURAL_ARABIC, 'Arabic languages'),
(PLURAL_ONE_TWO_OTHER, 'One/two/other'),
(PLURAL_ONE_TWO_FEW_OTHER, 'One/two/few/other'),
(PLURAL_ONE_TWO_THREE_OTHER, 'One/two/three/other'),
(PLURAL_ONE_OTHER_ZERO, 'One/other/zero'),
(PLURAL_ONE_FEW_MANY_OTHER, 'One/few/many/other'),
(PLURAL_TWO_OTHER, 'Two/other'),
(PLURAL_ONE_TWO_FEW_MANY_OTHER, 'One/two/few/many/other'),
(PLURAL_UNKNOWN, 'Unknown'),
(data.PLURAL_NONE, 'None'),
(data.PLURAL_ONE_OTHER, 'One/other (classic plural)'),
(data.PLURAL_ONE_FEW_OTHER, 'One/few/other (Slavic languages)'),
(data.PLURAL_ARABIC, 'Arabic languages'),
(data.PLURAL_ONE_TWO_OTHER, 'One/two/other'),
(data.PLURAL_ONE_TWO_FEW_OTHER, 'One/two/few/other'),
(data.PLURAL_ONE_TWO_THREE_OTHER, 'One/two/three/other'),
(data.PLURAL_ONE_OTHER_ZERO, 'One/other/zero'),
(data.PLURAL_ONE_FEW_MANY_OTHER, 'One/few/many/other'),
(data.PLURAL_TWO_OTHER, 'Two/other'),
(data.PLURAL_ONE_TWO_FEW_MANY_OTHER, 'One/two/few/many/other'),
(data.PLURAL_UNKNOWN, 'Unknown'),
)
code = models.SlugField(unique=True)
name = models.CharField(max_length=100)
......@@ -371,7 +282,7 @@ class Language(models.Model, PercentMixin):
)
plural_type = models.IntegerField(
choices=PLURAL_CHOICES,
default=PLURAL_ONE_OTHER
default=data.PLURAL_ONE_OTHER
)
objects = LanguageManager()
......@@ -404,7 +315,7 @@ class Language(models.Model, PercentMixin):
Returns label for plural form.
'''
try:
return unicode(PLURAL_NAMES[self.plural_type][idx])
return unicode(data.PLURAL_NAMES[self.plural_type][idx])
except:
if idx == 0:
return _('Singular')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment