Module: check_mk
Branch: master
Commit: 2c6db1ec483a34e274e6a3b161080e8093b2e1e0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2c6db1ec483a34…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 10 10:06:03 2012 +0100
cmk --localize update supports an optional ALIAS which is used as
display string in the multisite GUI
---
ChangeLog | 2 ++
modules/localize.py | 37 +++++++++++++++++++++++++++----------
web/htdocs/lib.py | 11 ++++++++++-
3 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 81df73b..72d59f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
* cmk -O/-R now uses omd re{start,load} core if using OMD
* FIX: setup.sh now setups up permissions for conf.d/wato
correctly
+ * cmk --localize update supports an optional ALIAS which is used as
+ display string in the multisite GUI
Checks & Agents:
* Windows agent: output eventlog texts in UTF-8 encoding. This
diff --git a/modules/localize.py b/modules/localize.py
index f409fcc..85e1650 100755
--- a/modules/localize.py
+++ b/modules/localize.py
@@ -39,9 +39,10 @@ def verbose_system(command):
domain = 'multisite'
-pot_file = None
-po_file = None
-mo_file = None
+pot_file = None
+po_file = None
+mo_file = None
+alias_file = None
if local_locale_dir:
locale_base = local_locale_dir
@@ -61,10 +62,12 @@ def localize_usage(err = ''):
BE AWARE: This is an experimental feature!!!
Available commands are:
- update LANG ... Creates or updates a .po file for the given language.
- compile LANG ... Compiles the .po file into a .mo file which can
- be used by gettext.
- edit LANG ... Call update, open .po in editor and compile in one step
+ update LANG (ALIAS) ... Creates or updates a .po file for the given language.
+ The alias is an optional attribute which will be used as
+ display string in the Multisite GUI.
+ compile LANG ... Compiles the .po file into a .mo file which can
+ be used by gettext.
+ edit LANG ... Call update, open .po in editor and compile in one step
The regular process for translating is:
@@ -86,6 +89,10 @@ def do_localize(args):
else:
lang = None
+ alias = None
+ if len(args) > 2:
+ alias = args[2]
+
commands = {
"update" : localize_update,
"compile" : localize_compile,
@@ -97,6 +104,7 @@ def do_localize(args):
try:
f(lang)
+ write_alias(alias)
except LocalizeException, e:
sys.stderr.write("%s\n" % e)
sys.exit(1)
@@ -108,6 +116,14 @@ def do_localize(args):
(", ".join(allc[:-1]), allc[-1]))
sys.exit(1)
+def write_alias(alias):
+ if not alias:
+ return
+
+ if alias == '-':
+ os.remove(alias_file)
+ else:
+ file(alias_file, 'w').write(alias)
def check_binaries():
# Are the xgettext utils available?
@@ -121,9 +137,10 @@ def get_languages():
def init_files(lang):
- global po_file, mo_file
- po_file = locale_base + '/%s/LC_MESSAGES/%s.po' % (lang, domain)
- mo_file = locale_base + '/%s/LC_MESSAGES/%s.mo' % (lang, domain)
+ global po_file, mo_file, alias_file
+ po_file = locale_base + '/%s/LC_MESSAGES/%s.po' % (lang, domain)
+ mo_file = locale_base + '/%s/LC_MESSAGES/%s.mo' % (lang, domain)
+ alias_file = locale_base + '/%s/alias' % (lang)
def localize_update_po():
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index e2cffda..2d3ab6f 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -126,9 +126,18 @@ def get_languages():
if defaults.omd_root:
dirs.append(defaults.omd_root + "/local/share/check_mk/locale")
+ def get_language_alias(dirs, lang):
+ alias = lang
+ for lang_dir in dirs:
+ try:
+ alias = file('%s/%s/alias' % (lang_dir, lang),
'r').read().strip()
+ except (OSError, IOError):
+ pass
+ return alias
+
for lang_dir in dirs:
try:
- languages += [ (val, val) for val in os.listdir(lang_dir) if not '.'
in val ]
+ languages += [ (val, get_language_alias(dirs, val)) for val in
os.listdir(lang_dir) if not '.' in val ]
except OSError:
# Catch "OSError: [Errno 2] No such file or directory:" when
directory not exists
pass