implemented gettext instead of old hdf style
This commit is contained in:
parent
27b61640bc
commit
557d3e8f8c
|
@ -207,6 +207,9 @@ class CryptoBoxProps(CryptoBox):
|
||||||
'''reads all files in path LangDir and returns a list of
|
'''reads all files in path LangDir and returns a list of
|
||||||
basenames from existing hdf files, that should are all available
|
basenames from existing hdf files, that should are all available
|
||||||
languages'''
|
languages'''
|
||||||
|
# TODO: for now we hardcode it - change this!
|
||||||
|
return "en fr si de".split(" ")
|
||||||
|
# TODO: old implementation (before gettext) - remove it
|
||||||
languages = [ f.rstrip(".hdf")
|
languages = [ f.rstrip(".hdf")
|
||||||
for f in os.listdir(self.prefs["Locations"]["LangDir"])
|
for f in os.listdir(self.prefs["Locations"]["LangDir"])
|
||||||
if f.endswith(".hdf") ]
|
if f.endswith(".hdf") ]
|
||||||
|
|
|
@ -81,28 +81,15 @@ class CryptoBoxPlugin:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getLanguageData(self, lang="en"):
|
def getLanguageData(self):
|
||||||
try:
|
import neo_cgi, neo_util
|
||||||
import neo_cgi, neo_util
|
|
||||||
except:
|
|
||||||
raise CryptoBoxExceptions.CBEnvironmentError("couldn't import 'neo_*'! Try 'apt-get install python-clearsilver'.")
|
|
||||||
langdir = os.path.abspath(os.path.join(self.pluginDir, "lang"))
|
|
||||||
## first: the default language file (english)
|
|
||||||
langFiles = [os.path.join(langdir, "en.hdf")]
|
|
||||||
## maybe we have to load a translation afterwards
|
|
||||||
if lang != "en":
|
|
||||||
langFiles.append(os.path.join(langdir, lang + ".hdf"))
|
|
||||||
file_found = False
|
|
||||||
lang_hdf = neo_util.HDF()
|
lang_hdf = neo_util.HDF()
|
||||||
for langFile in langFiles:
|
langFile = os.path.join(self.pluginDir, 'language.hdf')
|
||||||
if os.access(langFile, os.R_OK):
|
try:
|
||||||
lang_hdf.readFile(langFile)
|
lang_hdf.readFile(langFile)
|
||||||
file_found = True
|
except (neo_util.Error, neo_util.ParseError), errMsg:
|
||||||
if file_found:
|
self.cbox.log.error("failed to load language file (%s) of plugin (%s):" % (langFile,self.getName()))
|
||||||
return lang_hdf
|
return lang_hdf
|
||||||
else:
|
|
||||||
self.cbox.log.debug("Couldn't find a valid plugin language file (%s)" % str(langFiles))
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def loadDataSet(self, hdf):
|
def loadDataSet(self, hdf):
|
||||||
|
|
|
@ -16,6 +16,8 @@ except ImportError:
|
||||||
raise ImportError, errorMsg
|
raise ImportError, errorMsg
|
||||||
|
|
||||||
|
|
||||||
|
GETTEXT_DOMAIN = 'cryptobox-server'
|
||||||
|
|
||||||
|
|
||||||
class PluginIconHandler:
|
class PluginIconHandler:
|
||||||
|
|
||||||
|
@ -385,7 +387,40 @@ class WebInterfaceSites:
|
||||||
return hdf.getValue(value, "")
|
return hdf.getValue(value, "")
|
||||||
|
|
||||||
|
|
||||||
|
def __substituteGettext(self, languages, textDomain, hdf):
|
||||||
|
import gettext
|
||||||
|
try:
|
||||||
|
translator = gettext.translation(textDomain, languages=languages)
|
||||||
|
except IOError, errMsg:
|
||||||
|
## no translation found
|
||||||
|
self.cbox.log.warn("unable to load language file: %s" % errMsg)
|
||||||
|
return hdf
|
||||||
|
def walk_tree(hdf_node):
|
||||||
|
def translate_node(node):
|
||||||
|
for (key,value) in node.attrs():
|
||||||
|
if key == 'LINK': return
|
||||||
|
node.setValue("",translator.ugettext(node.value()))
|
||||||
|
while hdf_node:
|
||||||
|
translate_node(hdf_node)
|
||||||
|
walk_tree(hdf_node.child())
|
||||||
|
hdf_node = hdf_node.next()
|
||||||
|
walk_tree(hdf)
|
||||||
|
|
||||||
|
|
||||||
def __getLanguageData(self, web_lang="en"):
|
def __getLanguageData(self, web_lang="en"):
|
||||||
|
hdf = neo_util.HDF()
|
||||||
|
hdf.readFile(os.path.join(self.prefs["Locations"]["TemplateDir"],"language.hdf"))
|
||||||
|
self.__substituteGettext([web_lang], GETTEXT_DOMAIN, hdf)
|
||||||
|
## load the language data of all plugins
|
||||||
|
for p in self.pluginList.getPlugins():
|
||||||
|
pl_lang = p.getLanguageData()
|
||||||
|
self.__substituteGettext([web_lang], "%s-feature-%s" % (GETTEXT_DOMAIN, p.getName()), pl_lang)
|
||||||
|
hdf.copy("Plugins.%s" % p.getName(), pl_lang)
|
||||||
|
self.cbox.log.debug("language data for plugin loaded: %s" % p.getName())
|
||||||
|
return hdf
|
||||||
|
|
||||||
|
|
||||||
|
def __getLanguageData2(self, web_lang="en"):
|
||||||
default_lang = "en"
|
default_lang = "en"
|
||||||
conf_lang = self.prefs["WebSettings"]["Language"]
|
conf_lang = self.prefs["WebSettings"]["Language"]
|
||||||
hdf = neo_util.HDF()
|
hdf = neo_util.HDF()
|
||||||
|
@ -427,12 +462,6 @@ class WebInterfaceSites:
|
||||||
## first: assume, that the template file is in the global template directory
|
## first: assume, that the template file is in the global template directory
|
||||||
self.dataset["Settings.TemplateFile"] = os.path.abspath(os.path.join(self.prefs["Locations"]["TemplateDir"], template + ".cs"))
|
self.dataset["Settings.TemplateFile"] = os.path.abspath(os.path.join(self.prefs["Locations"]["TemplateDir"], template + ".cs"))
|
||||||
|
|
||||||
## load the language data of all plugins
|
|
||||||
for p in self.pluginList.getPlugins():
|
|
||||||
pl_lang = p.getLanguageData(self.dataset["Settings.Language"])
|
|
||||||
if pl_lang:
|
|
||||||
hdf.copy("Lang.Plugins.%s" % p.getName(), pl_lang)
|
|
||||||
|
|
||||||
if plugin:
|
if plugin:
|
||||||
## check, if the plugin provides the template file -> overriding
|
## check, if the plugin provides the template file -> overriding
|
||||||
plugin_cs_file = plugin.getTemplateFileName(template)
|
plugin_cs_file = plugin.getTemplateFileName(template)
|
||||||
|
@ -472,4 +501,3 @@ class WebInterfaceSites:
|
||||||
else:
|
else:
|
||||||
yield line + "\n"
|
yield line + "\n"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue