--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ d23f9c796805 Tue Nov 29 23:05:52 2011 +0100 @@ -0,0 +1,54 @@ +#!/usr/bin/env python2 + +from gettext import * + +_searchdirs=None + +origfind=find + +def setpaths(pathlist): + global _searchdirs + if isinstance(pathlist,list): + _searchdirs=pathlist + else: + _searchdirs=list(pathlist) + +def addpath(path): + global _searchdirs + if _searchdirs is None: + _searchdirs=list(path) + else: + if path not in _searchdirs: + _searchdirs.append(path) + +def delpath(path): + global _searchdirs + if _searchdirs is not None: + if path in _searchdirs: + _searchdirs.remove(path) + +def clearpath(): + global _searchdirs + if _searchdirs is not None: + _searchdirs=None + +def find(domain, localedir=None, languages=None, all=False): + if _searchdirs is None: + return origfind(domain, localedir, languages, all) + searches=[localedir]+_searchdirs + results=list() + for dir in searches: + res=origfind(domain,dir,languages,all) + if all is False: + results.append(res) + else: + results.extend(res) + if all is False: + results=filter(lambda x:x is not None,results) + if len(results)==0: + return None + else: + return results[0] + else: + return results + --- a/module/setup.py Tue Nov 29 21:45:27 2011 +0100 +++ a/module/setup.py Tue Nov 29 23:05:52 2011 +0100 @@ -17,7 +17,7 @@ @author: RaNaN """ from getpass import getpass -import gettext +import module.common.pylgettext as gettext import os from os import makedirs from os.path import abspath @@ -44,7 +44,8 @@ langs = self.config.getMetaData("general", "language")["type"].split(";") lang = self.ask(u"Choose your Language / Wähle deine Sprache", "en", langs) - translation = gettext.translation("setup", join(self.path, "locale"), languages=["en", lang]) + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) + translation = gettext.translation("setup", join(self.path, "locale"), languages=[lang, "en"],fallback=True) translation.install(True) # print "" @@ -342,8 +343,8 @@ self.config["ssl"]["activated"] = self.ask(_("Activate SSL?"), "y", bool=True) def set_user(self): - - translation = gettext.translation("setup", join(self.path, "locale"), languages=["en", self.config["general"]["language"]]) + gettext.setpaths([join(os.sep), "usr", "share", "pyload", "locale"), None]) + translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"],"en"],fallback=True) translation.install(True) from module.database import DatabaseBackend @@ -394,7 +395,8 @@ def conf_path(self, trans=False): if trans: - translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"]]) + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) + translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"], "en"],fallback=True) translation.install(True) print _("Setting new configpath, current configuration will not be transfered!") --- a/module/web/webinterface.py Tue Nov 29 21:45:27 2011 +0100 +++ a/module/web/webinterface.py Tue Nov 29 23:05:52 2011 +0100 @@ -18,8 +18,9 @@ """ import sys -import gettext +import module.common.pylgettext as gettext +import os from os.path import join, abspath, dirname, exists from os import makedirs @@ -98,8 +99,9 @@ else: env.filters["url"] = lambda x: PREFIX + x if x.startswith("/") else x +gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("django", join(PYLOAD_DIR, "locale"), - languages=["en", config.get("general", "language")]) + languages=[config.get("general", "language"), "en"],fallback=True) translation.install(True) env.install_gettext_translations(translation) --- a/pyLoadCli.py Tue Nov 29 21:45:27 2011 +0100 +++ a/pyLoadCli.py Tue Nov 29 23:05:52 2011 +0100 @@ -20,7 +20,7 @@ from __future__ import with_statement from getopt import GetoptError, getopt -import gettext +import module.common.pylgettext as gettext import os from os import _exit from os.path import join, exists, abspath, basename @@ -490,8 +490,9 @@ for opt in configFile.items("cli"): config[opt[0]] = opt[1] + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("pyLoadCli", join(pypath, "locale"), - languages=["en", config["language"]]) + languages=[config["language"],"en"],fallback=True) translation.install(unicode=True) interactive = False @@ -515,8 +516,9 @@ config["port"] = params elif option in ("-l", "--language"): config["language"] = params + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("pyLoadCli", join(pypath, "locale"), - languages=["en", config["language"]]) + languages=[config["language"],"en"],fallback=True) translation.install(unicode=True) elif option in ("-h", "--help"): print_help(config) @@ -585,4 +587,4 @@ if __name__ == "__main__": - main() + main() --- a/pyLoadCore.py Tue Nov 29 21:45:27 2011 +0100 +++ a/pyLoadCore.py Tue Nov 29 23:05:52 2011 +0100 @@ -25,7 +25,7 @@ import __builtin__ from getopt import getopt, GetoptError -import gettext +import module.common.pylgettext as gettext from imp import find_module import logging import logging.handlers @@ -288,8 +288,9 @@ self.config = ConfigParser() + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("pyLoad", self.path("locale"), - languages=["en", self.config['general']['language']]) + languages=[self.config['general']['language'],"en"],fallback=True) translation.install(True) self.debug = self.doDebug or self.config['general']['debug_mode'] --- a/pyLoadGui.py Tue Nov 29 21:45:27 2011 +0100 +++ a/pyLoadGui.py Tue Nov 29 23:05:52 2011 +0100 @@ -29,7 +29,8 @@ from PyQt4.QtGui import * import re -import gettext +import module.common.pylgettext as gettext +import os from os.path import abspath from os.path import join from os.path import basename @@ -77,7 +78,8 @@ parser = XMLParser(join(self.path, "module", "config", "gui_default.xml")) lang = parser.xml.elementsByTagName("language").item(0).toElement().text() - translation = gettext.translation("pyLoadGui", join(pypath, "locale"), languages=["en", str(lang)]) + gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) + translation = gettext.translation("pyLoadGui", join(pypath, "locale"), languages=[str(lang), "en"], fallback=True) try: translation.install(unicode=(True if sys.stdout.encoding.lower().startswith("utf") else False)) except: