[damned-lies] Load known plural forms and display it in UI
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Subject: [damned-lies] Load known plural forms and display it in UI
- Date: Tue, 26 May 2009 03:44:02 -0400 (EDT)
commit 1f46608580d7831eb3bfa66699194b0ff5894d2e
Author: Claude Paroz <claude 2xlibre net>
Date: Mon May 25 22:29:05 2009 +0200
Load known plural forms and display it in UI
---
languages/management/commands/load-plurals.py | 130 +++++++++++++++++++++++++
languages/models.py | 4 +
templates/teams/team_detail.html | 2 +
3 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/languages/management/__init__.py b/languages/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/languages/management/commands/__init__.py b/languages/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/languages/management/commands/load-plurals.py b/languages/management/commands/load-plurals.py
new file mode 100644
index 0000000..434c3f2
--- /dev/null
+++ b/languages/management/commands/load-plurals.py
@@ -0,0 +1,130 @@
+from django.core.management.base import BaseCommand
+from languages.models import Language
+
+# Shamelessly copied from http://translate.sourceforge.net/wiki/l10n/pluralforms (2009-05-25)
+plurals = {
+ 'af': "nplurals=2; plural=(n != 1)",
+ 'ak': "nplurals=2; plural=(n > 1)",
+ 'am': "nplurals=2; plural=(n > 1)",
+ 'ar': "nplurals=6; plural= n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;",
+ 'arn': "nplurals=2; plural=(n > 1)",
+ 'ay': "nplurals=1; plural=0",
+ 'az': "nplurals=2; plural=(n != 1)",
+ 'be': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'bg': "nplurals=2; plural=(n != 1)",
+ 'bn': "nplurals=2; plural=(n != 1)",
+ 'bo': "nplurals=1; plural=0",
+ 'bs': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'ca': "nplurals=2; plural=(n != 1)",
+ 'cs': "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n< =4) ? 1 : 2",
+ 'csb': "nplurals=3; n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2",
+ 'cy': "nplurals=4; plural= (n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3",
+ 'da': "nplurals=2; plural=(n != 1)",
+ 'de': "nplurals=2; plural=(n != 1)",
+ 'dz': "nplurals=1; plural=0",
+ 'el': "nplurals=2; plural=(n != 1)",
+ 'en': "nplurals=2; plural=(n != 1)",
+ 'eo': "nplurals=2; plural=(n != 1)",
+ 'es': "nplurals=2; plural=(n != 1)",
+ 'es_AR': "nplurals=2; plural=(n != 1)",
+ 'et': "nplurals=2; plural=(n != 1)",
+ 'eu': "nplurals=2; plural=(n != 1)",
+ 'fa': "nplurals=1; plural=0",
+ 'fi': "nplurals=2; plural=(n != 1)",
+ 'fil': "nplurals=2; plural=n > 1",
+ 'fo': "nplurals=2; plural=(n != 1)",
+ 'fr': "nplurals=2; plural=(n > 1)",
+ 'fur': "nplurals=2; plural=(n != 1)",
+ 'fy': "nplurals=2; plural=(n != 1)",
+ 'ga': "nplurals=5; plural=n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4",
+ 'gl': "nplurals=2; plural=(n != 1)",
+ 'gu': "nplurals=2; plural=(n != 1)",
+ 'gun': "nplurals=2; plural = (n > 1)",
+ 'ha': "nplurals=2; plural=(n != 1)",
+ 'he': "nplurals=2; plural=(n != 1)",
+ 'hi': "nplurals=2; plural=(n != 1)",
+ 'hy': "nplurals=1; plural=0",
+ 'hr': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'hu': "nplurals=1; plural=0",
+ 'id': "plurals=1; plural=0",
+ 'is': "nplurals=2; plural=(n % 100 != 1 && n % 100 != 21 && n % 100 != 31 && n % 100 != 41 && n % 100 != 51 && n % 100 != 61 && n % 100 != 71 && n % 100 != 81 && n % 100 != 91)",
+ 'it': "nplurals=2; plural=(n != 1)",
+ 'ja': "nplurals=1; plural=0",
+ 'jv': "nplurals=2; plural=n!=0",
+ 'ka': "nplurals=1; plural=0",
+ 'km': "nplurals=1; plural=0",
+ 'kn': "nplurals=2; plural=(n!=1)",
+ 'ko': "nplurals=1; plural=0",
+ 'ku': "nplurals=2; plural=(n!= 1)",
+ 'kw': "nplurals=4; plural= (n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3",
+ 'ky': "nplurals=1; plural=0",
+ 'lb': "nplurals=2; plural=(n != 1)",
+ 'ln': "nplurals=2; plural=n>1;",
+ 'lo': "nplurals=1; plural=0",
+ 'lt': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'lv': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)",
+ 'mg': "nplurals=2; plural=(n > 1)",
+ 'mi': "nplurals=2; plural=(n > 1)",
+ 'mk': "nplurals=2; plural= n==1 || n%10==1 ? 0 : 1",
+ 'ml': "nplurals=2; plural=(n != 1)",
+ 'mn': "nplurals=2; plural=(n != 1)",
+ 'mr': "nplurals=2; plural=(n != 1)",
+ 'ms': "nplurals=1; plural=0",
+ 'mt': "nplurals=4; plural=(n==1 ? 0 : n==0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3)",
+ 'nah': "nplurals=2; plural=(n != 1)",
+ 'nap': "nplurals=2; plural=(n != 1)",
+ 'nb': "nplurals=2; plural=(n != 1)",
+ 'ne': "nplurals=2; plural=(n != 1)",
+ 'nl': "nplurals=2; plural=(n != 1)",
+ 'nn': "nplurals=2; plural=(n != 1)",
+ 'no': "nplurals=2; plural=(n != 1)",
+ 'nso': "nplurals=2; plural=(n > 1)",
+ 'or': "nplurals=2; plural=(n != 1)",
+ 'ps': "nplurals=2; plural=(n != 1)",
+ 'pa': "nplurals=2; plural=(n != 1)",
+ 'pap': "nplurals=2; plural=(n != 1)",
+ 'pl': "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'pms': "nplurals=2; plural=(n != 1)",
+ 'pt': "nplurals=2; plural=(n != 1)",
+ 'pt_BR': "nplurals=2; plural=(n > 1)",
+ 'ro': "nplurals=3; plural=(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);",
+ 'ru': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'sco': "nplurals=2; plural=(n != 1)",
+ 'sk': "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2",
+ 'sl': "nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3)",
+ 'so': "nplurals=2; plural=n != 1",
+ 'sq': "nplurals=2; plural=(n != 1)",
+ 'sr': "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",
+ 'su': "nplurals=1; plural=0",
+ 'sv': "nplurals=2; plural=(n != 1)",
+ 'ta': "nplurals=2; plural=(n != 1)",
+ 'te': "nplurals=2; plural=(n != 1)",
+ 'tg': "nplurals=2; plural=(n != 1)",
+ 'ti': "nplurals=2; plural=n > 1",
+ 'th': "nplurals=1; plural=0",
+ 'tk': "nplurals=2; plural=(n != 1)",
+ 'tr': "nplurals=1; plural=0",
+ 'uk': "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 || n%100>=20) ? 1 : 2)",
+ 'ur': "nplurals=2; plural=(n != 1)",
+ 'uz': "nplurals=1; plural=0;",
+ 'vi': "nplurals=1; plural=0",
+ 'wa': "nplurals=2; plural=(n > 1)",
+ 'zh': "nplurals=1; plural=0",
+ # 'zh means all districts and all variants of Chinese, such as zh_CN, zh_HK, zh_TW and so on.",
+ # Note: In rare cases where plural form introduces difference in personal pronoun (such as her vs. they, we vs. I), the plural form is different:",
+ # 'zh Chinese nplurals=2; plural=(n > 1)",
+}
+
+class Command(BaseCommand):
+
+ def handle(self, *args, **options):
+ """ Load known plural forms for existing languages """
+
+ for locale in plurals:
+ try:
+ lang = Language.objects.get(locale=locale)
+ except Language.DoesNotExist:
+ continue
+ lang.plurals = plurals[locale]
+ lang.save()
+ print "Plural form loaded"
diff --git a/languages/models.py b/languages/models.py
index 9f80276..3af9092 100644
--- a/languages/models.py
+++ b/languages/models.py
@@ -21,6 +21,10 @@ class Language(models.Model):
else:
return self.locale
+ def get_plurals(self):
+ # Translators: this concerns an unknown plural form
+ return self.plurals or _("Unknown")
+
def bugs_url_enter(self):
return "http://bugzilla.gnome.org/enter_bug.cgi?product=l10n&component=%s%%20[%s]" % (self.name, self.locale)
diff --git a/templates/teams/team_detail.html b/templates/teams/team_detail.html
index 119aefc..317253e 100644
--- a/templates/teams/team_detail.html
+++ b/templates/teams/team_detail.html
@@ -63,6 +63,8 @@
<tr><td></td><td><a href="{% url language_all lang.locale,"ui" %}">{% trans "All modules" %}</a></td>
<td></td><td><a href="{% url language_all lang.locale,"doc" %}">{% trans "All modules" %}</a></td><td></td></tr>
</table>
+<p><strong>{% trans "Plural form:" %}</strong> {{ lang.get_plurals }}</p>
+
{% endfor %}
{% if not team.fake %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]