From 156c2c294e9ffe3c62fc495c3fab2fd671a4b658 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Thu, 30 Aug 2012 23:55:14 -0500 Subject: [PATCH] fixed plural rules with pkgutil --- VERSION | 2 +- applications/admin/languages/default.py | 3 +- applications/admin/views/default/design.html | 8 +--- gluon/contrib/rules/__init__.py | 1 - gluon/contrib/rules/plural_rules-af.py | 17 ------- gluon/contrib/rules/plural_rules-bg.py | 17 ------- gluon/contrib/rules/plural_rules-cs.py | 19 -------- gluon/contrib/rules/plural_rules-de.py | 17 ------- gluon/contrib/rules/plural_rules-en.py | 20 -------- gluon/contrib/rules/plural_rules-es.py | 17 ------- gluon/contrib/rules/plural_rules-fr.py | 17 ------- gluon/contrib/rules/plural_rules-he.py | 17 ------- gluon/contrib/rules/plural_rules-hi.py | 17 ------- gluon/contrib/rules/plural_rules-hu.py | 17 ------- gluon/contrib/rules/plural_rules-it.py | 17 ------- gluon/contrib/rules/plural_rules-ja.py | 14 ------ gluon/contrib/rules/plural_rules-lt.py | 19 -------- gluon/contrib/rules/plural_rules-pl.py | 19 -------- gluon/contrib/rules/plural_rules-pt.py | 17 ------- gluon/contrib/rules/plural_rules-ro.py | 17 ------- gluon/contrib/rules/plural_rules-ru.py | 20 -------- gluon/contrib/rules/plural_rules-sk.py | 20 -------- gluon/contrib/rules/plural_rules-sl.py | 20 -------- gluon/contrib/rules/plural_rules-tr.py | 14 ------ gluon/contrib/rules/plural_rules-uk.py | 21 --------- gluon/contrib/rules/plural_rules-zh.py | 14 ------ gluon/languages.py | 49 +++++--------------- 27 files changed, 17 insertions(+), 433 deletions(-) delete mode 100644 gluon/contrib/rules/__init__.py delete mode 100644 gluon/contrib/rules/plural_rules-af.py delete mode 100644 gluon/contrib/rules/plural_rules-bg.py delete mode 100644 gluon/contrib/rules/plural_rules-cs.py delete mode 100644 gluon/contrib/rules/plural_rules-de.py delete mode 100644 gluon/contrib/rules/plural_rules-en.py delete mode 100644 gluon/contrib/rules/plural_rules-es.py delete mode 100644 gluon/contrib/rules/plural_rules-fr.py delete mode 100644 gluon/contrib/rules/plural_rules-he.py delete mode 100644 gluon/contrib/rules/plural_rules-hi.py delete mode 100644 gluon/contrib/rules/plural_rules-hu.py delete mode 100644 gluon/contrib/rules/plural_rules-it.py delete mode 100644 gluon/contrib/rules/plural_rules-ja.py delete mode 100644 gluon/contrib/rules/plural_rules-lt.py delete mode 100644 gluon/contrib/rules/plural_rules-pl.py delete mode 100644 gluon/contrib/rules/plural_rules-pt.py delete mode 100644 gluon/contrib/rules/plural_rules-ro.py delete mode 100644 gluon/contrib/rules/plural_rules-ru.py delete mode 100644 gluon/contrib/rules/plural_rules-sk.py delete mode 100644 gluon/contrib/rules/plural_rules-sl.py delete mode 100644 gluon/contrib/rules/plural_rules-tr.py delete mode 100644 gluon/contrib/rules/plural_rules-uk.py delete mode 100644 gluon/contrib/rules/plural_rules-zh.py diff --git a/VERSION b/VERSION index 24b002fd..eb7c1797 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.3 (2012-08-30 23:07:46) stable +Version 2.0.3 (2012-08-30 23:55:09) stable diff --git a/applications/admin/languages/default.py b/applications/admin/languages/default.py index 5e7b0a7d..beeff162 100644 --- a/applications/admin/languages/default.py +++ b/applications/admin/languages/default.py @@ -53,6 +53,7 @@ 'Exception instance attributes': 'Exception instance attributes', 'exposes': 'exposes', 'extends': 'extends', +'file does not exist': 'file does not exist', 'filter': 'filter', 'Frames': 'Frames', 'Get from URL:': 'Get from URL:', @@ -72,8 +73,8 @@ 'Logout': 'Logout', 'Models': 'Models', 'models': 'models', -'modules': 'modules', 'Modules': 'Modules', +'modules': 'modules', 'New application wizard': 'New application wizard', 'New simple application': 'New simple application', 'Overwrite installed app': 'Overwrite installed app', diff --git a/applications/admin/views/default/design.html b/applications/admin/views/default/design.html index 1f1b0887..1934fc1d 100644 --- a/applications/admin/views/default/design.html +++ b/applications/admin/views/default/design.html @@ -223,16 +223,12 @@ for c in controllers: controller_functions+=[c[:-3]+'/%s.html'%x for x in functi {{=editpluralsfile('languages',pfile,dict(nplurals=p[0]))}} - {{=peekfile('languages',pfile,dict(id=id))}}, + {{=peekfile('languages',pfile,dict(id=id))}} {{else:}} - {{=T("are not used yet")}}, + {{=T("are not used yet")}} {{pass}} {{pass}} - {{=T("rules:")}} - - {{=peekfile('gluon/contrib/rules', p[2], dict(app=app, id=id), p[3] if p[3]!='ok' else None)}} - {{pass}} ) diff --git a/gluon/contrib/rules/__init__.py b/gluon/contrib/rules/__init__.py deleted file mode 100644 index 8b137891..00000000 --- a/gluon/contrib/rules/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gluon/contrib/rules/plural_rules-af.py b/gluon/contrib/rules/plural_rules-af.py deleted file mode 100644 index 9c0c8c61..00000000 --- a/gluon/contrib/rules/plural_rules-af.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for af (Afrikaans (South Africa)) - -nplurals=2 # Afrikaans language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-bg.py b/gluon/contrib/rules/plural_rules-bg.py deleted file mode 100644 index 985c5797..00000000 --- a/gluon/contrib/rules/plural_rules-bg.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for bg (Bulgarian) - -nplurals=2 # Bulgarian language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-cs.py b/gluon/contrib/rules/plural_rules-cs.py deleted file mode 100644 index 47e5e1d5..00000000 --- a/gluon/contrib/rules/plural_rules-cs.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for cs (Czech) - -nplurals=3 # Czech language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: ( 0 if n==1 else - 1 if 2<=n<=4 else - 2 ) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-de.py b/gluon/contrib/rules/plural_rules-de.py deleted file mode 100644 index 5393cd92..00000000 --- a/gluon/contrib/rules/plural_rules-de.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for de (Deutsch) - -nplurals=2 # German language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-en.py b/gluon/contrib/rules/plural_rules-en.py deleted file mode 100644 index 73a52400..00000000 --- a/gluon/contrib/rules/plural_rules-en.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for en (English) - -nplurals=2 # English language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -construct_plural_form = lambda word, plural_id: (word + - ('es' if word[-1:] in ('s','x','o') or - word[-2:] in ('sh','ch') - else 's')) - diff --git a/gluon/contrib/rules/plural_rules-es.py b/gluon/contrib/rules/plural_rules-es.py deleted file mode 100644 index 7f6a510a..00000000 --- a/gluon/contrib/rules/plural_rules-es.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for es (Spanish) - -nplurals=2 # Spanish language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-fr.py b/gluon/contrib/rules/plural_rules-fr.py deleted file mode 100644 index 4237c0e3..00000000 --- a/gluon/contrib/rules/plural_rules-fr.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for fr (French)) - -nplurals=2 # French language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-he.py b/gluon/contrib/rules/plural_rules-he.py deleted file mode 100644 index c1e316da..00000000 --- a/gluon/contrib/rules/plural_rules-he.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for he (Hebrew) - -nplurals=2 # Hebrew language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-hi.py b/gluon/contrib/rules/plural_rules-hi.py deleted file mode 100644 index d636c1e0..00000000 --- a/gluon/contrib/rules/plural_rules-hi.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for he (Hindi) - -nplurals=2 # Hindi has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-hu.py b/gluon/contrib/rules/plural_rules-hu.py deleted file mode 100644 index ea960e29..00000000 --- a/gluon/contrib/rules/plural_rules-hu.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for hu (Hungarian) - -nplurals=2 # Hungarian language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-it.py b/gluon/contrib/rules/plural_rules-it.py deleted file mode 100644 index ba3c7b5d..00000000 --- a/gluon/contrib/rules/plural_rules-it.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for it (Italian) - -nplurals=2 # Italian language has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-ja.py b/gluon/contrib/rules/plural_rules-ja.py deleted file mode 100644 index 168bccb8..00000000 --- a/gluon/contrib/rules/plural_rules-ja.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for ja (Japanese) - -nplurals=1 # Japanese language has ONE form! - -# Always returns 0: -get_plural_id = lambda n: 0 - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: word - diff --git a/gluon/contrib/rules/plural_rules-lt.py b/gluon/contrib/rules/plural_rules-lt.py deleted file mode 100644 index c7f4451f..00000000 --- a/gluon/contrib/rules/plural_rules-lt.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for lt (Lithuanian) - -nplurals=3 # Lithuanian language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n % 10 == 1 and n % 100 != 11 else - 1 if n % 10 >= 2 and (n % 100 < 10 or n % 100 >= 20) else - 2) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-pl.py b/gluon/contrib/rules/plural_rules-pl.py deleted file mode 100644 index a61a6a53..00000000 --- a/gluon/contrib/rules/plural_rules-pl.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for pl (Polish) - -nplurals=3 # Polish language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n==1 else - 1 if 2<=n<=4 else - 2) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-pt.py b/gluon/contrib/rules/plural_rules-pt.py deleted file mode 100644 index 57718af3..00000000 --- a/gluon/contrib/rules/plural_rules-pt.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for pt (Portuguese) - -nplurals=2 # Portuguese has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-ro.py b/gluon/contrib/rules/plural_rules-ro.py deleted file mode 100644 index 9158a3d4..00000000 --- a/gluon/contrib/rules/plural_rules-ro.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for ro (Romanian) - -nplurals=2 # Romanian has 2 forms: - # 1 singular and 1 plural - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: int(n != 1) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-ru.py b/gluon/contrib/rules/plural_rules-ru.py deleted file mode 100644 index 23c4f563..00000000 --- a/gluon/contrib/rules/plural_rules-ru.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for ru (Russian) - -nplurals=3 # Russian language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n % 10 == 1 and n % 100 != 11 else - 1 if n % 10 >= 2 and n % 10 <= 4 and - (n % 100 < 10 or n % 100 >= 20) else - 2) - -# construct_plural_form() is not used now because of complex -# rules of Russian language. Default version of -# this function is used to simple insert new words into -# plural_dict dictionary) -# construct_plural_form = lambda word, plural_id: word diff --git a/gluon/contrib/rules/plural_rules-sk.py b/gluon/contrib/rules/plural_rules-sk.py deleted file mode 100644 index df8d5232..00000000 --- a/gluon/contrib/rules/plural_rules-sk.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for sk (Slovak (Slovakia)) - -nplurals=3 # Slovak language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n % 10 == 1 and n % 100 != 11 else - 1 if n % 10 >= 2 and n % 10 <= 4 and - (n % 100 < 10 or n % 100 >= 20) else - 2) - -# construct_plural_form() is not used now because of complex -# rules of Slovak language. Default version of this function -# is used to simple insert new words into plural_dict dictionary) -# construct_plural_form = lambda word, plural_id: word - diff --git a/gluon/contrib/rules/plural_rules-sl.py b/gluon/contrib/rules/plural_rules-sl.py deleted file mode 100644 index 465072d2..00000000 --- a/gluon/contrib/rules/plural_rules-sl.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for sl (Slovenian) - -nplurals=4 # Slovenian language has 4 forms: - # 1 singular and 3 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n % 100 == 1 else - 1 if n % 100 == 2 else - 2 if n % 100 in (3,4) else - 3) - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: (word + 'suffix') - diff --git a/gluon/contrib/rules/plural_rules-tr.py b/gluon/contrib/rules/plural_rules-tr.py deleted file mode 100644 index 8d61e14e..00000000 --- a/gluon/contrib/rules/plural_rules-tr.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for tr (Turkish) - -nplurals=1 # Turkish language has ONE form! - -# Always returns 0: -get_plural_id = lambda n: 0 - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: word - diff --git a/gluon/contrib/rules/plural_rules-uk.py b/gluon/contrib/rules/plural_rules-uk.py deleted file mode 100644 index bbd4b4e4..00000000 --- a/gluon/contrib/rules/plural_rules-uk.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for uk (Ukrainian) - -nplurals=3 # Ukrainian language has 3 forms: - # 1 singular and 2 plurals - -# Determine plural_id for number *n* as sequence of positive -# integers: 0,1,... -# NOTE! For singular form ALWAYS return plural_id = 0 -get_plural_id = lambda n: (0 if n % 10 == 1 and n % 100 != 11 else - 1 if n % 10 >= 2 and n % 10 <= 4 and - (n % 100 < 10 or n % 100 >= 20) else - 2) - -# construct_plural_form() is not used now because of complex -# rules of Ukrainian language. Default version of -# this function is used to simple insert new words into -# plural_dict dictionary) -# construct_plural_form = lambda word, plural_id: word - diff --git a/gluon/contrib/rules/plural_rules-zh.py b/gluon/contrib/rules/plural_rules-zh.py deleted file mode 100644 index 0eed6c7c..00000000 --- a/gluon/contrib/rules/plural_rules-zh.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- -# Plural-Forms for zh (Chinese) - -nplurals=1 # Chinese language has ONE form! - -# Always returns 0: -get_plural_id = lambda n: 0 - -# Construct and return plural form of *word* using -# *plural_id* (which ALWAYS>0). This function will be executed -# for words (or phrases) not found in plural_dict dictionary -# construct_plural_form = lambda word, plural_id: word - diff --git a/gluon/languages.py b/gluon/languages.py index 818ac90d..2d751d95 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -12,6 +12,7 @@ Plural subsystem is created by Vladyslav Kozlovskyy (Ukraine) import os import re +import pkgutil from utf8 import Utf8 from cgi import escape import portalocker @@ -82,7 +83,6 @@ regex_backslash = re.compile(r"\\([\\{}%])") regex_plural = re.compile('%({.+?})') regex_plural_dict = re.compile('^{(?P[^()[\]][^()[\]]*?)\((?P[^()\[\]]+)\)}$') # %%{word(varname or number)} regex_plural_tuple = re.compile('^{(?P[^[\]()]+)(?:\[(?P\d+)\])?}$') # %%{word[index]} or %%{word} -regex_plural_rules = re.compile('^plural_rules-[a-zA-Z]{2}(-[a-zA-Z]{2})?\.py$') # UTF8 helper functions def upper_fun(s): @@ -215,48 +215,23 @@ def read_possible_languages(appdir): langs['en'] = ('en', 'English', 0) return langs -def read_global_plural_rules(filename): - """ - retrieve plural rules from rules/*plural_rules-lang*.py file. - - args: - filename (str): plural_rules filename - - returns: - (nplurals, get_plural_id, construct_plural_form, status) - e.g.: (3, , , ok) - """ - env = {} - data = portalocker.read_locked(filename) - try: - exec(data) in env - status='ok' - except Exception, e: - status='Syntax error in %s (%s)' % (filename, e) - logging.error(status) - nplurals = env.get('nplurals', DEFAULT_NPLURALS) - get_plural_id = env.get('get_plural_id', DEFAULT_GET_PLURAL_ID) - construct_plural_form = env.get('construct_plural_form', - DEFAULT_CONSTRUCTOR_PLURAL_FORM) - return (nplurals, get_plural_id, construct_plural_form, status) - - def read_possible_plurals(): """ create list of all possible plural rules files result is cached to increase speed """ - pdir = pjoin(pdirname(__file__),'contrib','rules') + import gluon.contrib.plural_rules as package plurals = {} - # scan rules directory for plural_rules-*.py files: - if os.path.exists(pdir): - for pname in os.listdir(pdir): - if not isdir(pname) and regex_plural_rules.match(pname): - lang = pname[13:-3] - fname = ospath.join(pdir, pname) - n, f1, f2, status = read_global_plural_rules(fname) - if status == 'ok': - plurals[lang] = (lang, n, f1, f2, pname) + for importer, modname, ispkg in pkgutil.iter_modules(package.__path__): + if len(modname)==2: + module = __import__(package.__name__+'.'+modname) + lang = modname + pname = modname+'.py' + nplurals = getattr(module,'nplurals', DEFAULT_NPLURALS) + get_plural_id = getattr(module,'get_plural_id', DEFAULT_GET_PLURAL_ID) + construct_plural_form = getattr(module,'construct_plural_form', + DEFAULT_CONSTRUCTOR_PLURAL_FORM) + plurals[lang] = (lang, nplurals, get_plural_id, construct_plural_form, pname) plurals['default'] = ('default', DEFAULT_NPLURALS, DEFAULT_GET_PLURAL_ID,