Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make the example plugin use generic languages

The example plugin now uses generic languages instead of region specific
ones. It also uses a new function in languageutils to test what language
it should reply in.
  • Loading branch information...
commit f83fdfa869c7366963879defcee90a9b555a2d84 1 parent bec960f
Theo Spears authored
View
12 PluginManager.py
@@ -4,6 +4,7 @@
import logging
import os
import re
+import languageutils
@@ -111,18 +112,9 @@ def searchPrioritizedPlugin(assistantId, speech, languages):
return (pluginObj, method, match)
return (None, None, None)
-def getLanguageCodes(language):
- languages = list()
- while True:
- languages.append(language)
- if '-' not in language:
- break
- language = re.sub('-[^-]*$', '', language)
- return languages
-
def getPluginForImmediateExecution(assistantId, speech, language, otherPluginParams):
(sendObj, sendPlist, assistant, location) = otherPluginParams
- languages = getLanguageCodes(language)
+ languages = languageutils.getCompatibleCodes(language)
(pluginObj, method, match) = searchPrioritizedPlugin(assistantId, speech, languages)
if pluginObj == None and method == None:
View
13 languageutils.py
@@ -0,0 +1,13 @@
+import re
+
+def getCompatibleCodes(language):
+ languages = list()
+ while True:
+ languages.append(language)
+ if '-' not in language:
+ break
+ language = re.sub('-[^-]*$', '', language)
+ return languages
+
+def matches(baseLanguage, specificLanguage):
+ return baseLanguage in getCompatibleCodes(specificLanguage)
View
27 plugins/examplePlugin/__init__.py
@@ -5,37 +5,38 @@
from plugin import *
from siriObjects.systemObjects import ResultCallback
import uuid
+import languageutils
class examplePlugin(Plugin):
- @register("de-DE", ".*Sinn.*Leben.*")
- @register("en-US", ".*Meaning.*Life.*")
+ @register("de", ".*Sinn.*Leben.*")
+ @register("en", ".*Meaning.*Life.*")
def meaningOfLife(self, speech, language, matchedRegex):
- if language == 'de-DE':
+ if languageutils.matches('de', language):
answer = self.ask(u"Willst du das wirklich wissen?")
self.say(u"Du hast \"{0}\" gesagt!".format(answer))
else:
self.say("I shouldn't tell you!")
self.complete_request()
- @register("de-DE", "(.*Hallo.*)|(.*Hi.*Siri.*)|(Hi)|(Hey)")
- @register("en-US", "(.*Hello.*)|(.*Hi.*Siri.*)|(Hi)|(Hey)")
- @register("fr-FR", ".*(Bonjour|Coucou|Salut)( Siri)?.*")
- @register("nl-NL", ".*(Hallo|Goeiedag|Heey)( Siri)?.*")
+ @register("de", "(.*Hallo.*)|(.*Hi.*Siri.*)|(Hi)|(Hey)")
+ @register("en", "(.*Hello.*)|(.*Hi.*Siri.*)|(Hi)|(Hey)")
+ @register("fr", ".*(Bonjour|Coucou|Salut)( Siri)?.*")
+ @register("nl", ".*(Hallo|Goeiedag|Heey)( Siri)?.*")
def st_hello(self, speech, language):
- if language == 'de-DE':
+ if languageutils.matches('de', language):
self.say(u"Hallo {0}!".format(self.user_name()))
- elif language == 'fr-FR':
+ elif languageutils.matches('fr', language):
self.say(u"Bonjour {0}!".format(self.user_name()));
- elif language == 'nl-NL':
+ elif languageutils.matches('nl', language):
self.say(u"Hallo, {0}!".format(self.user_name()));
else:
self.say(u"Greetings, {0}!".format(self.user_name()))
self.complete_request()
- @register("de-DE", ".*standort.*test.*")
- @register("en-US", ".*location.*test.*")
- @register("nl-NL", ".*locatie.*test.*")
+ @register("de", ".*standort.*test.*")
+ @register("en", ".*location.*test.*")
+ @register("nl", ".*locatie.*test.*")
def locationTest(self, speech, language):
location = self.getCurrentLocation(force_reload=True)
self.say(u"lat: {0}, long: {1}".format(location.latitude, location.longitude))
Please sign in to comment.
Something went wrong with that request. Please try again.