Merge branch 'i18n' into l10n-fr

This commit is contained in:
Valentin Lorentz 2010-11-01 15:01:57 +01:00
commit 22fa9f4098
2 changed files with 9 additions and 5 deletions

View File

@ -185,16 +185,17 @@ class _PluginInternationalization:
def _unescape(self, string):
import supybot.utils as utils
return utils.str.normalizeWhitespace(str.replace(string, '\\n', '\n'))
string = str.replace(string, '\\n', '\n') # gettext escapes the \n
string = utils.str.normalizeWhitespace(string, removeNewline=False)
return string
def __call__(self, untranslated):
"""Main function.
his is the function which is called when a plugin runs _()"""
import supybot.utils as utils
if untranslated.__class__ == internationalizedString:
return untranslated._original
untranslated = utils.str.normalizeWhitespace(untranslated)
untranslated = self._unescape(untranslated)
if not 'conf' in globals():
return untranslated
if self.currentLocaleName != conf.supybot.language():

View File

@ -59,11 +59,14 @@ def rsplit(s, sep=None, maxsplit=-1):
else:
return s.rsplit(sep, maxsplit)
def normalizeWhitespace(s):
def normalizeWhitespace(s, removeNewline=True):
"""Normalizes the whitespace in a string; \s+ becomes one space."""
beginning = s.startswith(' ')
ending = s.endswith(' ')
if removeNewline:
s = ' '.join(s.split())
else:
s = ' '.join(s.split(' '))
if beginning:
s = ' ' + s
if ending: