Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/language/model.py
diff options
context:
space:
mode:
authorSascha Silbe <silbe@activitycentral.com>2011-03-12 17:44:09 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-03-12 17:44:09 (GMT)
commitdb56ac4562a9ab10308de0998b56262956f51b64 (patch)
treee9ea3923a6203538480822593354146c01d1341b /extensions/cpsection/language/model.py
parent8cd75e783fec952497eda68ae06e00323a4c179b (diff)
parentff47b24c5aa032f830c6f3dc3ae32dfed3c72229 (diff)
Merge commit 'refs/top-bases/t/bug-1755' into t/bug-1755t/bug-1755
* commit 'refs/top-bases/t/bug-1755': (261 commits) Fix up style issues introduced by commit 3f8a1e1 Don't set default timezone Restore setting a language with the command line OLPC #10681 battery frame device: replace HAL with UPower use ConsoleKit instead of HAL for shutdown/reboot fix recognition of JEBs outside of data store Adjust the year in the licence visible in the control panel Handle activities that cycle through windows dlo#10695 Speaker frame device: pop up palette on left-click instead of toggling mute recognise translations using pgettext Remove last few pieces of buddy-icon.jpg handling fix whitespace error introduced by 4b6a534 (revert of 4a3416b) Commit from Sugar Labs: Translation System by user RafaelOrtiz.: 374 of 374 messages translated (0 fuzzy). Intro: Fall back to user name if GECOS real name field is empty Sugar Ad-hoc icons show in search results when connect/disconnect to AP OLPC #10412 Show busy cursor during session shutdown Show free space for the Journal in the Journal volumes toolbar (SL#2318) Fix incorrect logging level for warning about missing GSM configuration simplify extension loading exception error Revert "Add cpu and memory resource indicator to frame" as agreed on with erikos. Scheduling for inclusion in 0.94 after potential artwork changes based on feedback from the Design Team. ... Conflicts: src/jarabe/util/emulator.py
Diffstat (limited to 'extensions/cpsection/language/model.py')
-rw-r--r--extensions/cpsection/language/model.py86
1 files changed, 48 insertions, 38 deletions
diff --git a/extensions/cpsection/language/model.py b/extensions/cpsection/language/model.py
index fe80410..240e562 100644
--- a/extensions/cpsection/language/model.py
+++ b/extensions/cpsection/language/model.py
@@ -21,11 +21,14 @@
#
import os
+import locale
from gettext import gettext as _
import subprocess
-_default_lang = 'en_US.utf8'
-_standard_msg = _("Could not access ~/.i18n. Create standard settings.")
+
+_default_lang = '%s.%s' % locale.getdefaultlocale()
+_standard_msg = _('Could not access ~/.i18n. Create standard settings.')
+
def read_all_languages():
fdp = subprocess.Popen(['locale', '-av'], stdout=subprocess.PIPE)
@@ -42,7 +45,7 @@ def read_all_languages():
if locale.endswith('utf8') and len(lang):
locales.append((lang, territory, locale))
- #FIXME: This is a temporary workaround for locales that are essential to
+ #FIXME: This is a temporary workaround for locales that are essential to
# OLPC, but are not in Glibc yet.
locales.append(('Kreyol', 'Haiti', 'ht_HT.utf8'))
locales.append(('Dari', 'Afghanistan', 'fa_AF.utf8'))
@@ -51,7 +54,8 @@ def read_all_languages():
locales.sort()
return locales
-def _initialize():
+
+def _initialize():
if set_languages.__doc__ is None:
# when running under 'python -OO', all __doc__ fields are None,
# so += would fail -- and this function would be unnecessary anyway.
@@ -59,13 +63,12 @@ def _initialize():
languages = read_all_languages()
set_languages.__doc__ += '\n'
for lang in languages:
- set_languages.__doc__ += '%s \n' % (lang[0].replace(' ', '_') + '/' +
+ set_languages.__doc__ += '%s \n' % (lang[0].replace(' ', '_') + '/' +
lang[1].replace(' ', '_'))
-
-def _write_i18n(langs):
- colon = ':'
- langstr = colon.join(langs)
- path = os.path.join(os.environ.get("HOME"), '.i18n')
+
+
+def _write_i18n(lang_env, language_env):
+ path = os.path.join(os.environ.get('HOME'), '.i18n')
if not os.access(path, os.W_OK):
print _standard_msg
fd = open(path, 'w')
@@ -74,32 +77,33 @@ def _write_i18n(langs):
fd.close()
else:
fd = open(path, 'w')
- fd.write('LANG="%s"\n' % langs[0].strip("\n"))
- fd.write('LANGUAGE="%s"\n' % langstr)
+ fd.write('LANG="%s"\n' % lang_env)
+ fd.write('LANGUAGE="%s"\n' % language_env)
fd.close()
+
def get_languages():
- path = os.path.join(os.environ.get("HOME"), '.i18n')
+ path = os.path.join(os.environ.get('HOME', ''), '.i18n')
if not os.access(path, os.R_OK):
- print _standard_msg
+ print _standard_msg
fd = open(path, 'w')
fd.write('LANG="%s"\n' % _default_lang)
fd.write('LANGUAGE="%s"\n' % _default_lang)
fd.close()
return [_default_lang]
-
- fd = open(path, "r")
+
+ fd = open(path, 'r')
lines = fd.readlines()
fd.close()
langlist = None
for line in lines:
- if line.startswith("LANGUAGE="):
+ if line.startswith('LANGUAGE='):
lang = line[9:].replace('"', '')
lang = lang.strip()
langlist = lang.split(':')
- elif line.startswith("LANG="):
+ elif line.startswith('LANG='):
lang = line[5:].replace('"', '')
# There might be cases where .i18n may not contain a LANGUAGE field
@@ -108,6 +112,7 @@ def get_languages():
else:
return langlist
+
def print_languages():
codes = get_languages()
@@ -121,30 +126,35 @@ def print_languages():
found_lang = True
break
if not found_lang:
- print (_("Language for code=%s could not be determined.") % code)
-
+ print (_('Language for code=%s could not be determined.') % code)
+
+
def set_languages(languages):
"""Set the system language.
- languages :
+ languages :
"""
- if isinstance(languages, str):
- # This came from the commandline
- #TODO: Support multiple languages from the command line
- if languages.endswith('utf8'):
- _write_i18n(languages)
- return 1
- else:
- langs = read_all_languages()
- for lang, territory, locale in langs:
- code = lang.replace(' ', '_') + '/' \
- + territory.replace(' ', '_')
- if code == languages:
- _write_i18n(locale)
- return 1
- print (_("Sorry I do not speak \'%s\'.") % languages)
+
+ if languages.endswith('utf8'):
+ set_languages_list([languages])
+ return 1
else:
- _write_i18n(languages)
+ langs = read_all_languages()
+ for lang, territory, locale in langs:
+ code = lang.replace(' ', '_') + '/' \
+ + territory.replace(' ', '_')
+ if code == languages:
+ set_languages_list([locale])
+ return 1
+ print (_("Sorry I do not speak \'%s\'.") % languages)
+
+
+def set_languages_list(languages):
+ """Set the system language using a list of preferred languages"""
+ colon = ':'
+ language_env = colon.join(languages)
+ lang_env = languages[0].strip('\n')
+ _write_i18n(lang_env, language_env)
+
# inilialize the docstrings for the language
_initialize()
-