[Dextrose] [PATCH 2/5] Kepp sugar locale in ~/.dmrc instead of ~/.i18n #2603

alsroot at sugarlabs.org alsroot at sugarlabs.org
Fri Oct 21 21:34:03 EDT 2011


From: Aleksey Lim <alsroot at activitycentral.org>

---
 bin/sugar.in                           |    9 ++++++-
 extensions/cpsection/language/model.py |   44 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletions(-)
 mode change 100644 => 100755 bin/sugar.in

diff --git a/bin/sugar.in b/bin/sugar.in
old mode 100644
new mode 100755
index de3cfbd..f5fb399
--- a/bin/sugar.in
+++ b/bin/sugar.in
@@ -80,7 +80,14 @@ if test "$SUGAR_EMULATOR" = "yes" -a "$(type gnome-keyring-daemon)"; then
 fi
 
 # Source language settings and debug definitions
-if [ -f ~/.i18n ]; then
+if [ -f ~/.dmrc ]; then
+    dmrc_lang=$(grep -i '^Language *=' ~/.dmrc | awk -F= '{print $2}' | sed 's/[[:space:]]//g')
+    if [ "${dmrc_lang}" ]; then
+        [ ${dmrc_lang} = "C" ] && dmrc_lang="en_US.utf8"
+        LANG="${dmrc_lang}"
+        LANGUAGE="${LANG}:$(grep -i '^ExtraLanguages *=' ~/.dmrc | awk -F= '{print $2}' | sed 's/[[:space:]]//g; s/;/:/g')"
+    fi
+elif [ -f ~/.i18n ]; then
         . ~/.i18n
 fi
 if [ -f ~/.sugar/debug ]; then
diff --git a/extensions/cpsection/language/model.py b/extensions/cpsection/language/model.py
index 17de6bb..06e945f 100644
--- a/extensions/cpsection/language/model.py
+++ b/extensions/cpsection/language/model.py
@@ -24,6 +24,7 @@ import os
 import locale
 from gettext import gettext as _
 import subprocess
+from ConfigParser import ConfigParser
 
 
 _default_lang = '%s.%s' % locale.getdefaultlocale()
@@ -68,6 +69,29 @@ def _initialize():
 
 
 def _write_i18n(lang_env, language_env):
+    dmrc_path = os.path.join(os.environ.get('HOME'), '.dmrc')
+    if os.path.exists(dmrc_path):
+        dmrc = ConfigParser()
+        dmrc.optionxform = lambda x: str(x).capitalize()
+        dmrc.read(dmrc_path)
+
+        if not dmrc.has_section('Desktop'):
+            dmrc.add_section('Desktop')
+        dmrc.set('Desktop', 'Language', lang_env)
+        if not dmrc.has_section('Sugar'):
+            dmrc.add_section('Sugar')
+        langs = language_env.split(':')
+        if len(langs) > 1:
+            dmrc.set('Sugar', 'ExtraLanguages', ';'.join(langs[1:]))
+        else:
+            dmrc.set('Sugar', 'ExtraLanguages', '')
+
+        dmrc_file = file(dmrc_path, 'w')
+        dmrc.write(dmrc_file)
+        dmrc_file.close()
+
+        return
+
     path = os.path.join(os.environ.get('HOME'), '.i18n')
     if not os.access(path, os.W_OK):
         print _standard_msg
@@ -83,6 +107,26 @@ def _write_i18n(lang_env, language_env):
 
 
 def get_languages():
+    dmrc_path = os.path.join(os.environ.get('HOME'), '.dmrc')
+    if os.path.exists(dmrc_path):
+        dmrc = ConfigParser()
+        dmrc.read(dmrc_path)
+
+        langlist = []
+        if dmrc.has_option('Desktop', 'Language'):
+            lang = dmrc.get('Desktop', 'Language')
+            if lang.capitalize() == 'C':
+                lang = _default_lang
+            langlist.append(lang)
+
+        if dmrc.has_option('Sugar', 'ExtraLanguages'):
+            for lang in dmrc.get('Sugar', 'ExtraLanguages').split(';'):
+                lang = lang.strip()
+                if lang:
+                    langlist.append(lang)
+
+        return langlist or [os.environ.get('LANG') or _default_lang]
+
     path = os.path.join(os.environ.get('HOME', ''), '.i18n')
     if not os.access(path, os.R_OK):
         print _standard_msg
-- 
1.7.6.1



More information about the Dextrose mailing list