Use unicode in src/i18n.py

This commit is contained in:
Valentin Lorentz 2012-08-04 12:09:11 +02:00
parent d28fa0cbdf
commit 505fd580f8

View File

@ -166,6 +166,7 @@ class _PluginInternationalization:
self.translations = {} self.translations = {}
for line in translationFile: for line in translationFile:
line = line[0:-1] # Remove the ending \n line = line[0:-1] # Remove the ending \n
line = line.decode('utf8', errors='replace')
if line.startswith(MSGID): if line.startswith(MSGID):
# Don't check if step is WAITING_FOR_MSGID # Don't check if step is WAITING_FOR_MSGID
@ -217,10 +218,10 @@ class _PluginInternationalization:
def _unescape(self, string, removeNewline=False): def _unescape(self, string, removeNewline=False):
import supybot.utils as utils import supybot.utils as utils
string = str.replace(string, '\\n\\n', '\n\n') string = string.replace('\\n\\n', '\n\n')
string = str.replace(string, '\\n', ' ') string = string.replace('\\n', ' ')
string = str.replace(string, '\\"', '"') string = string.replace('\\"', '"')
string = str.replace(string, "\'", "'") string = string.replace("\'", "'")
string = utils.str.normalizeWhitespace(string, removeNewline) string = utils.str.normalizeWhitespace(string, removeNewline)
return string return string
@ -317,7 +318,6 @@ class internationalizedFunction:
def __init__(self, internationalizer, name, function): def __init__(self, internationalizer, name, function):
self._internationalizer = internationalizer self._internationalizer = internationalizer
self._name = name self._name = name
self.__call__ = function
self._origin = function self._origin = function
internationalizedFunctions.append(self) internationalizedFunctions.append(self)
def loadLocale(self): def loadLocale(self):
@ -327,7 +327,10 @@ class internationalizedFunction:
def restore(self): def restore(self):
self.__call__ = self._origin self.__call__ = self._origin
class internationalizedString(str): def __call__(self, *args, **kwargs):
return self._origin(*args, **kwargs)
class internationalizedString(unicode):
"""Simple subclass to str, that allow to add attributes. Also used to """Simple subclass to str, that allow to add attributes. Also used to
know if a string is already localized""" know if a string is already localized"""
pass pass