From ec6a267c09e9c15c0610d28312906a74ae00fffe Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 29 Oct 2010 15:31:36 +0200 Subject: [PATCH 1/2] Internationalize more functions in src/utils/str.py --- src/i18n.py | 21 +++++++++++++++++++++ src/utils/str.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/i18n.py b/src/i18n.py index 1236d2a74..6f80564b2 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -195,6 +195,27 @@ class PluginInternationalization: else: return (current_pluralize, current_depluralize) + def getOrdinal(self, current_ordinal): + # This should be used only by src/utils/str.py + try: + execfile(self._getL10nCode()) + except IOError: + pass # Handled by the else v- + if locals().has_key('ordinal'): + return ordinal + else: + return current_ordinal + + def getBeAndHave(self, current_be, current_have): + # This should be used only by src/utils/str.py + try: + execfile(self._getL10nCode()) + except IOError: + pass # Handled by the else v- + if locals().has_key('be') and locals().has_key('have'): + return (be, have) + else: + return (current_be, current_have) def internationalizeDocstring(obj): # FIXME: check if the plugin has an _ object diff --git a/src/utils/str.py b/src/utils/str.py index 73be108ba..741b870b2 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -350,6 +350,8 @@ def ordinal(i): ord = 'rd' return '%s%s' % (i, ord) +ordinal = _.getOrdinal(ordinal) + def be(i): """Returns the form of the verb 'to be' based on the number i.""" if i == 1: @@ -364,6 +366,8 @@ def has(i): else: return 'have' +be, have = _.getVerbs(be, have) + def toBool(s): s = s.strip().lower() if s in ('true', 'on', 'enable', 'enabled', '1'): From 6737424bc6fae02da68fbf0655ea1cd4ac1142e2 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 29 Oct 2010 15:33:36 +0200 Subject: [PATCH 2/2] Shorten PluginInternationalisation.get* in src/i18n.py --- src/i18n.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/i18n.py b/src/i18n.py index 6f80564b2..51db7ba3c 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -184,38 +184,29 @@ class PluginInternationalization: def _getL10nCode(self): return getLocalePath('supybot', self.currentLocaleName, 'py') - def getPluralizers(self, current_pluralize, current_depluralize): + def getPluralizers(self, pluralize, depluralize): # This should be used only by src/utils/str.py try: execfile(self._getL10nCode()) except IOError: - pass # Handled by the else v- - if locals().has_key('pluralize') and locals().has_key('depluralize'): - return (pluralize, depluralize) - else: - return (current_pluralize, current_depluralize) + pass + return (pluralize, depluralize) - def getOrdinal(self, current_ordinal): + def getOrdinal(self, ordinal): # This should be used only by src/utils/str.py try: execfile(self._getL10nCode()) except IOError: - pass # Handled by the else v- - if locals().has_key('ordinal'): - return ordinal - else: - return current_ordinal + pass + return ordinal - def getBeAndHave(self, current_be, current_have): + def getBeAndHave(self, be, have): # This should be used only by src/utils/str.py try: execfile(self._getL10nCode()) except IOError: - pass # Handled by the else v- - if locals().has_key('be') and locals().has_key('have'): - return (be, have) - else: - return (current_be, current_have) + pass + return (be, have) def internationalizeDocstring(obj): # FIXME: check if the plugin has an _ object