mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Merge branch 'l10n-fr' into testing
This commit is contained in:
commit
e4256ff8c7
26
src/i18n.py
26
src/i18n.py
@ -56,7 +56,7 @@ def import_conf():
|
|||||||
for key in i18nClasses:
|
for key in i18nClasses:
|
||||||
i18nClasses[key].loadLocale()
|
i18nClasses[key].loadLocale()
|
||||||
|
|
||||||
def get_plugin_dir(plugin_name):
|
def getPluginDir(plugin_name):
|
||||||
filename = None
|
filename = None
|
||||||
try:
|
try:
|
||||||
filename = sys.modules[plugin_name].__file__
|
filename = sys.modules[plugin_name].__file__
|
||||||
@ -75,10 +75,7 @@ def get_plugin_dir(plugin_name):
|
|||||||
|
|
||||||
def getLocalePath(name, localeName, extension):
|
def getLocalePath(name, localeName, extension):
|
||||||
if name != 'supybot':
|
if name != 'supybot':
|
||||||
try:
|
directory = getPluginDir(name) + 'locale'
|
||||||
directory = get_plugin_dir(name) + 'locale'
|
|
||||||
except TypeError: # get_plugin_dir returned None
|
|
||||||
return ''
|
|
||||||
else:
|
else:
|
||||||
import ansi # Any Supybot plugin could fit
|
import ansi # Any Supybot plugin could fit
|
||||||
directory = ansi.__file__[0:-len('ansi.pyc')] + 'locale'
|
directory = ansi.__file__[0:-len('ansi.pyc')] + 'locale'
|
||||||
@ -191,9 +188,13 @@ class _PluginInternationalization:
|
|||||||
return utils.str.normalizeWhitespace(str.replace(string, '\\n', '\n'))
|
return utils.str.normalizeWhitespace(str.replace(string, '\\n', '\n'))
|
||||||
|
|
||||||
def __call__(self, untranslated):
|
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:
|
if untranslated.__class__ == internationalizedString:
|
||||||
return untranslated._original
|
return untranslated._original
|
||||||
untranslated = __import__('supybot').utils.str.normalizeWhitespace(untranslated)
|
untranslated = utils.str.normalizeWhitespace(untranslated)
|
||||||
if not 'conf' in globals():
|
if not 'conf' in globals():
|
||||||
return untranslated
|
return untranslated
|
||||||
if self.currentLocaleName != conf.supybot.language():
|
if self.currentLocaleName != conf.supybot.language():
|
||||||
@ -207,12 +208,17 @@ class _PluginInternationalization:
|
|||||||
return untranslated
|
return untranslated
|
||||||
|
|
||||||
def _translate(self, string):
|
def _translate(self, string):
|
||||||
|
"""Translate the string.
|
||||||
|
|
||||||
|
C the string internationalizer if any; else, use the local database"""
|
||||||
if string.__class__ == internationalizedString:
|
if string.__class__ == internationalizedString:
|
||||||
return string._internationalizer(string.untranslated)
|
return string._internationalizer(string.untranslated)
|
||||||
else:
|
else:
|
||||||
return self.translations[string]
|
return self.translations[string]
|
||||||
|
|
||||||
def _addTracker(self, string, untranslated):
|
def _addTracker(self, string, untranslated):
|
||||||
|
"""Add a kind of 'tracker' on the string, in order to keep the
|
||||||
|
untranslated string (used when changing the locale)"""
|
||||||
if string.__class__ == internationalizedString:
|
if string.__class__ == internationalizedString:
|
||||||
return string
|
return string
|
||||||
else:
|
else:
|
||||||
@ -222,6 +228,8 @@ class _PluginInternationalization:
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
def _loadL10nCode(self):
|
def _loadL10nCode(self):
|
||||||
|
"""Open the file containing the code specific to this locale, and
|
||||||
|
load its functions."""
|
||||||
if self.name != 'supybot':
|
if self.name != 'supybot':
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
@ -287,11 +295,9 @@ class internationalizedFunction:
|
|||||||
self.__call__ = self._origin
|
self.__call__ = self._origin
|
||||||
|
|
||||||
class internationalizedString(str):
|
class internationalizedString(str):
|
||||||
|
"""Simple subclass to str, that allow to add attributes. Also used to
|
||||||
|
know if a string is already localized"""
|
||||||
pass
|
pass
|
||||||
# def __init__(self, *args, **kwargs):
|
|
||||||
# self.__parent.__init__(*args, **kwargs)
|
|
||||||
# self._original = str(self)
|
|
||||||
# self._internationalizer = None
|
|
||||||
|
|
||||||
def internationalizeDocstring(obj):
|
def internationalizeDocstring(obj):
|
||||||
"""Decorates functions and internationalize their docstring.
|
"""Decorates functions and internationalize their docstring.
|
||||||
|
Loading…
Reference in New Issue
Block a user