diff --git a/lib/api/alexa/index.js b/lib/api/alexa/index.js index ff233a53de0..ad1413b0980 100644 --- a/lib/api/alexa/index.js +++ b/lib/api/alexa/index.js @@ -7,8 +7,8 @@ var _ = require('lodash'); function configure (app, wares, ctx, env) { var entries = ctx.entries; var express = require('express') - , api = express.Router( ) - ; + , api = express.Router( ); + var translate = ctx.language.translate; // invoke common middleware api.use(wares.sendJSONStatus); @@ -43,7 +43,16 @@ function configure (app, wares, ctx, env) { }); api.post('/alexa', ctx.authorization.isPermitted('api:*:read'), function (req, res, next) { - console.log('Incoming request from Alexa'); + console.log('Incoming request from Alexa'); + var locale = req.body.request.locale; + if(locale){ + if(locale.length > 2) { + locale = locale.substr(0, 2); + } + ctx.language.set(locale); + moment.locale(locale); + } + switch (req.body.request.type) { case 'IntentRequest': onIntent(req.body.request.intent, function (title, response) { @@ -67,57 +76,48 @@ function configure (app, wares, ctx, env) { }); ctx.alexa.addToRollup('Status', function bgRollupHandler(slots, sbx, callback) { - entries.list({count: 1}, function(err, records) { - var direction = ''; - if (records[0].direction === 'FortyFiveDown') { - direction = ' and slightly dropping'; - } else if (records[0].direction === 'FortyFiveUp') { - direction = ' and slightly rising'; - } else if (records[0].direction === 'Flat') { - direction = ' and holding'; - } else if (records[0].direction === 'SingleUp') { - direction = ' and rising'; - } else if (records[0].direction === 'SingleDown') { - direction = ' and dropping'; - } else if (records[0].direction === 'DoubleDown') { - direction = ' and rapidly dropping'; - } else if (records[0].direction === 'DoubleUp') { - direction = ' and rapidly rising'; + entries.list({count: 1}, function (err, records) { + var direction; + if (translate(records[0].direction)) { + direction = translate(records[0].direction); } else { direction = records[0].direction; } - var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)) + '.'; + var status = translate('alexaStatus', { + params: [ + sbx.scaleMgdl(records[0].sgv), + direction, + moment(records[0].date).from(moment(sbx.time)) + ] + }); + //var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)) + '.'; callback(null, {results: status, priority: -1}); }); // console.log('BG results called'); // callback(null, 'BG results'); }, 'BG Status'); - ctx.alexa.configureIntentHandler('MetricNow', function (callback, slots, sbx) { + ctx.alexa.configureIntentHandler('MetricNow', function ( callback, slots, sbx, locale) { entries.list({count: 1}, function(err, records) { - var direction = ''; - if (records[0].direction === 'FortyFiveDown') { - direction = ' and slightly dropping'; - } else if (records[0].direction === 'FortyFiveUp') { - direction = ' and slightly rising'; - } else if (records[0].direction === 'Flat') { - direction = ' and holding'; - } else if (records[0].direction === 'SingleUp') { - direction = ' and rising'; - } else if (records[0].direction === 'SingleDown') { - direction = ' and dropping'; - } else if (records[0].direction === 'DoubleDown') { - direction = ' and rapidly dropping'; - } else if (records[0].direction === 'DoubleUp') { - direction = ' and rapidly rising'; + var direction; + if(translate(records[0].direction)){ + direction = translate(records[0].direction); + } else { + direction = records[0].direction; } - var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)); + var status = translate('alexaStatus', { + params: [ + sbx.scaleMgdl(records[0].sgv), + direction, + moment(records[0].date).from(moment(sbx.time))] + }); + //var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)); callback('Current blood glucose', status); }); }, 'metric', ['bg', 'blood glucose', 'number']); - ctx.alexa.configureIntentHandler('NSStatus', function(callback, slots, sbx) { - ctx.alexa.getRollup('Status', sbx, slots, function (status) { + ctx.alexa.configureIntentHandler('NSStatus', function(callback, slots, sbx, locale) { + ctx.alexa.getRollup('Status', sbx, slots, locale, function (status) { callback('Full status', status); }); }); diff --git a/lib/language.js b/lib/language.js index ea46e0fc7d7..263529f5bad 100644 --- a/lib/language.js +++ b/lib/language.js @@ -9294,7 +9294,7 @@ function init() { ,fi: 'Tarkista VS, aika bolustaa?' ,pt: 'Meça a glicemia, hora de bolus de correção?' ,sk: 'Skontrolovať glykémiu, čas na bolus?' - ,it: 'Controllare BG, il tempo del bolo?' + ,it: 'Controllare BG, il tempo del bolo?' ,nl: 'Controleer BG, tijd om te bolussen?' ,zh_cn: '测量血糖,该输注大剂量了?' } @@ -9398,7 +9398,7 @@ function init() { ,ro: 'Insulină în exces: %1U mai mult decât este necesar pentru a atinge ținta inferioară, fără a ține cont de carbohidrați' ,bg: 'Излишният инсулин %1U е повече от необходимия за достигане до долната граница, ВХ не се вземат под внимание' ,ru: 'Избыток инсулина равного %1U, необходимого для достижения нижнего целевого значения, углеводы не будут учтены' - ,sv: 'Överskott av insulin motsvarande %1U mer än nödvändigt för att nå lågt målvärde, kolhydrater ej medräknade' + ,sv: 'Överskott av insulin motsvarande %1U mer än nödvändigt för att nå lågt målvärde, kolhydrater ej medräknade' ,nb: 'Insulin tilsvarende %1U mer enn det trengs for å nå lavt mål, karbohydrater ikke medregnet' ,fi: 'Liikaa insuliinia: %1U enemmän kuin tarvitaan tavoitteeseen pääsyyn (huomioimatta hiilihydraatteja)' ,pt: 'Excesso de insulina equivalente a %1U além do necessário para atingir a meta inferior, sem levar em conta carboidratos' @@ -9934,9 +9934,9 @@ function init() { ,sv: '%1d sedan' ,nb: '%1d siden' ,fi: '%1d sitten' - ,pt: '%1d atrás' + ,pt: '%1d atrás' ,sk: 'pred %1d' - ,it: '%1d fa' + ,it: '%1d fa' ,nl: '%1d geleden' ,zh_cn: '%1天前' } @@ -9948,7 +9948,7 @@ function init() { ,sv: 'RETRO' ,nb: 'GAMMELT' ,fi: 'RETRO' - ,pt: 'RETRO' + ,pt: 'RETRO' ,sk: 'RETRO' ,it: 'RETRO' ,nl: 'RETRO' @@ -9962,7 +9962,7 @@ function init() { ,sv: 'Sensor' ,nb: 'Sensoralder' ,fi: 'SIKÄ' - ,pt: 'IddS' + ,pt: 'IddS' ,sk: 'SENZ' ,it: 'SAGE' ,nl: 'SAGE' @@ -9977,7 +9977,7 @@ function init() { ,sv: 'Sensor byte/omstart överskriden!' ,nb: 'Sensor bytte/omstart overskredet!' ,fi: 'Sensorin vaihto/uudelleenkäynnistys yli määräajan!' - ,pt: 'Substituição/reinício de sensor vencido' + ,pt: 'Substituição/reinício de sensor vencido' ,sk: 'Čas na výmenu/reštart sensoru uplynul!' ,it: 'Cambio/riavvio del sensore in ritardo!' ,nl: 'Sensor vevang/hertstart tijd gepasseerd' @@ -9991,7 +9991,7 @@ function init() { ,sv: 'Dags att byta/starta om sensorn' ,nb: 'På tide å bytte/restarte sensoren' ,fi: 'Aika vaihtaa / käynnistää sensori uudelleen' - ,pt: 'Hora de substituir/reiniciar sensor' + ,pt: 'Hora de substituir/reiniciar sensor' ,sk: 'Čas na výmenu/reštart senzoru' ,it: 'Tempo di cambiare/riavvio sensore' ,nl: 'Sensor vervangen of herstarten' @@ -10005,7 +10005,7 @@ function init() { ,sv: 'Byt/starta om sensorn snart' ,nb: 'Bytt/restarta sensoren snart' ,fi: 'Vaihda/käynnistä sensori uudelleen pian' - ,pt: 'Mudar/reiniciar sensor em breve' + ,pt: 'Mudar/reiniciar sensor em breve' ,sk: 'Čoskoro bude potrebné vymeniť/reštartovať senzor' ,it: 'Modifica/riavvio sensore prossimamente' ,nl: 'Herstart of vervang sensor binnenkort' @@ -10019,7 +10019,7 @@ function init() { ,sv: 'Sensorålder %1 dagar %2 timmar' ,nb: 'Sensoralder %1 dag %2 timer' ,fi: 'Sensorin ikä %1 päivää, %2 tuntia' - ,pt: 'Idade do sensor %1 dias %2 horas' + ,pt: 'Idade do sensor %1 dias %2 horas' ,sk: 'Vek senzoru %1 dní %2 hodín' ,it: 'Durata Sensore %1 giorni %2 ore' ,nl: 'Sensor leeftijd %1 dag(en) en %2 uur' @@ -10033,7 +10033,7 @@ function init() { ,sv: 'Sensor insättning' ,nb: 'Sensor satt inn' ,fi: 'Sensorin Vaihto' - ,pt: 'Inserção de sensor' + ,pt: 'Inserção de sensor' ,sk: 'Výmena senzoru' ,it: 'SAGE - inserimento sensore' ,nl: 'Sensor ingebracht' @@ -10047,7 +10047,7 @@ function init() { ,sv: 'Sensorstart' ,nb: 'Sensorstart' ,fi: 'Sensorin Aloitus' - ,pt: 'Início de sensor' + ,pt: 'Início de sensor' ,sk: 'Štart senzoru' ,it: 'SAGE - partenza sensore' ,nl: 'Sensor start' @@ -10183,7 +10183,391 @@ function init() { ,ro: 'Variația medie orară' ,ru: 'усредненное изменение за час' } - + , 'FortyFiveDown': { + bg: 'slightly dropping' + , cs: 'slightly dropping' + , de: 'leicht sinkend' + , dk: 'slightly dropping' + , el: 'slightly dropping' + , en: 'slightly dropping' + , es: 'slightly dropping' + , fi: 'slightly dropping' + , fr: 'slightly dropping' + , he: 'slightly dropping' + , hr: 'slightly dropping' + , it: 'slightly dropping' + , ko: 'slightly dropping' + , nb: 'slightly dropping' + , pl: 'slightly dropping' + , pt: 'slightly dropping' + , ro: 'slightly dropping' + , ru: 'slightly dropping' + , sk: 'slightly dropping' + , sv: 'slightly dropping' + , zh_cn: 'slightly dropping' + , zh_tw: 'slightly dropping' + }, + 'FortyFiveUp': { + bg: 'slightly rising' + , cs: 'slightly rising' + , de: 'leicht fallend' + , dk: 'slightly rising' + , el: 'slightly rising' + , en: 'slightly rising' + , es: 'slightly rising' + , fi: 'slightly rising' + , fr: 'slightly rising' + , he: 'slightly rising' + , hr: 'slightly rising' + , it: 'slightly rising' + , ko: 'slightly rising' + , nb: 'slightly rising' + , pl: 'slightly rising' + , pt: 'slightly rising' + , ro: 'slightly rising' + , ru: 'slightly rising' + , sk: 'slightly rising' + , sv: 'slightly rising' + , zh_cn: 'slightly rising' + , zh_tw: 'slightly rising' + }, + 'Flat': { + bg: 'holding' + , cs: 'holding' + , de: 'gleichbleibend' + , dk: 'holding' + , el: 'holding' + , en: 'holding' + , es: 'holding' + , fi: 'holding' + , fr: 'holding' + , he: 'holding' + , hr: 'holding' + , it: 'holding' + , ko: 'holding' + , nb: 'holding' + , pl: 'holding' + , pt: 'holding' + , ro: 'holding' + , ru: 'holding' + , sk: 'holding' + , sv: 'holding' + , zh_cn: 'holding' + , zh_tw: 'holding' + }, + 'SingleUp': { + bg: 'rising' + , cs: 'rising' + , de: 'steigend' + , dk: 'rising' + , el: 'rising' + , en: 'rising' + , es: 'rising' + , fi: 'rising' + , fr: 'rising' + , he: 'rising' + , hr: 'rising' + , it: 'rising' + , ko: 'rising' + , nb: 'rising' + , pl: 'rising' + , pt: 'rising' + , ro: 'rising' + , ru: 'rising' + , sk: 'rising' + , sv: 'rising' + , zh_cn: 'rising' + , zh_tw: 'rising' + }, + 'SingleDown': { + bg: 'dropping' + , cs: 'dropping' + , de: 'sinkend' + , dk: 'dropping' + , el: 'dropping' + , en: 'dropping' + , es: 'dropping' + , fi: 'dropping' + , fr: 'dropping' + , he: 'dropping' + , hr: 'dropping' + , it: 'dropping' + , ko: 'dropping' + , nb: 'dropping' + , pl: 'dropping' + , pt: 'dropping' + , ro: 'dropping' + , ru: 'dropping' + , sk: 'dropping' + , sv: 'dropping' + , zh_cn: 'dropping' + , zh_tw: 'dropping' + }, + 'DoubleDown': { + bg: 'rapidly dropping' + , cs: 'rapidly dropping' + , de: 'schnell sinkend' + , dk: 'rapidly dropping' + , el: 'rapidly dropping' + , en: 'rapidly dropping' + , es: 'rapidly dropping' + , fi: 'rapidly dropping' + , fr: 'rapidly dropping' + , he: 'rapidly dropping' + , hr: 'rapidly dropping' + , it: 'rapidly dropping' + , ko: 'rapidly dropping' + , nb: 'rapidly dropping' + , pl: 'rapidly dropping' + , pt: 'rapidly dropping' + , ro: 'rapidly dropping' + , ru: 'rapidly dropping' + , sk: 'rapidly dropping' + , sv: 'rapidly dropping' + , zh_cn: 'rapidly dropping' + , zh_tw: 'rapidly dropping' + }, + 'DoubleUp': { + bg: 'rapidly rising' + , cs: 'rapidly rising' + , de: 'schnell steigend' + , dk: 'rapidly rising' + , el: 'rapidly rising' + , en: 'rapidly rising' + , es: 'rapidly rising' + , fi: 'rapidly rising' + , fr: 'rapidly rising' + , he: 'rapidly rising' + , hr: 'rapidly rising' + , it: 'rapidly rising' + , ko: 'rapidly rising' + , nb: 'rapidly rising' + , pl: 'rapidly rising' + , pt: 'rapidly rising' + , ro: 'rapidly rising' + , ru: 'rapidly rising' + , sk: 'rapidly rising' + , sv: 'rapidly rising' + , zh_cn: 'rapidly rising' + , zh_tw: 'rapidly rising' + }, + 'alexaStatus': { + bg: '%1 and %2 as of %3.' + , cs: '%1 and %2 as of %3.' + , de: '%1 und bis %3 %2.' + , dk: '%1 and %2 as of %3.' + , el: '%1 and %2 as of %3.' + , en: '%1 and %2 as of %3.' + , es: '%1 and %2 as of %3.' + , fi: '%1 and %2 as of %3.' + , fr: '%1 and %2 as of %3.' + , he: '%1 and %2 as of %3.' + , hr: '%1 and %2 as of %3.' + , it: '%1 and %2 as of %3.' + , ko: '%1 and %2 as of %3.' + , nb: '%1 and %2 as of %3.' + , pl: '%1 and %2 as of %3.' + , pt: '%1 and %2 as of %3.' + , ro: '%1 and %2 as of %3.' + , ru: '%1 and %2 as of %3.' + , sk: '%1 and %2 as of %3.' + , sv: '%1 and %2 as of %3.' + , zh_cn: '%1 and %2 as of %3.' + , zh_tw: '%1 and %2 as of %3.' + }, + 'alexaBasal': { + bg: '%1 current basal is %2 units per hour' + , cs: '%1 current basal is %2 units per hour' + , de: '%1 aktuelle Basalrate ist %2 Einheiten je Stunde' + , dk: '%1 current basal is %2 units per hour' + , el: '%1 current basal is %2 units per hour' + , en: '%1 current basal is %2 units per hour' + , es: '%1 current basal is %2 units per hour' + , fi: '%1 current basal is %2 units per hour' + , fr: '%1 current basal is %2 units per hour' + , he: '%1 current basal is %2 units per hour' + , hr: '%1 current basal is %2 units per hour' + , it: '%1 current basal is %2 units per hour' + , ko: '%1 current basal is %2 units per hour' + , nb: '%1 current basal is %2 units per hour' + , pl: '%1 current basal is %2 units per hour' + , pt: '%1 current basal is %2 units per hour' + , ro: '%1 current basal is %2 units per hour' + , ru: '%1 current basal is %2 units per hour' + , sk: '%1 current basal is %2 units per hour' + , sv: '%1 current basal is %2 units per hour' + , zh_cn: '%1 current basal is %2 units per hour' + , zh_tw: '%1 current basal is %2 units per hour' + }, + 'alexaBasalTemp': { + bg: '%1 temp basal of %2 units per hour will end %3' + , cs: '%1 temp basal of %2 units per hour will end %3' + , de: '%1 temporäre Basalrate von %2 Einheiten endet in %3' + , dk: '%1 temp basal of %2 units per hour will end %3' + , el: '%1 temp basal of %2 units per hour will end %3' + , en: '%1 temp basal of %2 units per hour will end %3' + , es: '%1 temp basal of %2 units per hour will end %3' + , fi: '%1 temp basal of %2 units per hour will end %3' + , fr: '%1 temp basal of %2 units per hour will end %3' + , he: '%1 temp basal of %2 units per hour will end %3' + , hr: '%1 temp basal of %2 units per hour will end %3' + , it: '%1 temp basal of %2 units per hour will end %3' + , ko: '%1 temp basal of %2 units per hour will end %3' + , nb: '%1 temp basal of %2 units per hour will end %3' + , pl: '%1 temp basal of %2 units per hour will end %3' + , pt: '%1 temp basal of %2 units per hour will end %3' + , ro: '%1 temp basal of %2 units per hour will end %3' + , ru: '%1 temp basal of %2 units per hour will end %3' + , sk: '%1 temp basal of %2 units per hour will end %3' + , sv: '%1 temp basal of %2 units per hour will end %3' + , zh_cn: '%1 temp basal of %2 units per hour will end %3' + , zh_tw: '%1 temp basal of %2 units per hour will end %3' + }, + 'alexaIob': { + bg: 'and you have %1 insulin on board.' + , cs: 'and you have %1 insulin on board.' + , de: 'und du hast %1 Insulin wirkend.' + , dk: 'and you have %1 insulin on board.' + , el: 'and you have %1 insulin on board.' + , en: 'and you have %1 insulin on board.' + , es: 'and you have %1 insulin on board.' + , fi: 'and you have %1 insulin on board.' + , fr: 'and you have %1 insulin on board.' + , he: 'and you have %1 insulin on board.' + , hr: 'and you have %1 insulin on board.' + , it: 'and you have %1 insulin on board.' + , ko: 'and you have %1 insulin on board.' + , nb: 'and you have %1 insulin on board.' + , pl: 'and you have %1 insulin on board.' + , pt: 'and you have %1 insulin on board.' + , ro: 'and you have %1 insulin on board.' + , ru: 'and you have %1 insulin on board.' + , sk: 'and you have %1 insulin on board.' + , sv: 'and you have %1 insulin on board.' + , zh_cn: 'and you have %1 insulin on board.' + , zh_tw: 'and you have %1 insulin on board.' + }, + 'alexaIobIntent': { + bg: 'You have %1 insulin on board' + , cs: 'You have %1 insulin on board' + , de: 'Du hast noch %1 Insulin wirkend' + , dk: 'You have %1 insulin on board' + , el: 'You have %1 insulin on board' + , en: 'You have %1 insulin on board' + , es: 'You have %1 insulin on board' + , fi: 'You have %1 insulin on board' + , fr: 'You have %1 insulin on board' + , he: 'You have %1 insulin on board' + , hr: 'You have %1 insulin on board' + , it: 'You have %1 insulin on board' + , ko: 'You have %1 insulin on board' + , nb: 'You have %1 insulin on board' + , pl: 'You have %1 insulin on board' + , pt: 'You have %1 insulin on board' + , ro: 'You have %1 insulin on board' + , ru: 'You have %1 insulin on board' + , sk: 'You have %1 insulin on board' + , sv: 'You have %1 insulin on board' + , zh_cn: 'You have %1 insulin on board' + , zh_tw: 'You have %1 insulin on board' + }, + 'alexaIobUnits': { + bg: '%1 units of' + , cs: '%1 units of' + , de: 'noch %1 Einheiten' + , dk: '%1 units of' + , el: '%1 units of' + , en: '%1 units of' + , es: '%1 units of' + , fi: '%1 units of' + , fr: '%1 units of' + , he: '%1 units of' + , hr: '%1 units of' + , it: '%1 units of' + , ko: '%1 units of' + , nb: '%1 units of' + , pl: '%1 units of' + , pt: '%1 units of' + , ro: '%1 units of' + , ru: '%1 units of' + , sk: '%1 units of' + , sv: '%1 units of' + , zh_cn: '%1 units of' + , zh_tw: '%1 units of' + }, + 'alexaPreamble': { + bg: 'Your' + , cs: 'Your' + , de: 'Deine' + , dk: 'Your' + , el: 'Your' + , en: 'Your' + , es: 'Your' + , fi: 'Your' + , fr: 'Your' + , he: 'Your' + , hr: 'Your' + , it: 'Your' + , ko: 'Your' + , nb: 'Your' + , pl: 'Your' + , pt: 'Your' + , ro: 'Your' + , ru: 'Your' + , sk: 'Your' + , sv: 'Your' + , zh_cn: 'Your' + , zh_tw: 'Your' + }, + 'alexaPreamble3person': { + bg: '%1 has a ' + , cs: '%1 has a ' + , de: '%1 hat eine' + , dk: '%1 has a ' + , el: '%1 has a ' + , en: '%1 has a ' + , es: '%1 has a ' + , fi: '%1 has a ' + , fr: '%1 has a ' + , he: '%1 has a ' + , hr: '%1 has a ' + , it: '%1 has a ' + , ko: '%1 has a ' + , nb: '%1 has a ' + , pl: '%1 has a ' + , pt: '%1 has a ' + , ro: '%1 has a ' + , ru: '%1 has a ' + , sk: '%1 has a ' + , sv: '%1 has a ' + , zh_cn: '%1 has a ' + , zh_tw: '%1 has a ' + }, + 'alexaNoInsulin': { + bg: 'no' + , cs: 'no' + , de: 'kein' + , dk: 'no' + , el: 'no' + , en: 'no' + , es: 'no' + , fi: 'no' + , fr: 'no' + , he: 'no' + , hr: 'no' + , it: 'no' + , ko: 'no' + , nb: 'no' + , pl: 'no' + , pt: 'no' + , ro: 'no' + , ru: 'no' + , sk: 'no' + , sv: 'no' + , zh_cn: 'no' + , zh_tw: 'no' + } + }; language.translations = translations; diff --git a/lib/plugins/alexa.js b/lib/plugins/alexa.js index 7be0dfe5258..38ae449c249 100644 --- a/lib/plugins/alexa.js +++ b/lib/plugins/alexa.js @@ -66,7 +66,7 @@ function init(env, ctx) { // status = _.orderBy(status, ['priority'], ['asc']) }; - alexa.getRollup = function(rollupGroup, sbx, slots, callback) { + alexa.getRollup = function(rollupGroup, sbx, slots, locale, callback) { var handlers = _.map(rollup[rollupGroup], 'handler'); console.log('Rollup array for ', rollupGroup); console.log(rollup[rollupGroup]); diff --git a/lib/plugins/basalprofile.js b/lib/plugins/basalprofile.js index d82421a2579..db47e2bf279 100644 --- a/lib/plugins/basalprofile.js +++ b/lib/plugins/basalprofile.js @@ -101,19 +101,38 @@ function init (ctx) { }; function basalMessage(slots, sbx) { - var basalValue = sbx.data.profile.getTempBasal(sbx.time); - var response = 'Unable to determine current basal'; - var preamble = ''; - if (basalValue.treatment) { - preamble = (slots && slots.pwd && slots.pwd.value) ? slots.pwd.value + ' has a ' : 'Your '; - var minutesLeft = moment(basalValue.treatment.endmills).from(moment(sbx.time)); - response = preamble + 'temp basal of ' + basalValue.totalbasal + ' units per hour will end ' + minutesLeft; - } else { - preamble = (slots && slots.pwd && slots.pwd.value) ? slots.pwd.value + ' ' : 'Your '; - response = preamble + 'current basal is ' + basalValue.totalbasal + ' units per hour'; + var basalValue = sbx.data.profile.getTempBasal(sbx.time); + var response = 'Unable to determine current basal'; + var preamble = ''; + if (basalValue.treatment) { + preamble = (slots && slots.pwd && slots.pwd.value) ? translate('alexaPreamble3person', { + params: [ + slots.pwd.value + ] + }) : translate('alexaPreamble'); + var minutesLeft = moment(basalValue.treatment.endmills).from(moment(sbx.time)); + response = translate('alexaBasalTemp', { + params: [ + preamble, + basalValue.totalbasal, + minutesLeft + ] + }); + } else { + preamble = (slots && slots.pwd && slots.pwd.value) ? translate('alexaPreamble3person', { + params: [ + slots.pwd.value + ] + }) : translate('alexaPreamble'); + response = translate('alexaBasal', { + params: [ + preamble, + basalValue.totalbasal + ] + }); + } + return response; } - return response; - } function alexaRollupCurrentBasalHandler (slots, sbx, callback) { callback(null, {results: basalMessage(slots, sbx), priority: 1}); diff --git a/lib/plugins/iob.js b/lib/plugins/iob.js index 744afb2b39b..dcc0c4504a9 100644 --- a/lib/plugins/iob.js +++ b/lib/plugins/iob.js @@ -244,21 +244,42 @@ function init(ctx) { }; function alexaIOBIntentHandler (callback, slots, sbx) { - var preamble = (slots && slots.pwd && slots.pwd.value) ? slots.pwd.value.replace('\'s', '') + ' has ' : 'You have '; - var message = preamble + getIob(sbx) + ' insulin on board'; + var preamble = + (slots && slots.pwd && slots.pwd.value) ? + translate('alexaPreamble3person', { + params: [ + slots.pwd.value.replace('\'s', '') + ] + }) : + translate('alexaPreamble'); + + var message = translate('alexaIobIntent', { + params: [ + //preamble, + getIob(sbx) + ] + }); + //preamble + + ' insulin on board'; callback('Current IOB', message); } function alexaIOBRollupHandler (slots, sbx, callback) { - var message = 'and you have ' + getIob(sbx) + ' insulin on board.'; + var iob = getIob(sbx); + var message = translate('alexaIob', { + params: [iob] + }); callback(null, {results: message, priority: 2}); } function getIob(sbx) { if (sbx.properties.iob && sbx.properties.iob.iob !== 0) { - return utils.toFixed(sbx.properties.iob.iob) + ' units of'; + return translate('alexaIobUnits', { + params: [ + utils.toFixed(sbx.properties.iob.iob) + ] + }); } - return 'no'; + return translate('alexaNoInsulin'); } iob.alexa = { diff --git a/tests/basalprofileplugin.test.js b/tests/basalprofileplugin.test.js index 26abcc23a8d..0bcfd3bc268 100644 --- a/tests/basalprofileplugin.test.js +++ b/tests/basalprofileplugin.test.js @@ -8,6 +8,7 @@ describe('basalprofile', function ( ) { settings: {} , language: require('../lib/language')() }; + ctx.language.set('en'); ctx.ddata = require('../lib/data/ddata')(); ctx.notifications = require('../lib/notifications')(env, ctx); diff --git a/tests/iob.test.js b/tests/iob.test.js index e9ec18664b0..30872e4fb4d 100644 --- a/tests/iob.test.js +++ b/tests/iob.test.js @@ -6,6 +6,7 @@ var should = require('should'); describe('IOB', function() { var ctx = {}; ctx.language = require('../lib/language')(); + ctx.language.set('en'); var iob = require('../lib/plugins/iob')(ctx);