From f106ad1a8efc3e39c1e818873e53c53aac963faa Mon Sep 17 00:00:00 2001 From: schneefux Date: Mon, 2 Feb 2015 11:53:03 +0100 Subject: first i18n (WIP) --- client/modules/Joke.py | 6 +++--- client/modules/Time.py | 9 +++------ client/modules/Unclear.py | 6 +++--- jasper.py | 10 ++++++++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/client/modules/Joke.py b/client/modules/Joke.py index a260e5a..72a7b8b 100644 --- a/client/modules/Joke.py +++ b/client/modules/Joke.py @@ -3,7 +3,7 @@ import random import re from client import jasperpath -WORDS = ["JOKE", "KNOCK KNOCK"] +WORDS = [_("JOKE"), _("KNOCK KNOCK")] def getRandomJoke(filename=jasperpath.data('text', 'JOKES.txt')): @@ -43,7 +43,7 @@ def handle(text, mic, profile): """ joke = getRandomJoke() - mic.say("Knock knock") + mic.say(_("Knock knock")) def firstLine(text): mic.say(joke[0]) @@ -63,4 +63,4 @@ def isValid(text): Arguments: text -- user-input, typically transcribed speech """ - return bool(re.search(r'\bjoke\b', text, re.IGNORECASE)) + return bool(re.search(r"\b" + _("joke") + r"\b", text, re.IGNORECASE)) diff --git a/client/modules/Time.py b/client/modules/Time.py index 4726839..0d57265 100644 --- a/client/modules/Time.py +++ b/client/modules/Time.py @@ -2,9 +2,8 @@ import datetime import re from client.app_utils import getTimezone -from semantic.dates import DateService -WORDS = ["TIME"] +WORDS = [_("TIME")] def handle(text, mic, profile): @@ -20,9 +19,7 @@ def handle(text, mic, profile): tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) - service = DateService() - response = service.convertTime(now) - mic.say("It is %s right now." % response) + mic.say(_("It is %s right now.") % now.strftime(_("%I %M %p"))) def isValid(text): @@ -32,4 +29,4 @@ def isValid(text): Arguments: text -- user-input, typically transcribed speech """ - return bool(re.search(r'\btime\b', text, re.IGNORECASE)) + return bool(re.search(r"\b" + _("time") + r"\b", text, re.IGNORECASE)) diff --git a/client/modules/Unclear.py b/client/modules/Unclear.py index 071eea3..5701c52 100644 --- a/client/modules/Unclear.py +++ b/client/modules/Unclear.py @@ -18,9 +18,9 @@ def handle(text, mic, profile): number) """ - messages = ["I'm sorry, could you repeat that?", - "My apologies, could you try saying that again?", - "Say that again?", "I beg your pardon?"] + messages = [_("I'm sorry, could you repeat that?"), + _("My apologies, could you try saying that again?"), + _("Say that again?"), _("I beg your pardon?")] message = random.choice(messages) diff --git a/jasper.py b/jasper.py index 908523a..02db89e 100755 --- a/jasper.py +++ b/jasper.py @@ -9,6 +9,12 @@ import logging import yaml import argparse +import locale +import gettext +locale.setlocale(locale.LC_ALL, '') +langs = gettext.translation('messages', localedir='./languages', languages=[]) +langs.install() + from client import tts, stt, jasperpath, diagnose # Add jasperpath.LIB_PATH to sys.path @@ -103,10 +109,10 @@ class Jasper(object): def run(self): if 'first_name' in self.config: - salutation = ("How can I be of service, %s?" + salutation = (_("How can I be of service, %s?") % self.config["first_name"]) else: - salutation = "How can I be of service?" + salutation = _("How can I be of service?") self.mic.say(salutation) conversation = Conversation("JASPER", self.mic, self.config) -- cgit v1.3.1