Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final fixes #32

Open
wants to merge 6 commits into
base: i18n
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions lambda/py/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import requests
import calendar
import gettext
import prompts
from datetime import datetime
from pytz import timezone
from ask_sdk_s3.adapter import S3Adapter
Expand Down Expand Up @@ -46,16 +45,14 @@ def can_handle(self, handler_input):

def handle(self, handler_input):
data = handler_input.attributes_manager.request_attributes["_"]
speech = data[prompts.WELCOME_MSG]
reprompt = data[prompts.WELCOME_REPROMPT_MSG]
speech = data["WELCOME_MSG"]
reprompt = data["WELCOME_REPROMPT_MSG"]

handler_input.response_builder.speak(speech).ask(reprompt)
return handler_input.response_builder.response

class HasBirthdayLaunchRequestHandler(AbstractRequestHandler):
"""
Handler for launch after they have set their birthday
"""
"""Handler for launch after they have set their birthday"""

def can_handle(self, handler_input):
# extract persistent attributes and check if they are all present
Expand All @@ -72,7 +69,7 @@ def handle(self, handler_input):
day = int(attr['day'])

data = handler_input.attributes_manager.request_attributes["_"]
error_timezone_speech = data[prompts.ERROR_TIMEZONE_MSG]
error_timezone_speech = data["ERROR_TIMEZONE_MSG"]

# get skill locale from request
skill_locale = handler_input.request_envelope.request.locale
Expand Down Expand Up @@ -127,35 +124,35 @@ def handle(self, handler_input):
# if it is not the user birthday
if now_date != next_birthday:
if diff_days > 1:
speak_output = data[prompts.WELCOME_BACK_MSG_plural].format(diff_days, current_year-year)
speak_output = data["WELCOME_BACK_MSG_plural"].format(diff_days, current_year-year)
if diff_days < 2:
speak_output = data[prompts.WELCOME_BACK_MSG].format(diff_days, current_year - year)
speak_output = data["WELCOME_BACK_MSG"].format(diff_days, current_year - year)

# if it is the user birthday
else:
if (current_year - year > 1):
speak_output = data[prompts.HAPPY_BIRTHDAY_MSG_plural].format(current_year - year)
speak_output = data["HAPPY_BIRTHDAY_MSG_plural"].format(current_year - year)
if current_year - year < 2:
speak_output = data[prompts.HAPPY_BIRTHDAY_MSG].format(current_year - year)
speak_output = data["HAPPY_BIRTHDAY_MSG"].format(current_year - year)

# all other locales
else:
speak_output = data[prompts.HAPPY_BIRTHDAY_MSG].format(current_year - year)
speak_output = data["HAPPY_BIRTHDAY_MSG"].format(current_year - year)

# if it is not the user birthday
if now_date != next_birthday:
if diff_days > 1:
# for ja and hi, the order of the slots is inverted, i.e. year before day
if ('ja' in skill_locale or 'hi' in skill_locale):
speak_output = data[prompts.WELCOME_BACK_MSG_plural].format(current_year-year, diff_days)
speak_output = data["WELCOME_BACK_MSG_plural"].format(current_year-year, diff_days)
else:
speak_output = data[prompts.WELCOME_BACK_MSG_plural].format(diff_days, current_year-year)
speak_output = data["WELCOME_BACK_MSG_plural"].format(diff_days, current_year-year)
elif diff_days < 2:
# for ja and hi, the order of the slots is inverted, i.e. year before day
if ('ja' in skill_locale or 'hi' in skill_locale):
speak_output = data[prompts.WELCOME_BACK_MSG].format(current_year - year, diff_days)
speak_output = data["WELCOME_BACK_MSG"].format(current_year - year, diff_days)
else:
speak_output = data[prompts.WELCOME_BACK_MSG].format(diff_days, current_year - year)
speak_output = data["WELCOME_BACK_MSG"].format(diff_days, current_year - year)

return (
handler_input.response_builder
Expand All @@ -164,7 +161,6 @@ def handle(self, handler_input):
.response
)


class BirthdayIntentHandler(AbstractRequestHandler):
"""
Handler for Capturing the Birthday
Expand Down Expand Up @@ -206,8 +202,9 @@ def handle(self, handler_input):
# ensure that the order the arguments is correct (MM/DD/YYYY or DD/MM/YYYY) according to locale
date = self.formatDate(year, month, day, skill_locale)

speech = data[prompts.REGISTER_BIRTHDAY_MSG].format(date[0], date[1], date[2])
speech = data["REGISTER_BIRTHDAY_MSG"].format(date[0], date[1], date[2])
handler_input.response_builder.speak(speech)
handler_input.response_builder.set_should_end_session(True)
return handler_input.response_builder.response

# function to ensure that the date format corresponds with the locale that is triggering thee skill
Expand Down Expand Up @@ -242,7 +239,7 @@ def handle(self, handler_input):
# type: (HandlerInput) -> Response

data = handler_input.attributes_manager.request_attributes["_"]
speak_output = data[prompts.HELP_MSG]
speak_output = data["HELP_MSG"]

return (
handler_input.response_builder
Expand All @@ -262,7 +259,7 @@ def can_handle(self, handler_input):
def handle(self, handler_input):
# type: (HandlerInput) -> Response
data = handler_input.attributes_manager.request_attributes["_"]
speak_output = data[prompts.GOODBYE_MSG]
speak_output = data["GOODBYE_MSG"]

return (
handler_input.response_builder
Expand Down Expand Up @@ -299,7 +296,7 @@ def handle(self, handler_input):
# type: (HandlerInput) -> Response
data = handler_input.attributes_manager.request_attributes["_"]
intent_name = ask_utils.get_intent_name(handler_input)
speak_output = data[prompts.REFLECTOR_MSG].format(intent_name)
speak_output = data["REFLECTOR_MSG"].format(intent_name)

return (
handler_input.response_builder
Expand All @@ -322,7 +319,7 @@ def handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> Response
logger.error(exception, exc_info=True)
data = handler_input.attributes_manager.request_attributes["_"]
speak_output = data[prompts.ERROR_MSG]
speak_output = data["ERROR_MSG"]

return (
handler_input.response_builder
Expand Down
4 changes: 4 additions & 0 deletions lambda/py/requirements.txt~HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ask-sdk-core
ask-sdk-s3-persistence-adapter
boto3
pytz
4 changes: 4 additions & 0 deletions lambda/py/requirements.txt~Simplifying Localization
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ask-sdk-core
ask-sdk-s3-persistence-adapter
boto3
pytz
52 changes: 26 additions & 26 deletions skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@
"manifest": {
"publishingInformation": {
"locales": {
"en-US": {
"name": "cake walk"
"de-DE": {
"name": "Herzlichen Glückwunsch"
},
"en-AU": {
"name": "cake walk"
"name": "Cake Walk"
},
"en-CA": {
"name": "cake walk"
"name": "Cake Walk"
},
"en-GB": {
"name": "cake walk"
"name": "Cake Walk"
},
"en-IN": {
"name": "cake walk"
"name": "Cake Walk"
},
"pt-BR": {
"name": "feliz aniversário"
"en-US": {
"name": "Cake Walk"
},
"it-IT": {
"name": "buon compleanno"
"es-ES": {
"name": "Feliz Cumpleaños"
},
"es-MX": {
"name": "Feliz Cumpleaños"
},
"es-US": {
"name": "Feliz Cumpleaños"
},
"fr-FR": {
"name": "Joyeux Anniversaire"
},
"fr-CA": {
"name": "Bonne Fête"
},
"fr-FR": {
"name": "Joyeux Anniversaire"
},
"hi-IN": {
"name": "cake walk"
"name": "Cake Walk"
},
"it-IT": {
"name": "Buon Compleanno"
},
"ja-JP": {
"name": "ケークウォーク"
},
"de-DE": {
"name": "Herzlichen Glückwunsch"
},
"es-ES": {
"name": "feliz cumpleaños"
},
"es-MX": {
"name": "feliz cumpleaños"
},
"es-US": {
"name": "feliz cumpleaños"
"pt-BR": {
"name": "Feliz Aniversário"
}
},
},
"isAvailableWorldwide": true,
"testingInstructions": "Sample Testing Instructions.",
"category": "EDUCATION_AND_REFERENCE",
Expand Down