Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-12-13 21:29:20 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-12-13 21:29:20 (GMT)
commita3f9915b28e83a8c95faf685494088ab6a097054 (patch)
tree1a1a50e9dac5611170965b417fc0d6a79001d664
parent52c14d37d047c048862eda8ae53017289dafd44b (diff)
add i18n support for sample projects (Jorge Alberto Gómez López)
-rw-r--r--data/en/graphics/bounce (renamed from data/graphics/bounce)0
-rw-r--r--data/en/graphics/camera (renamed from data/graphics/camera)0
-rw-r--r--data/en/graphics/jump (renamed from data/graphics/jump)0
-rw-r--r--data/en/graphics/life (renamed from data/graphics/life)0
-rw-r--r--data/en/graphics/lines (renamed from data/graphics/lines)0
-rw-r--r--data/en/graphics/physics (renamed from data/graphics/physics)0
-rw-r--r--data/en/graphics/pong (renamed from data/graphics/pong)0
-rw-r--r--data/en/graphics/snow (renamed from data/graphics/snow)0
-rw-r--r--data/en/graphics/tree (renamed from data/graphics/tree)0
-rw-r--r--data/en/math/factorial (renamed from data/math/factorial)0
-rw-r--r--data/en/math/fibonacci (renamed from data/math/fibonacci)0
-rw-r--r--data/en/math/guess (renamed from data/math/guess)0
-rw-r--r--data/en/math/pascal (renamed from data/math/pascal)0
-rw-r--r--data/en/math/pi (renamed from data/math/pi)0
-rw-r--r--data/en/math/sierpinski (renamed from data/math/sierpinski)0
-rw-r--r--data/en/math/stern-brocot (renamed from data/math/stern-brocot)0
-rw-r--r--data/en/math/times (renamed from data/math/times)0
-rw-r--r--data/en/python/function (renamed from data/python/function)0
-rw-r--r--data/en/python/if (renamed from data/python/if)0
-rw-r--r--data/en/python/interpreter (renamed from data/python/interpreter)0
-rw-r--r--data/en/python/recursion (renamed from data/python/recursion)0
-rw-r--r--data/en/sound/getSoundList (renamed from data/sound/getSoundList)0
-rw-r--r--data/en/sound/playSine (renamed from data/sound/playSine)0
-rw-r--r--data/en/sound/playWave (renamed from data/sound/playWave)0
-rw-r--r--data/en/sound/sequence (renamed from data/sound/sequence)0
-rw-r--r--data/en/string/hello (renamed from data/string/hello)0
-rw-r--r--data/en/string/jeringoso (renamed from data/string/jeringoso)0
-rw-r--r--data/en/string/thanks (renamed from data/string/thanks)0
-rw-r--r--pippy_app.py82
29 files changed, 70 insertions, 12 deletions
diff --git a/data/graphics/bounce b/data/en/graphics/bounce
index 74b87dd..74b87dd 100644
--- a/data/graphics/bounce
+++ b/data/en/graphics/bounce
diff --git a/data/graphics/camera b/data/en/graphics/camera
index 66d3d50..66d3d50 100644
--- a/data/graphics/camera
+++ b/data/en/graphics/camera
diff --git a/data/graphics/jump b/data/en/graphics/jump
index 7e4d433..7e4d433 100644
--- a/data/graphics/jump
+++ b/data/en/graphics/jump
diff --git a/data/graphics/life b/data/en/graphics/life
index c6d79cb..c6d79cb 100644
--- a/data/graphics/life
+++ b/data/en/graphics/life
diff --git a/data/graphics/lines b/data/en/graphics/lines
index 16db9d6..16db9d6 100644
--- a/data/graphics/lines
+++ b/data/en/graphics/lines
diff --git a/data/graphics/physics b/data/en/graphics/physics
index 08aa696..08aa696 100644
--- a/data/graphics/physics
+++ b/data/en/graphics/physics
diff --git a/data/graphics/pong b/data/en/graphics/pong
index bd2f75f..bd2f75f 100644
--- a/data/graphics/pong
+++ b/data/en/graphics/pong
diff --git a/data/graphics/snow b/data/en/graphics/snow
index e1b2df1..e1b2df1 100644
--- a/data/graphics/snow
+++ b/data/en/graphics/snow
diff --git a/data/graphics/tree b/data/en/graphics/tree
index adc179f..adc179f 100644
--- a/data/graphics/tree
+++ b/data/en/graphics/tree
diff --git a/data/math/factorial b/data/en/math/factorial
index 95d0cd4..95d0cd4 100644
--- a/data/math/factorial
+++ b/data/en/math/factorial
diff --git a/data/math/fibonacci b/data/en/math/fibonacci
index 6cef209..6cef209 100644
--- a/data/math/fibonacci
+++ b/data/en/math/fibonacci
diff --git a/data/math/guess b/data/en/math/guess
index 14c6539..14c6539 100644
--- a/data/math/guess
+++ b/data/en/math/guess
diff --git a/data/math/pascal b/data/en/math/pascal
index 06fab84..06fab84 100644
--- a/data/math/pascal
+++ b/data/en/math/pascal
diff --git a/data/math/pi b/data/en/math/pi
index 747f7ca..747f7ca 100644
--- a/data/math/pi
+++ b/data/en/math/pi
diff --git a/data/math/sierpinski b/data/en/math/sierpinski
index 1c0b89e..1c0b89e 100644
--- a/data/math/sierpinski
+++ b/data/en/math/sierpinski
diff --git a/data/math/stern-brocot b/data/en/math/stern-brocot
index 9ece0f7..9ece0f7 100644
--- a/data/math/stern-brocot
+++ b/data/en/math/stern-brocot
diff --git a/data/math/times b/data/en/math/times
index 4757a4a..4757a4a 100644
--- a/data/math/times
+++ b/data/en/math/times
diff --git a/data/python/function b/data/en/python/function
index 2149c67..2149c67 100644
--- a/data/python/function
+++ b/data/en/python/function
diff --git a/data/python/if b/data/en/python/if
index 0e4b947..0e4b947 100644
--- a/data/python/if
+++ b/data/en/python/if
diff --git a/data/python/interpreter b/data/en/python/interpreter
index 535aaca..535aaca 100644
--- a/data/python/interpreter
+++ b/data/en/python/interpreter
diff --git a/data/python/recursion b/data/en/python/recursion
index bf8cd53..bf8cd53 100644
--- a/data/python/recursion
+++ b/data/en/python/recursion
diff --git a/data/sound/getSoundList b/data/en/sound/getSoundList
index 85fe06f..85fe06f 100644
--- a/data/sound/getSoundList
+++ b/data/en/sound/getSoundList
diff --git a/data/sound/playSine b/data/en/sound/playSine
index c17e169..c17e169 100644
--- a/data/sound/playSine
+++ b/data/en/sound/playSine
diff --git a/data/sound/playWave b/data/en/sound/playWave
index ee86aa6..ee86aa6 100644
--- a/data/sound/playWave
+++ b/data/en/sound/playWave
diff --git a/data/sound/sequence b/data/en/sound/sequence
index 06eac36..06eac36 100644
--- a/data/sound/sequence
+++ b/data/en/sound/sequence
diff --git a/data/string/hello b/data/en/string/hello
index bb52fc2..bb52fc2 100644
--- a/data/string/hello
+++ b/data/en/string/hello
diff --git a/data/string/jeringoso b/data/en/string/jeringoso
index e24c069..e24c069 100644
--- a/data/string/jeringoso
+++ b/data/en/string/jeringoso
diff --git a/data/string/thanks b/data/en/string/thanks
index 48d6d95..48d6d95 100644
--- a/data/string/thanks
+++ b/data/en/string/thanks
diff --git a/pippy_app.py b/pippy_app.py
index ce8fa46..cb5de56 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -25,6 +25,7 @@ import os
import time
import subprocess
from random import uniform
+import locale
from gi.repository import Gtk
from gi.repository import Gdk
@@ -56,11 +57,14 @@ import groupthink.gtk_tools
from FileDialog import FileDialog
+_default_lang = '%s.%s' % locale.getdefaultlocale()
text_buffer = None
# magic prefix to use utf-8 source encoding
PYTHON_PREFIX = """#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
+default_categoties = [_('Graphics'), _('Math'), _('Pyhton'), _('Sound'),
+ _('String')]
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.toolbarbox import ToolbarButton
@@ -203,11 +207,37 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
self.paths = []
root = os.path.join(get_bundle_path(), 'data')
- for d in sorted(os.listdir(root)):
- if not os.path.isdir(os.path.join(root, d)):
- continue # skip non-dirs
- direntry = {"name": _(d.capitalize()),
- "path": os.path.join(root, d) + "/"}
+
+ # get preferred language and default one
+ self.pref_lang = self.get_languages()[0].split("_")[0]
+ self.default_lang = _default_lang.split("_")[0]
+
+ # construct the path for both
+ self.lang_path = os.path.join(root, self.pref_lang)
+ self.default_path = os.path.join(root, self.default_lang)
+
+ # get all folders in lang examples
+ self.all_folders = []
+ if os.path.exists(self.lang_path):
+ for d in sorted(os.listdir(self.lang_path)):
+ self.all_folders.append(d)
+
+ # get all folders in english examples
+ for d in sorted(os.listdir(self.default_path)):
+ # check if folder isn't already in list
+ if d not in self.all_folders:
+ self.all_folders.append(d)
+
+ for folder in self.all_folders:
+ direntry = {}
+ # check if dir exists in pref language, if exists, add it
+ if os.path.exists(os.path.join(self.lang_path, folder)):
+ direntry = {"name": _(folder.capitalize()),
+ "path": os.path.join(self.lang_path, folder) + "/"}
+ # if not try to see if it's in default english path
+ elif os.path.exists(os.path.join(self.default_path, folder)):
+ direntry = {"name": _(folder.capitalize()),
+ "path": os.path.join(self.default_path, folder) + "/"}
self.paths.append([direntry['name'], direntry['path']])
# Adding local examples
@@ -295,6 +325,36 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
def after_init(self):
self.outbox.hide()
+ def get_languages(self):
+ path = os.path.join(os.environ.get('HOME', ''), '.i18n')
+ if not os.access(path, os.R_OK):
+ logging.debug('Could not access ~/.i18n')
+ 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 is None:
+ return [lang]
+ else:
+ return langlist
+
def _toggle_output_cb(self, button):
shown = button.get_active()
if shown:
@@ -346,9 +406,9 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
if text_buffer.get_modified():
from sugar3.graphics.alert import ConfirmationAlert
alert = ConfirmationAlert()
- alert.props.title = _('Example selection Warning')
- alert.props.msg = _('You have modified the currently selected file. \
-Discard changes?')
+ alert.props.title = _('Example-selection Warning')
+ alert.props.msg = _('You have modified the currently selected \
+file. Discard changes?')
alert.connect('response', self._discard_changes_cb, path)
self.add_alert(alert)
return False
@@ -419,13 +479,11 @@ Discard changes?')
def __copybutton_cb(self, button):
global text_buffer
- clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
- text_buffer.copy_clipboard(clipboard)
+ text_buffer.copy_clipboard(Gtk.Clipboard())
def __pastebutton_cb(self, button):
global text_buffer
- clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
- text_buffer.paste_clipboard(clipboard, None, True)
+ text_buffer.paste_clipboard(Gtk.Clipboard(), None, True)
def gobutton_cb(self, button):
from shutil import copy2