From 97f51ab08e1066f46820a68ab94fe7a5241219a9 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 28 Oct 2010 16:42:52 +0200 Subject: [PATCH 1/3] Fix i18n bug for global Supybot --- src/i18n.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/i18n.py b/src/i18n.py index b246908b7..60a6a3190 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -93,9 +93,13 @@ class PluginInternationalization: elif localeName is None: localeName = 'en' self.currentLocaleName = localeName - directory = get_plugin_dir(self.name) + 'locale' + if self.name != 'supybot': + directory = get_plugin_dir(self.name) + 'locale' + filename = '%s/%s.po' % (directory, localeName) + else: + filename = 'locale/%s.po' % localeName try: - translationFile = open('%s/%s.po' % (directory, localeName), 'ru') + translationFile = open(filename, 'ru') except IOError: # The translation is unavailable self.translations = {} return @@ -170,7 +174,7 @@ class PluginInternationalization: return self.translations[untranslated] % args except KeyError: return untranslated % args - + def internationalizeDocstring(obj): # FIXME: check if the plugin has an _ object From e8bc966827fbeecb082d39b7009c655e26c70641 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 28 Oct 2010 17:28:27 +0200 Subject: [PATCH 2/3] Add locale abitrary code Add the capability for Supybot to load code depending on the locale src/utils/str.py now imports pluralize and depluralize from this code --- src/i18n.py | 32 ++++++++++++++++++++++++++------ src/utils/str.py | 11 ++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/i18n.py b/src/i18n.py index 60a6a3190..1236d2a74 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -67,6 +67,14 @@ def get_plugin_dir(plugin_name): return filename[0:-len(allowed_file)] return +def getLocalePath(name, localeName, extension): + if name != 'supybot': + directory = get_plugin_dir(name) + 'locale' + else: + import ansi # Any Supybot plugin could fit + directory = ansi.__file__[0:-len('ansi.pyc')] + 'locale' + return '%s/%s.%s' % (directory, localeName, extension) + i18nClasses = {} internationalizedCommands = {} @@ -93,13 +101,11 @@ class PluginInternationalization: elif localeName is None: localeName = 'en' self.currentLocaleName = localeName - if self.name != 'supybot': - directory = get_plugin_dir(self.name) + 'locale' - filename = '%s/%s.po' % (directory, localeName) - else: - filename = 'locale/%s.po' % localeName + try: - translationFile = open(filename, 'ru') + translationFile = open(getLocalePath(self.name, localeName, 'po'), + 'ru') # ru is the mode, not the beginning + # of 'russian' ;) except IOError: # The translation is unavailable self.translations = {} return @@ -175,6 +181,20 @@ class PluginInternationalization: except KeyError: return untranslated % args + def _getL10nCode(self): + return getLocalePath('supybot', self.currentLocaleName, 'py') + + def getPluralizers(self, current_pluralize, current_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) + def internationalizeDocstring(obj): # FIXME: check if the plugin has an _ object diff --git a/src/utils/str.py b/src/utils/str.py index 2c6fef345..73be108ba 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -42,6 +42,9 @@ import textwrap from iter import all, any from structures import TwoWayDictionary +from supybot.i18n import PluginInternationalization +_ = PluginInternationalization() + curry = new.instancemethod chars = string.maketrans('', '') @@ -253,12 +256,12 @@ def matchCase(s1, s2): L[i] = L[i].upper() return ''.join(L) -consonants = 'bcdfghjklmnpqrstvwxz' -_pluralizeRegex = re.compile('[%s]y$' % consonants) def pluralize(s): """Returns the plural of s. Put any exceptions to the general English rule of appending 's' in the plurals dictionary. """ + consonants = 'bcdfghjklmnpqrstvwxz' + _pluralizeRegex = re.compile('[%s]y$' % consonants) lowered = s.lower() # Exception dictionary if lowered in plurals: @@ -275,9 +278,9 @@ def pluralize(s): else: return matchCase(s, s+'s') -_depluralizeRegex = re.compile('[%s]ies' % consonants) def depluralize(s): """Returns the singular of s.""" + _depluralizeRegex = re.compile('[%s]ies' % consonants) lowered = s.lower() if lowered in plurals: return matchCase(s, plurals[lowered]) @@ -291,6 +294,8 @@ def depluralize(s): else: return s # Don't know what to do. +pluralize, depluralize = _.getPluralizers(pluralize, depluralize) + def nItems(n, item, between=None): """Works like this: From 6c1b91c227a13fb3168d44b0731e49a622e0f973 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 29 Oct 2010 12:03:08 +0200 Subject: [PATCH 3/3] MoobotFactoid: Internationalize a string --- plugins/MoobotFactoids/messages.pot | 92 ++++++++++++++++------------- plugins/MoobotFactoids/plugin.py | 4 +- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/plugins/MoobotFactoids/messages.pot b/plugins/MoobotFactoids/messages.pot index 0c51bc8d8..ce53fb9a3 100644 --- a/plugins/MoobotFactoids/messages.pot +++ b/plugins/MoobotFactoids/messages.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2010-10-17 16:36+CEST\n" +"POT-Creation-Date: 2010-10-29 12:02+CEST\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -28,38 +28,38 @@ msgid "" " when the 'most' command is called." msgstr "" -#: plugin.py:293 +#: plugin.py:292 #, docstring msgid "" "Add the help for \"@help MoobotFactoids\" here (assuming you don't implement a MoobotFactoids\n" " command). This should describe *how* to use this plugin." msgstr "" -#: plugin.py:350 +#: plugin.py:349 msgid "%s is %s" msgstr "" -#: plugin.py:369 +#: plugin.py:368 msgid "Factoid %q is locked." msgstr "" -#: plugin.py:376 +#: plugin.py:375 msgid "Factoid %q not found." msgstr "" -#: plugin.py:386 +#: plugin.py:385 msgid "Missing an 'is' or '_is_'." msgstr "" -#: plugin.py:402 +#: plugin.py:401 msgid "Factoid %q already exists." msgstr "" -#: plugin.py:436 +#: plugin.py:435 msgid "%s, or %s" msgstr "" -#: plugin.py:457 +#: plugin.py:456 #, docstring msgid "" "[] \n" @@ -70,7 +70,7 @@ msgid "" " " msgstr "" -#: plugin.py:470 +#: plugin.py:469 #, docstring msgid "" "[] \n" @@ -81,39 +81,39 @@ msgid "" " " msgstr "" -#: plugin.py:481 plugin.py:521 +#: plugin.py:480 plugin.py:520 msgid "No such factoid: %q" msgstr "" -#: plugin.py:490 +#: plugin.py:489 msgid "Created by %s on %s." msgstr "" -#: plugin.py:496 +#: plugin.py:495 msgid " Last modified by %s on %s." msgstr "" -#: plugin.py:504 +#: plugin.py:503 msgid " Last requested by %s on %s, requested %n." msgstr "" -#: plugin.py:511 +#: plugin.py:510 msgid " Locked by %s on %s." msgstr "" -#: plugin.py:526 +#: plugin.py:525 msgid "Factoid %q is already locked." msgstr "" -#: plugin.py:529 +#: plugin.py:528 msgid "Factoid %q is not locked." msgstr "" -#: plugin.py:539 +#: plugin.py:538 msgid "Cannot %s someone else's factoid unless you are an admin." msgstr "" -#: plugin.py:551 +#: plugin.py:550 #, docstring msgid "" "[] \n" @@ -124,7 +124,7 @@ msgid "" " " msgstr "" -#: plugin.py:562 +#: plugin.py:561 #, docstring msgid "" "[] \n" @@ -135,7 +135,7 @@ msgid "" " " msgstr "" -#: plugin.py:573 +#: plugin.py:572 #, docstring msgid "" "[] {popular|authored|recent}\n" @@ -148,43 +148,51 @@ msgid "" " " msgstr "" -#: plugin.py:598 +#: plugin.py:594 +msgid "author" +msgstr "" + +#: plugin.py:596 +msgid "authors" +msgstr "" + +#: plugin.py:597 msgid "Most prolific %s: %L" msgstr "" -#: plugin.py:600 plugin.py:612 +#: plugin.py:599 plugin.py:611 msgid "There are no factoids in my database." msgstr "" -#: plugin.py:607 +#: plugin.py:606 msgid "latest factoid" msgstr "" -#: plugin.py:609 +#: plugin.py:608 msgid "latest factoids" msgstr "" -#: plugin.py:610 +#: plugin.py:609 msgid "%s: %L" msgstr "" -#: plugin.py:619 +#: plugin.py:618 msgid "requested factoid" msgstr "" -#: plugin.py:621 +#: plugin.py:620 msgid "requested factoids" msgstr "" -#: plugin.py:622 +#: plugin.py:621 msgid "Top %s: %L" msgstr "" -#: plugin.py:624 +#: plugin.py:623 msgid "No factoids have been requested from my database." msgstr "" -#: plugin.py:628 +#: plugin.py:627 #, docstring msgid "" "[] \n" @@ -196,15 +204,15 @@ msgid "" " " msgstr "" -#: plugin.py:641 +#: plugin.py:640 msgid "No factoids by %q found." msgstr "" -#: plugin.py:644 +#: plugin.py:643 msgid "Author search for %q (%i found): %L" msgstr "" -#: plugin.py:651 +#: plugin.py:650 #, docstring msgid "" "[] \n" @@ -215,15 +223,15 @@ msgid "" " " msgstr "" -#: plugin.py:659 +#: plugin.py:658 msgid "No keys matching %q found." msgstr "" -#: plugin.py:666 +#: plugin.py:665 msgid "Key search for %q (%i found): %L" msgstr "" -#: plugin.py:673 +#: plugin.py:672 #, docstring msgid "" "[] \n" @@ -234,15 +242,15 @@ msgid "" " " msgstr "" -#: plugin.py:681 +#: plugin.py:680 msgid "No values matching %q found." msgstr "" -#: plugin.py:684 +#: plugin.py:683 msgid "Value search for %q (%i found): %L" msgstr "" -#: plugin.py:691 +#: plugin.py:690 #, docstring msgid "" "[] \n" @@ -252,7 +260,7 @@ msgid "" " " msgstr "" -#: plugin.py:704 +#: plugin.py:703 #, docstring msgid "" "[]\n" @@ -263,7 +271,7 @@ msgid "" " " msgstr "" -#: plugin.py:712 +#: plugin.py:711 msgid "No factoids in the database." msgstr "" diff --git a/plugins/MoobotFactoids/plugin.py b/plugins/MoobotFactoids/plugin.py index b3f5a1bac..6576dadbd 100644 --- a/plugins/MoobotFactoids/plugin.py +++ b/plugins/MoobotFactoids/plugin.py @@ -591,9 +591,9 @@ class MoobotFactoids(callbacks.Plugin): L = ['%s (%s)' % (plugins.getUserName(t[0]), int(t[1])) for t in results] if L: - author = 'author' + author = _('author') if len(L) != 1: - author = 'authors' + author = _('authors') irc.reply(format(_('Most prolific %s: %L'), author, L)) else: irc.error(_('There are no factoids in my database.'))