Working on an app called locale that will handle locales , so we can see eg month, day names and more in our language.
Writing single values work's like expected, but looks like not using the correct way to write a list.
So how should this be written correctly?
// source s = require('Storage'); var locale = { "de_DE": { dp : ',', ts : '.', cs : '€', ics : 'EUR', sp : 'km', ds : 'mm,cm,m,km', t : '°C', ap: 0, mo : "Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", mos : "Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", dy : "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", dys : "So,Mo,Di,Mi,Do,Fr,Sa", tr : { yes: 'ja', Yes : 'Ja', no: 'nein', No : 'Nein', ok : 'ok', on : 'an', off: 'aus' } } }; lang = "de_DE"; s.write('locale',` exports.name = function() {return '${lang}'}; exports.temp = function(n){return n + '${locale[lang].tr}';}; exports.translate = function(t){return ${locale[lang].tr}[t];}; `); /* console.log(require('locale').name()); console.log(require('locale').translate("yes")); console.log(require('locale').temp(25.5)); */ //translate = function(t) { return locale[lang].tr[t];}; console.log(s.read('locale')); console.log(require('locale').temp(25.5)); console.log(require('locale').translate("yes")); /* output exports.name = function() {return 'de_DE'}; exports.temp = function(n){return n + '[object Object]';}; exports.translate = function(t){return [object Object][t];}; 25.5[object Object] Uncaught ReferenceError: "object" is not defined at line 1 col 2 [object Object][t]; ^ in function "translate" called from line 48 col 46 console.log(require('locale').translate("yes")); ^ */
@MaBe started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Working on an app called locale that will handle locales , so we can see eg month, day names and more in our language.
Writing single values work's like expected, but looks like not using the correct way to write a list.
So how should this be written correctly?