Skip to content

Commit 9378208

Browse files
authored
Merge pull request alexa-samples#21 from bbezerra82/fixDateFormat
Fix date format
2 parents 7e4c9e3 + e00bacb commit 9378208

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎i18n/lambda_function.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def can_handle(self, handler_input):
147147
def handle(self, handler_input):
148148
_ = handler_input.attributes_manager.request_attributes["_"]
149149
slots = handler_input.request_envelope.request.intent.slots
150+
locale = handler_input.request_envelope.request.locale
150151

151152
# extract slot values
152153
year = slots["year"].value
@@ -163,10 +164,25 @@ def handle(self, handler_input):
163164
handler_input.attributes_manager.persistent_attributes = session_attr
164165
handler_input.attributes_manager.save_persistent_attributes()
165166

166-
speech = _(data.REGISTER_BIRTHDAY_MSG).format(month, day, year)
167+
date = self.formatDate(year, month, day, locale)
168+
169+
speech = _(data.REGISTER_BIRTHDAY_MSG).format(date[0], date[1], date[2])
167170
handler_input.response_builder.speak(speech)
168171
return handler_input.response_builder.response
169172

173+
# function to ensure that the date format corresponds with the locale that is triggering thee skill
174+
def formatDate(self, year, month, day, locale):
175+
if locale == 'en-US':
176+
date = [month, day, year]
177+
elif locale == 'jp-JP':
178+
date = [year, month, day]
179+
else:
180+
date = [day, month, year]
181+
182+
return date
183+
184+
185+
170186

171187
class HelpIntentHandler(AbstractRequestHandler):
172188
"""

0 commit comments

Comments
 (0)