diff options
Diffstat (limited to 'extensions/cpsection/language')
-rw-r--r-- | extensions/cpsection/language/Makefile.am | 6 | ||||
-rw-r--r-- | extensions/cpsection/language/Makefile.in | 442 | ||||
-rw-r--r-- | extensions/cpsection/language/__init__.py | 21 | ||||
-rw-r--r-- | extensions/cpsection/language/model.py | 164 | ||||
-rw-r--r-- | extensions/cpsection/language/view.py | 281 |
5 files changed, 914 insertions, 0 deletions
diff --git a/extensions/cpsection/language/Makefile.am b/extensions/cpsection/language/Makefile.am new file mode 100644 index 0000000..209fc32 --- /dev/null +++ b/extensions/cpsection/language/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/extensions/cpsection/language + +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py diff --git a/extensions/cpsection/language/Makefile.in b/extensions/cpsection/language/Makefile.in new file mode 100644 index 0000000..9028190 --- /dev/null +++ b/extensions/cpsection/language/Makefile.in @@ -0,0 +1,442 @@ +# Makefile.in generated by automake 1.11.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = extensions/cpsection/language +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(sugar_PYTHON) +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile) +am__installdirs = "$(DESTDIR)$(sugardir)" +py_compile = $(top_srcdir)/py-compile +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GCONFTOOL = @GCONFTOOL@ +GCONF_SCHEMA_CONFIG_SOURCE = @GCONF_SCHEMA_CONFIG_SOURCE@ +GCONF_SCHEMA_FILE_DIR = @GCONF_SCHEMA_FILE_DIR@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ +INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ +INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ +INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGMERGE = @MSGMERGE@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POFILES = @POFILES@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SHELL_CFLAGS = @SHELL_CFLAGS@ +SHELL_LIBS = @SHELL_LIBS@ +STRIP = @STRIP@ +SUCROSE_VERSION = @SUCROSE_VERSION@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +intltool__v_merge_options_ = @intltool__v_merge_options_@ +intltool__v_merge_options_0 = @intltool__v_merge_options_0@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +sugardir = $(pkgdatadir)/extensions/cpsection/language +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign extensions/cpsection/language/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign extensions/cpsection/language/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-sugarPYTHON: $(sugar_PYTHON) + @$(NORMAL_INSTALL) + test -z "$(sugardir)" || $(MKDIR_P) "$(DESTDIR)$(sugardir)" + @list='$(sugar_PYTHON)'; dlist=; list2=; test -n "$(sugardir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then b=; else b="$(srcdir)/"; fi; \ + if test -f $$b$$p; then \ + $(am__strip_dir) \ + dlist="$$dlist $$f"; \ + list2="$$list2 $$b$$p"; \ + else :; fi; \ + done; \ + for file in $$list2; do echo $$file; done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(sugardir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(sugardir)" || exit $$?; \ + done || exit $$?; \ + if test -n "$$dlist"; then \ + $(am__py_compile) --destdir "$(DESTDIR)" \ + --basedir "$(sugardir)" $$dlist; \ + else :; fi + +uninstall-sugarPYTHON: + @$(NORMAL_UNINSTALL) + @list='$(sugar_PYTHON)'; test -n "$(sugardir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + dir='$(DESTDIR)$(sugardir)'; \ + filesc=`echo "$$files" | sed 's|$$|c|'`; \ + fileso=`echo "$$files" | sed 's|$$|o|'`; \ + st=0; \ + for files in "$$files" "$$filesc" "$$fileso"; do \ + $(am__uninstall_files_from_dir) || st=$$?; \ + done; \ + exit $$st +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: + for dir in "$(DESTDIR)$(sugardir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-sugarPYTHON + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-sugarPYTHON + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic distclean \ + distclean-generic distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip install-sugarPYTHON installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \ + uninstall-am uninstall-sugarPYTHON + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/extensions/cpsection/language/__init__.py b/extensions/cpsection/language/__init__.py new file mode 100644 index 0000000..c93b7d1 --- /dev/null +++ b/extensions/cpsection/language/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2008, OLPC +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from gettext import gettext as _ + +CLASS = 'Language' +ICON = 'module-language' +TITLE = _('Language') diff --git a/extensions/cpsection/language/model.py b/extensions/cpsection/language/model.py new file mode 100644 index 0000000..17de6bb --- /dev/null +++ b/extensions/cpsection/language/model.py @@ -0,0 +1,164 @@ +# Copyright (C) 2007, 2008 One Laptop Per Child +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# +# The language config is based on the system-config-language +# (http://fedoraproject.org/wiki/SystemConfig/language) tool +# Parts of the code were reused. +# + +import os +import locale +from gettext import gettext as _ +import subprocess + + +_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) + lines = fdp.stdout.read().split('\n') + locales = [] + + for line in lines: + if line.find('locale:') != -1: + locale = line.split()[1] + elif line.find('language |') != -1: + lang = line.lstrip('language |') + elif line.find('territory |') != -1: + territory = line.lstrip('territory |') + if locale.endswith('utf8') and len(lang): + locales.append((lang, territory, locale)) + + #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')) + locales.append(('Pashto', 'Afghanistan', 'ps_AF.utf8')) + + locales.sort() + return locales + + +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. + return + languages = read_all_languages() + set_languages.__doc__ += '\n' + for lang in languages: + set_languages.__doc__ += '%s \n' % (lang[0].replace(' ', '_') + '/' + + lang[1].replace(' ', '_')) + + +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') + fd.write('LANG="%s"\n' % _default_lang) + fd.write('LANGUAGE="%s"\n' % _default_lang) + fd.close() + else: + fd = open(path, 'w') + 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') + if not os.access(path, os.R_OK): + 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') + lines = fd.readlines() + fd.close() + + langlist = None + + for line in lines: + if line.startswith('LANGUAGE='): + lang = line[9:].replace('"', '') + lang = lang.strip() + langlist = lang.split(':') + elif line.startswith('LANG='): + lang = line[5:].replace('"', '') + + # There might be cases where .i18n may not contain a LANGUAGE field + if langlist == None: + return [lang] + else: + return langlist + + +def print_languages(): + codes = get_languages() + + languages = read_all_languages() + for code in codes: + found_lang = False + for lang in languages: + if lang[2].split('.')[0] == code.split('.')[0]: + print lang[0].replace(' ', '_') + '/' + \ + lang[1].replace(' ', '_') + found_lang = True + break + if not found_lang: + print (_('Language for code=%s could not be determined.') % code) + + +def set_languages(languages): + """Set the system language. + languages : + """ + + if isinstance(languages, list): + set_languages_list(languages) + return + + if languages.endswith('utf8'): + set_languages_list([languages]) + return 1 + else: + 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() diff --git a/extensions/cpsection/language/view.py b/extensions/cpsection/language/view.py new file mode 100644 index 0000000..1553959 --- /dev/null +++ b/extensions/cpsection/language/view.py @@ -0,0 +1,281 @@ +# Copyright (C) 2008, OLPC +# Copyright (C) 2009, Simon Schampijer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk +import gobject +import gettext + +from sugar.graphics import style +from sugar.graphics.icon import Icon + +from jarabe.controlpanel.sectionview import SectionView +from jarabe.controlpanel.inlinealert import InlineAlert + +_translate_language = lambda msg: gettext.dgettext('iso_639', msg) +_translate_country = lambda msg: gettext.dgettext('iso_3166', msg) + +CLASS = 'Language' +ICON = 'module-language' +TITLE = gettext.gettext('Language') + + +class Language(SectionView): + def __init__(self, model, alerts): + SectionView.__init__(self) + + self._model = model + self.restart_alerts = alerts + self._lang_sid = 0 + self._selected_lang_count = 0 + self._labels = [] + self._stores = [] + self._comboboxes = [] + self._add_remove_boxes = [] + self._changed = False + self._cursor_change_handler = None + + self._available_locales = self._model.read_all_languages() + self._selected_locales = self._model.get_languages() + + self.set_border_width(style.DEFAULT_SPACING * 2) + self.set_spacing(style.DEFAULT_SPACING) + + explanation = gettext.gettext('Add languages in the order you prefer.' + ' If a translation is not available,' + ' the next in the list will be used.') + self._text = gtk.Label(explanation) + self._text.set_width_chars(100) + self._text.set_line_wrap(True) + self._text.set_alignment(0, 0) + self.pack_start(self._text, False) + self._text.show() + + scrolled = gtk.ScrolledWindow() + scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scrolled.show() + self.pack_start(scrolled, expand=True) + + self._table = gtk.Table(rows=1, columns=3, homogeneous=False) + self._table.set_border_width(style.DEFAULT_SPACING * 2) + self._table.show() + scrolled.add_with_viewport(self._table) + + self._lang_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) + self.pack_start(self._lang_alert_box, False) + + self._lang_alert = InlineAlert() + self._lang_alert_box.pack_start(self._lang_alert) + if 'lang' in self.restart_alerts: + self._lang_alert.props.msg = self.restart_msg + self._lang_alert.show() + self._lang_alert_box.show() + + self.setup() + + def _add_row(self, locale_code=None): + """Adds a row to the table""" + + self._selected_lang_count += 1 + + self._table.resize(self._selected_lang_count, 3) + + label = gtk.Label(str=str(self._selected_lang_count)) + label.modify_fg(gtk.STATE_NORMAL, + style.COLOR_SELECTION_GREY.get_gdk_color()) + self._labels.append(label) + self._attach_to_table(label, 0, 1, padding=1) + label.show() + + store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) + for language, country, code in self._available_locales: + description = '%s (%s)' % (_translate_language(language), \ + _translate_country(country)) + store.append([code, description]) + + combobox = gtk.ComboBox(model=store) + cell = gtk.CellRendererText() + combobox.pack_start(cell) + combobox.add_attribute(cell, 'text', 1) + + if locale_code: + for row in store: + lang = locale_code.split('.')[0] + lang_column = row[0].split('.')[0] + if lang in lang_column: + combobox.set_active_iter(row.iter) + break + else: + combobox.set_active(1) + + combobox.connect('changed', self.__combobox_changed_cb) + + self._stores.append(store) + self._comboboxes.append(combobox) + self._attach_to_table(combobox, 1, 2, yoptions=gtk.SHRINK) + + add_remove_box = self._create_add_remove_box() + self._add_remove_boxes.append(add_remove_box) + self._attach_to_table(add_remove_box, 2, 3) + + add_remove_box.show_all() + + if self._selected_lang_count > 1: + previous_add_removes = self._add_remove_boxes[-2] + previous_add_removes.hide_all() + + self._determine_add_remove_visibility() + + combobox.show() + + def _attach_to_table(self, widget, row, column, padding=20, \ + yoptions=gtk.FILL): + self._table.attach(widget, row, column, \ + self._selected_lang_count - 1, self._selected_lang_count, \ + xoptions=gtk.FILL, yoptions=yoptions, xpadding=padding, \ + ypadding=padding) + + def _delete_last_row(self): + """Deletes the last row of the table""" + + self._selected_lang_count -= 1 + + label, add_remove_box, combobox, store_ = self._get_last_row() + + label.destroy() + add_remove_box.destroy() + combobox.destroy() + + self._table.resize(self._selected_lang_count, 3) + + self._add_remove_boxes[-1].show_all() + + def _get_last_row(self): + label = self._labels.pop() + add_remove_box = self._add_remove_boxes.pop() + combobox = self._comboboxes.pop() + store = self._stores.pop() + + return label, add_remove_box, combobox, store + + def setup(self): + for locale in self._selected_locales: + self._add_row(locale_code=locale) + + def undo(self): + self._model.undo() + self._lang_alert.hide() + + def _create_add_remove_box(self): + """Creates gtk.Hbox with add/remove buttons""" + add_icon = Icon(icon_name='list-add') + + add_button = gtk.Button() + add_button.set_image(add_icon) + add_button.connect('clicked', + self.__add_button_clicked_cb) + + remove_icon = Icon(icon_name='list-remove') + remove_button = gtk.Button() + remove_button.set_image(remove_icon) + remove_button.connect('clicked', + self.__remove_button_clicked_cb) + + add_remove_box = gtk.HButtonBox() + add_remove_box.set_layout(gtk.BUTTONBOX_START) + add_remove_box.set_spacing(10) + add_remove_box.pack_start(add_button) + add_remove_box.pack_start(remove_button) + + return add_remove_box + + def __add_button_clicked_cb(self, button): + self._add_row() + self._check_change() + + def __remove_button_clicked_cb(self, button): + self._delete_last_row() + self._check_change() + + def __combobox_changed_cb(self, button): + self._check_change() + + def _check_change(self): + selected_langs = self._get_selected_langs() + last_lang = selected_langs[-1] + + self._determine_add_remove_visibility(last_lang=last_lang) + + self._changed = (selected_langs != self._selected_locales) + + if self._changed == False: + # The user reverted back to the original config + self.needs_restart = False + if 'lang' in self.restart_alerts: + self.restart_alerts.remove('lang') + self._lang_alert.hide() + if self._lang_sid: + gobject.source_remove(self._lang_sid) + self._model.undo() + return False + + if self._lang_sid: + gobject.source_remove(self._lang_sid) + self._lang_sid = gobject.timeout_add(self._APPLY_TIMEOUT, + self.__lang_timeout_cb, + selected_langs) + + def _get_selected_langs(self): + new_codes = [] + for combobox in self._comboboxes: + it = combobox.get_active_iter() + model = combobox.get_model() + lang_code = model.get(it, 0)[0] + new_codes.append(lang_code) + + return new_codes + + def _determine_add_remove_visibility(self, last_lang=None): + # We should not let users add fallback languages for English (USA) + # This is because the software is not usually _translated_ into English + # which means that the fallback gets selected automatically + + if last_lang is None: + selected_langs = self._get_selected_langs() + last_lang = selected_langs[-1] + + add_remove_box = self._add_remove_boxes[-1] + buttons = add_remove_box.get_children() + add_button, remove_button = buttons + + if last_lang.startswith('en_US'): + add_button.props.visible = False + else: + add_button.props.visible = True + + if self._selected_lang_count == 1: + remove_button.props.visible = False + else: + remove_button.props.visible = True + + def __lang_timeout_cb(self, codes): + self._lang_sid = 0 + self._model.set_languages_list(codes) + self.restart_alerts.append('lang') + self.needs_restart = True + self._lang_alert.props.msg = self.restart_msg + self._lang_alert.show() + return False |