Update RapydScript

This commit is contained in:
Kovid Goyal 2018-03-24 10:12:22 +05:30
parent 5e7d0fd42d
commit b6fb23ed68
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 7 deletions

View File

@ -531,29 +531,31 @@ def register_callback(func):
register_callback.install_callbacks.push(func) register_callback.install_callbacks.push(func)
register_callback.install_callbacks = v'[]' register_callback.install_callbacks = v'[]'
empty_translation_data = {'entries': {}}
class Translations: class Translations:
def __init__(self, translation_data): def __init__(self, translation_data):
translation_data = translation_data or {} translation_data = translation_data or empty_translation_data
func = _get_plural_forms_function(translation_data['plural_forms']) func = _get_plural_forms_function(translation_data.plural_forms)
self.translations = [[translation_data, func]] 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 = fallback or {} fallback = fallback or empty_translation_data
func = _get_plural_forms_function(fallback['plural_forms']) func = _get_plural_forms_function(fallback.plural_forms)
self.translations.push([fallback, func]) 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[0]['entries'] m = t[0].entries
if has_prop(m, text): if has_prop(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[0]['entries'] m = t[0].entries
if has_prop(m, text): if has_prop(m, text):
idx = t[1](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)
@ -565,4 +567,3 @@ class Translations:
return self.gettext.apply(self, arguments) return self.gettext.apply(self, arguments)
_ngettext = def (): _ngettext = def ():
return self.ngettext.apply(self, arguments) return self.ngettext.apply(self, arguments)

View File

@ -30,6 +30,7 @@
ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256] ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256]
def seed(x=Date().getTime()): def seed(x=Date().getTime()):
ρσ_seed_state.key_i = ρσ_seed_state.key_j = 0
if jstype(x) is 'number': if jstype(x) is 'number':
x = x.toString() x = x.toString()
elif jstype(x) is not 'string': elif jstype(x) is not 'string':