You are reading a single comment by @Gordon and its replies.
Click here to read the full conversation.
-
Hi Gordon,
thanks for the quick feedback. Got this working now:
https://github.com/espruino/BangleApps/pull/138For others: To get it to work in the emulator, instead of
var locales = require("locale");
I used this (for German):locale = {"lang":"de_DE","decimal_point":",","thousands_sep":".","currency_symbol":"\x80","int_curr_symbol":"EUR","speed":"kmh","distance":{"0":"m","1":"km"},"temperature":"°C","ampm":{"0":"","1":""},"timePattern":{"0":"%HH:%MM:%SS","1":"%HH:%MM"},"datePattern":{"0":"%A, %d. %B %Y","1":"%d.%m.%Y"},"abmonth":"Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez","month":"Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember","abday":"So,Mo,Di,Mi,Do,Fr,Sa","day":"Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag","trans":{"yes":"ja","Yes":"Ja","no":"nein","No":"Nein","ok":"ok","on":"an","off":"aus"}}; locales = { lang: locale.lang, currencySym: String.fromCharCode(locale.currency_symbol), dow: (d,short) => {day = d.getDay();return (short) ? locale.abday.split(",")[day] : locale.day.split(",")[day];}, month: (d,short) => { month = d.getMonth(); return (short) ? locale.abmonth.split(",")[month] : locale.month.split(",")[month];}, number: n => n.toString().replace(locale.thousands_sep, locale.decimal_point), currency: n => n.toFixed(2).replace(locale.thousands_sep, locale.decimal_point) + locale.currency_symbol, distance: n => (n < 1000) ? Math.round(n) + locale.distance[0] : Math.round(n/1000) + locale.distance[1], speed: s => Math.round(s) +locale.speed, temp: t => Math.round(t) + locale.temperature, translate: s => {s=""+s;return locale.trans[s]||locale.trans[s.toLowerCase()]||s;}, date: (d,short) => (short) ? `${('0'+d.getDate()).substr(-2)}.${('0'+(d.getMonth()+1).toString()).substr(-2)}.${d.getFullYear()}`: `${locale.day.split(',')[d.getDay()]}, ${('0'+d.getDate()).substr(-2)}. ${locale.month.split(',')[d.getMonth()]} ${d.getFullYear()}`, time: (d,short) => (short) ? `${('0'+d.getHours()).substr(-2)}:${('0'+d.getMinutes()).substr(-2)}`: `${('0'+d.getHours()).substr(-2)}:${('0'+d.getMinutes()).substr(-2)}:${('0'+d.getSeconds()).substr(-2)}`, };
The only thing I am still fighting with is the currency symbol, I am not getting this displayed...
Regards,
DerGuteWolf
At the moment you can't use any locale in the emulator other than the built-in one, which is en_GB.
Adding a full tutorial and docs on this is on my list of things to do, but if you look at https://github.com/espruino/Espruino/blob/master/libs/js/banglejs/locale.js you'll see what functions are available to you.
So if you do
require("locale").dow(new Date())
you'll get the day of the week. If you then try that app on a real Bangle.js with a different locale, you'll get the day names in the correct language