diff --git a/apps/locale/locale.html b/apps/locale/locale.html
index 72c862da0..7e958fcf8 100644
--- a/apps/locale/locale.html
+++ b/apps/locale/locale.html
@@ -2,6 +2,10 @@
+
@@ -13,6 +17,11 @@
+
+
Then click
@@ -93,21 +102,8 @@ exports = { name : "en_GB", currencySym:"£",
checkChars(locale,localeName);
});
- var languageSelector = document.getElementById("languages");
- languageSelector.innerHTML = Object.keys(locales).map(l=>{
- var localeParts = l.split("_"); // en_GB -> ["en","GB"]
- var icon = "";
- // If we have a 2 char ISO country code, use it to get the unicode flag
- if (localeParts[1] && localeParts[1].length==2)
- icon = localeParts[1].toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0)+127397) )+" ";
- if (localeParts[1]=="NAV")
- icon = "⛵✈️ ";
- return ``
- }).join("\n");
- document.getElementById("upload").addEventListener("click", function() {
-
- const lang = languageSelector.options[languageSelector.selectedIndex].value;
+ function createLocaleModule(lang) {
console.log(`Language ${lang}`);
const translations = document.getElementById('translations').checked;
@@ -151,7 +147,7 @@ exports = { name : "en_GB", currencySym:"£",
var replaceList = {
"%Y": "d.getFullYear()",
- "%y": "(d.getFullYear().toString()).slice(-2)",
+ "%y": "d.getFullYear().toString().slice(-2)",
"%m": "('0'+(d.getMonth()+1).toString()).slice(-2)",
"%-m": "d.getMonth()+1",
"%d": "('0'+d.getDate()).slice(-2)",
@@ -182,16 +178,17 @@ exports = { name : "en_GB", currencySym:"£",
`exports.number(n) + ${js(locale.currency_symbol)}`;
var temperature = locale.temperature=='°F' ? '(t*9/5)+32' : 't';
- var localeModule = `
+ function getLocaleModule(isLocal) {
+ return `
function round(n, dp) {
if (dp===undefined) dp=0;
- var p = Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10)));
+ var p = Math.max(0,Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10))));
return n.toFixed(p);
}
var is12;
function getHours(d) {
var h = d.getHours();
- if (is12 === undefined) is12 = (require('Storage').readJSON('setting.json', 1) || {})["12hour"];
+ if (is12 === undefined) is12 = ${isLocal ? "false" : `(require('Storage').readJSON('setting.json', 1) || {})["12hour"]`};
if (!is12) return ('0' + h).slice(-2);
return ((h % 12 == 0) ? 12 : h % 12).toString();
}
@@ -224,7 +221,54 @@ exports = {
time: (d,short) => short ? \`${timeS}\` : \`${timeN}\`,
meridian: d => d.getHours() < 12 ? ${js(locale.ampm[0])}:${js(locale.ampm[1])},
};
-`.trim();
+`.trim()
+ };
+
+ var exports;
+ eval(getLocaleModule(true));
+ console.log("exports:",exports);
+
+ var date = new Date();
+ document.getElementById("examples").innerHTML = `
+ | Short | Long |
+| Day | ${exports.dow(date,1)} | ${exports.dow(date,0)} |
+| Month | ${exports.month(date,1)} | ${exports.month(date,0)} |
+| Date | ${exports.date(date,1)} | ${exports.date(date,0)} |
+| Time | ${exports.time(date,1)} | ${exports.time(date,0)} |
+| Number | ${exports.number(12.3456789)} | ${exports.number(12.3456789,4)} |
+| Currency | | ${exports.currency(12.34)} |
+| Distance | ${exports.distance(12.34,0)} | ${exports.distance(12345.6,1)} |
+| Speed | | ${exports.speed(123)} |
+| Temperature | | ${exports.temp(12,0)} |
+`;
+ return getLocaleModule(false);
+ }
+
+ var languageSelector = document.getElementById("languages");
+ languageSelector.innerHTML = Object.keys(locales).map(l=>{
+ var locale = locales[l];
+ var localeParts = l.split("_"); // en_GB -> ["en","GB"]
+ var icon = "";
+ // If we have a 2 char ISO country code, use it to get the unicode flag
+ if (locale.icon)
+ icon = locale.icon+" ";
+ else if (localeParts[1] && localeParts[1].length==2)
+ icon = localeParts[1].toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0)+127397) )+" ";
+ return ``
+ }).join("\n");
+ languageSelector.addEventListener('change', function() {
+ const lang = languageSelector.options[languageSelector.selectedIndex].value;
+ createLocaleModule(lang);
+ });
+ // initial value
+ createLocaleModule(languageSelector.options[languageSelector.selectedIndex].value);
+
+
+
+ document.getElementById("upload").addEventListener("click", function() {
+
+ const lang = languageSelector.options[languageSelector.selectedIndex].value;
+ var localeModule = createLocaleModule(lang);
console.log("Locale Module is:",localeModule);
sendCustomizedApp({
diff --git a/apps/locale/locales.js b/apps/locale/locales.js
index cd720ba62..f36c6725e 100644
--- a/apps/locale/locales.js
+++ b/apps/locale/locales.js
@@ -79,6 +79,44 @@ var locales = {
day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
// No translation for english...
},
+ "en_US": {
+ lang: "en_US",
+ notes: "USA with MM/DD/YY date",
+ decimal_point: ".",
+ thousands_sep: ",",
+ currency_symbol: "$", currency_first: true,
+ int_curr_symbol: "USD",
+ speed: "mph",
+ distance: { 0: "ft", 1: "mi" },
+ temperature: "°F",
+ ampm: { 0: "am", 1: "pm" },
+ timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
+ datePattern: { 0: "%b %d, %Y", 1: "%m/%d/%y" },
+ abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
+ month: "January,February,March,April,May,June,July,August,September,October,November,December",
+ abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat",
+ day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
+ // No translation for english...
+ },
+ "en_US 2": {
+ lang: "en_US 2", icon:"🇺🇸",
+ notes: "USA with YYYY-MM-DD date",
+ decimal_point: ".",
+ thousands_sep: ",",
+ currency_symbol: "$", currency_first: true,
+ int_curr_symbol: "USD",
+ speed: "mph",
+ distance: { 0: "ft", 1: "mi" },
+ temperature: "°F",
+ ampm: { 0: "am", 1: "pm" },
+ timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
+ datePattern: { 0: "%b %d, %Y", 1: "%Y-%m-%d" },
+ abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
+ month: "January,February,March,April,May,June,July,August,September,October,November,December",
+ abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat",
+ day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
+ // No translation for english...
+ },
"en_IN": {
lang: "en_IN",
decimal_point: ".",
@@ -118,7 +156,7 @@ var locales = {
// No translation for english...
},
"en_NAV": { // navigation units nautical miles and knots
- lang: "en_NAV",
+ lang: "en_NAV", icon: "⛵✈️",
decimal_point: ".",
thousands_sep: ",",
currency_symbol: "£", currency_first: true,
@@ -154,24 +192,6 @@ var locales = {
trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus",
"< Back": "< Zurück", "Delete": "Löschen", "Mark Unread": "Als ungelesen markieren" }
},
- "en_US": {
- lang: "en_US",
- decimal_point: ".",
- thousands_sep: ",",
- currency_symbol: "$", currency_first: true,
- int_curr_symbol: "USD",
- speed: "mph",
- distance: { 0: "ft", 1: "mi" },
- temperature: "°F",
- ampm: { 0: "am", 1: "pm" },
- timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
- datePattern: { 0: "%b %d, %Y", 1: "%m/%d/%y" },
- abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
- month: "January,February,March,April,May,June,July,August,September,October,November,December",
- abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat",
- day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
- // No translation for english...
- },
"en_JP": { // we do not have the font, so it is not ja_JP
lang: "en_JP",
decimal_point: ".",