Update RapydScript

This commit is contained in:
Kovid Goyal 2016-04-02 22:31:56 +05:30
parent 0a5d6a3bf4
commit a1f50c1739
2 changed files with 12 additions and 9 deletions

Binary file not shown.

View File

@ -518,30 +518,33 @@ def install(translation_data):
t.install() t.install()
return t return t
has_prop = Object.prototype.hasOwnProperty
class Translations: class Translations:
def __init__(self, translation_data): def __init__(self, translation_data):
translation_data = translation_data or {} translation_data = translation_data or {}
translation_data['func'] = _get_plural_forms_function(translation_data['plural_forms']) func = _get_plural_forms_function(translation_data['plural_forms'])
self.translations = v'[translation_data]' self.translations = [[translation_data, func]]
self.language = translation_data['language'] self.language = translation_data['language']
def add_fallback(self, fallback): def add_fallback(self, fallback):
fallback['func'] = _get_plural_forms_function(fallback['plural_forms']) fallback = fallback or {}
self.translations.push(fallback or {}) func = _get_plural_forms_function(fallback['plural_forms'])
self.translations.push([fallback, func])
def gettext(self, text): def gettext(self, text):
for t in self.translations: for t in self.translations:
m = t['entries'] m = t[0]['entries']
if Object.prototype.hasOwnProperty.call(m, text): if has_prop.call(m, text):
return m[text][0] return m[text][0]
return text return text
def ngettext(self, text, plural, n): def ngettext(self, text, plural, n):
for t in self.translations: for t in self.translations:
m = t['entries'] m = t[0]['entries']
if Object.prototype.hasOwnProperty.call(m, text): if has_prop.call(m, text):
idx = t['func'](n) idx = t[1](n)
return m[text][idx] or (text if n is 1 else plural) return m[text][idx] or (text if n is 1 else plural)
return text if n is 1 else plural return text if n is 1 else plural