From b6fb23ed6898ac2102608a87b3e210318cdf1395 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 24 Mar 2018 10:12:22 +0530 Subject: [PATCH] Update RapydScript --- resources/rapydscript/lib/gettext.pyj | 15 ++++++++------- resources/rapydscript/lib/random.pyj | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/resources/rapydscript/lib/gettext.pyj b/resources/rapydscript/lib/gettext.pyj index bb1665df78..2a5b3c690f 100644 --- a/resources/rapydscript/lib/gettext.pyj +++ b/resources/rapydscript/lib/gettext.pyj @@ -531,29 +531,31 @@ def register_callback(func): register_callback.install_callbacks.push(func) register_callback.install_callbacks = v'[]' +empty_translation_data = {'entries': {}} + class Translations: def __init__(self, translation_data): - translation_data = translation_data or {} - func = _get_plural_forms_function(translation_data['plural_forms']) + translation_data = translation_data or empty_translation_data + func = _get_plural_forms_function(translation_data.plural_forms) self.translations = [[translation_data, func]] self.language = translation_data['language'] def add_fallback(self, fallback): - fallback = fallback or {} - func = _get_plural_forms_function(fallback['plural_forms']) + fallback = fallback or empty_translation_data + func = _get_plural_forms_function(fallback.plural_forms) self.translations.push([fallback, func]) def gettext(self, text): for t in self.translations: - m = t[0]['entries'] + m = t[0].entries if has_prop(m, text): return m[text][0] return text def ngettext(self, text, plural, n): for t in self.translations: - m = t[0]['entries'] + m = t[0].entries if has_prop(m, text): idx = t[1](n) return m[text][idx] or (text if n is 1 else plural) @@ -565,4 +567,3 @@ class Translations: return self.gettext.apply(self, arguments) _ngettext = def (): return self.ngettext.apply(self, arguments) - diff --git a/resources/rapydscript/lib/random.pyj b/resources/rapydscript/lib/random.pyj index 9c283b5737..bacd5791b2 100644 --- a/resources/rapydscript/lib/random.pyj +++ b/resources/rapydscript/lib/random.pyj @@ -30,6 +30,7 @@ ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256] def seed(x=Date().getTime()): + ρσ_seed_state.key_i = ρσ_seed_state.key_j = 0 if jstype(x) is 'number': x = x.toString() elif jstype(x) is not 'string':