2024-08-07 16:06:59 +00:00
<!DOCTYPE html>
< html lang = "en" >
2020-03-04 16:42:44 +00:00
< head >
2020-06-01 16:04:55 +00:00
< meta charset = "UTF-8" >
2020-03-04 16:42:44 +00:00
< link rel = "stylesheet" href = "../../css/spectre.min.css" >
2023-09-11 13:54:18 +00:00
< style >
2024-08-07 13:20:13 +00:00
table {width:100%;margin-top:3%;}
.table_t {font-weight:bold;width:40%;}
.form-group > * {display:block;}
2023-09-11 13:54:18 +00:00
< / style >
2020-03-04 16:42:44 +00:00
< / head >
< body >
< p > Please choose a language from the following list:< / p >
< div class = "form-group" >
< select id = "languages" class = "form-select" >
< / select >
< / div >
2022-01-15 19:09:58 +00:00
< div class = "form-group" >
2024-08-07 13:20:13 +00:00
< label > < input id = "translations" type = "checkbox" / > Add common language translations like "Yes", "No", "On", "Off"< br / > < i > (Not recommended. For translations use the option under < code > More...< / code > in the app loader.< / i > < / label >
< label > < input id = "customize" type = "checkbox" / > Advanced: Customize the date and time formats.< / label >
2022-01-15 19:09:58 +00:00
< / div >
2023-09-11 13:54:18 +00:00
< p >
2024-08-07 13:20:13 +00:00
< span id = "customize-warning" > < / span >
< table id = "examples-short-long" > < / table >
< table id = "examples" > < / table >
2023-09-11 13:54:18 +00:00
< / p >
2020-03-04 16:42:44 +00:00
< p > Then click < button id = "upload" class = "btn btn-primary" > Upload< / button > < / p >
2020-08-24 10:59:52 +00:00
< script src = "../../core/lib/customize.js" > < / script >
2022-04-07 15:08:39 +00:00
< script src = "../../core/js/utils.js" > < / script >
2024-08-07 16:06:59 +00:00
< script src = "locales.js" > < / script >
2020-03-04 16:42:44 +00:00
< script >
2020-04-02 13:16:54 +00:00
/*
2024-03-25 10:16:03 +00:00
eg. the built-in en_GB at https://github.com/espruino/Espruino/blob/master/libs/js/banglejs/locale.js is:
2020-04-02 13:16:54 +00:00
2024-03-25 10:16:03 +00:00
function round(n, dp) {
if (dp===undefined) dp=1;
var p = Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10)));
return n.toFixed(p);
}
exports = { name : "system", currencySym:"£",
2020-04-02 13:16:54 +00:00
translate : str=>str, // as-is
date : (d,short) => short?("0"+d.getDate()).substr(-2)+"/"+("0"+(d.getMonth()+1)).substr(-2)+"/"+d.getFullYear():d.toString().substr(4,11), // Date to "Feb 28 2020" or "28/02/2020"(short)
time : (d,short) => { // Date to "4:15.28 pm" or "15:42"(short)
2024-03-25 10:16:03 +00:00
var h = d.getHours(), m = d.getMinutes()
if ((require('Storage').readJSON('setting.json',1)||{})["12hour"])
h = (h%12==0) ? 12 : h%12; // 12 hour
2020-04-02 13:16:54 +00:00
if (short)
2024-03-25 10:16:03 +00:00
return (" "+h).substr(-2)+":"+("0"+m).substr(-2);
2020-04-02 13:16:54 +00:00
else {
2024-03-25 10:16:03 +00:00
var r = "am";
2020-04-02 13:16:54 +00:00
if (h==0) { h=12; }
else if (h>=12) {
if (h>12) h-=12;
r = "pm";
}
return (" "+h).substr(-2)+":"+("0"+m).substr(-2)+"."+("0"+d.getSeconds()).substr(-2)+" "+r;
}
},
2024-03-25 10:16:03 +00:00
dow : (d,short) => "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(",")[d.getDay()].substr(0, short ? 3 : 10), // Date to "Monday" or "Mon"(short)
month : (d,short) => "January,February,March,April,May,June,July,August,September,October,November,December".split(",")[d.getMonth()].substr(0, short ? 3 : 10), // Date to "February" or "Feb"(short)
number: (n, dec) => {
if (dec == null) dec = 2;
var w = n.toFixed(dec),
k = w|0,
b = n < 0 ? 1 : 0 ,
u = Math.abs(w-k),
d = (''+u.toFixed(dec)).substr(2, dec),
s = ''+k,
i = s.length,
r = '';
while ((i-=3) > b)
r = ',' + s.substr(i, 3) + r;
return s.substr(0, i + 3) + r + (d ? '.' + d: '');
},
currency : n => {console.log("Warning: Currency information is deprecated");return "£"+n.toFixed(2)}, // number to "£1.00"
distance : (m,dp) => (m< 1000 ) ? round ( m , dp ) + " m " :round ( m / 1000 , dp ) + " km " , / / meters to " 123m " or " 1 . 2km " depending on size
speed : (s,dp) => round(s/1.60934,dp)+"mph",// kph to "123mph"
temp : (t,dp) => round(t,dp)+"'C", // degrees C to degrees C
meridian: d => (d.getHours() < = 12) ? "am":"pm" // Date to am/pm
2020-04-02 13:16:54 +00:00
};
2024-03-25 10:16:03 +00:00
2020-04-02 13:16:54 +00:00
*/
2020-06-01 16:04:55 +00:00
function codePageLookup(lang, codePage, ch) {
var chCode = ch.charCodeAt();
if (chCode>=32 & & chCode< 128 ) return ch ; / / ASCII - copy it
// not normal ASCII
var n; // default is a space
if (codePage.map.indexOf(ch)>=0) // look up in char map, escape that
n = 128+codePage.map.indexOf(ch);
/*else if (chCode< 256 ) / / it ' s non-ascii , but < 256 - just escape it
n = chCode;*/
else {
2022-04-07 15:08:39 +00:00
if (CODEPAGE_CONVERSIONS[ch]) return CODEPAGE_CONVERSIONS[ch];
2020-06-01 16:04:55 +00:00
console.error(`Locale ${lang}: Character ${ch} (${chCode}) is not in Code Page ${codePage.name}`);
return undefined;
}
// escape the char
2020-06-02 19:21:27 +00:00
return '\\x'+(n+256).toString(16).slice(-2);
2020-06-01 16:04:55 +00:00
}
2020-04-02 13:16:54 +00:00
// do some sanity checks
Object.keys(locales).forEach(function(localeName) {
var locale = locales[localeName];
2020-04-09 07:57:06 +00:00
if (locale.trans & & !locale.trans.on) console.error(localeName+": If translations are provided, 'on' *must* be included");
2020-04-02 13:16:54 +00:00
if (distanceUnits[locale.distance[0]]===undefined) console.error(localeName+": Unknown distance unit "+locale.distance[0]);
if (distanceUnits[locale.distance[1]]===undefined) console.error(localeName+": Unknown distance unit "+locale.distance[1]);
if (speedUnits[locale.speed]===undefined) console.error(localeName+": Unknown speed unit "+locale.speed);
2020-06-01 16:04:55 +00:00
if (locale.temperature!='°C' & & locale.temperature!='°F')
console.error(localeName+": Unknown temperature unit "+locale.temperature);
// Now check that codepage is ok and all chars in translation are in that codepage
const codePageName = "ISO8859-1";
if (locale.codePage) codePageName = locale.codePage;
const codePage = codePages[codePageName];
if (codePage===undefined) console.error(localeName+": Unknown codePage "+codePageName);
function checkChars(v,path) {
if ("object"==typeof v)
Object.keys(v).forEach(k=>checkChars(v[k], path+"."+k));
else if ("string"==typeof v)
for (var i=0;i< v.length ; i + + )
if (codePageLookup(localeName, codePage, v[i])===undefined)
console.error(` ... in ${path}[${i}]`);
}
checkChars(locale,localeName);
2020-04-02 13:16:54 +00:00
});
2020-03-04 16:42:44 +00:00
2024-08-07 13:20:13 +00:00
function createLocaleModule() {
2020-06-01 16:04:55 +00:00
console.log(`Language ${lang}`);
2020-03-04 16:42:44 +00:00
2022-01-15 19:09:58 +00:00
const translations = document.getElementById('translations').checked;
console.log(`Translations: ${translations}`);
2020-03-04 16:42:44 +00:00
if (!locale) {
2024-08-07 13:20:13 +00:00
alert(`Locale not set for language ${lang}!`);
2020-03-04 16:42:44 +00:00
return;
}
2022-01-15 19:09:58 +00:00
if (!translations)
locale.trans = null;
2020-06-01 16:04:55 +00:00
const codePageName = "ISO8859-1";
if (locale.codePage)
codePageName = locale.codePage;
const codePage = codePages[codePageName];
if (!codePage) {
alert(`Code Page ${codePageName} not found!`);
return;
}
2020-04-02 13:16:54 +00:00
2020-06-01 16:04:55 +00:00
// Convert object to JSON, with codepage
function js(x) {
// do nortmal conversion
x = JSON.stringify(x);
/* assume any out of bounds character is going to
be inside a quoted string */
var s = '';
for (var i=0;i< x.length ; i + + ) {
var ch = codePageLookup(lang, codePage, x[i]);
s += (ch===undefined) ? "?" : ch;
}
return s;
}
2020-04-02 13:16:54 +00:00
2020-06-02 21:00:32 +00:00
function unitConv(x) {
return x === 1 ? 'n' : 'n/' + x
}
2020-03-04 16:42:44 +00:00
var replaceList = {
2020-04-02 13:16:54 +00:00
"%Y": "d.getFullYear()",
2023-09-11 13:54:18 +00:00
"%y": "d.getFullYear().toString().slice(-2)",
2020-06-02 19:21:27 +00:00
"%m": "('0'+(d.getMonth()+1).toString()).slice(-2)",
2020-04-02 13:16:54 +00:00
"%-m": "d.getMonth()+1",
2020-06-02 19:21:27 +00:00
"%d": "('0'+d.getDate()).slice(-2)",
2020-04-02 13:16:54 +00:00
"%-d": "d.getDate()",
2023-05-31 00:00:26 +00:00
"%HH": "getHours(d)",
2020-06-02 19:21:27 +00:00
"%MM": "('0'+d.getMinutes()).slice(-2)",
"%SS": "('0'+d.getSeconds()).slice(-2)",
2022-03-30 14:11:14 +00:00
"%A": `${js(locale.day)}.split(',')[d.getDay()]`,
"%a": `${js(locale.abday)}.split(',')[d.getDay()]`,
"%B": `${js(locale.month)}.split(',')[d.getMonth()]`,
2022-03-31 10:39:59 +00:00
"%b": `${js(locale.abmonth)}.split(',')[d.getMonth()]`,
2020-06-02 21:04:22 +00:00
"%p": `d.getHours()< 12 ? $ { js ( locale . ampm [ 0 ] . toUpperCase ( ) ) } : $ { js ( locale . ampm [ 1 ] . toUpperCase ( ) ) } ` ,
"%P": `d.getHours()< 12 ? $ { js ( locale . ampm [ 0 ] . toLowerCase ( ) ) } : $ { js ( locale . ampm [ 1 ] . toLowerCase ( ) ) } `
2020-03-04 16:42:44 +00:00
};
2024-08-07 13:20:13 +00:00
var timeN = patternToCode(locale.timePattern[0]);
var timeS = patternToCode(locale.timePattern[1]);
var dateN = patternToCode(locale.datePattern[0]);
var dateS = patternToCode(locale.datePattern[1]);
2020-06-02 11:06:19 +00:00
var temperature = locale.temperature=='°F' ? '(t*9/5)+32' : 't';
2020-03-04 16:42:44 +00:00
2023-09-11 13:54:18 +00:00
function getLocaleModule(isLocal) {
return `
2022-03-30 14:11:14 +00:00
function round(n, dp) {
if (dp===undefined) dp=0;
2023-09-11 13:54:18 +00:00
var p = Math.max(0,Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10))));
2022-03-30 14:11:14 +00:00
return n.toFixed(p);
2020-06-06 11:49:52 +00:00
}
2024-08-15 15:13:58 +00:00
var _is12Hours;
function is12Hours() {
if (_is12Hours === undefined) _is12Hours = ${isLocal ? "false" : `(require('Storage').readJSON('setting.json', 1) || {})["12hour"]`};
return _is12Hours;
}
2021-11-26 20:29:58 +00:00
function getHours(d) {
var h = d.getHours();
2024-08-15 15:13:58 +00:00
if (!is12Hours()) return ('0' + h).slice(-2);
2023-05-31 06:44:26 +00:00
return ((h % 12 == 0) ? 12 : h % 12).toString();
2021-11-26 20:29:58 +00:00
}
2020-06-02 11:10:35 +00:00
exports = {
2020-04-02 13:16:54 +00:00
name: ${js(locale.lang)},
2024-03-20 12:52:43 +00:00
currencySym: ${js("£")},
2022-04-26 09:31:29 +00:00
dow: (d,short) => ${js(locale.day + ',' + locale.abday)}.split(',')[d.getDay() + (short ? 7 : 0)],
2022-03-30 14:11:14 +00:00
month: (d,short) => ${js(locale.month + ',' + locale.abmonth)}.split(',')[d.getMonth() + (short ? 12 : 0)],
2020-06-06 20:26:07 +00:00
number: (n, dec) => {
if (dec == null) dec = 2;
var w = n.toFixed(dec),
k = w|0,
b = n < 0 ? 1 : 0 ,
u = Math.abs(w-k),
d = (''+u.toFixed(dec)).substr(2, dec),
s = ''+k,
i = s.length,
r = '';
2024-03-25 10:16:03 +00:00
while ((i-=3) > b)
2020-06-06 20:26:07 +00:00
r = '${locale.thousands_sep}' + s.substr(i, 3) + r;
return s.substr(0, i + 3) + r + (d ? '${locale.decimal_point}' + d: '');
},
2024-03-21 10:29:02 +00:00
currency: n => {console.log("Warning: Currency information is deprecated, see https://github.com/espruino/BangleApps/issues/3269");return ${js("£")}+exports.number(n)},
2022-03-30 14:11:14 +00:00
distance: (n,dp) => n < ${distanceUnits[locale.distance[1]]} ? round(${unitConv(distanceUnits[locale.distance[0]])},dp) + ${js(locale.distance[0])} : round(${unitConv(distanceUnits[locale.distance[1]])},dp) + ${js(locale.distance[1])},
speed: (n,dp) => round(${unitConv(speedUnits[locale.speed])},dp) + ${js(locale.speed)},
temp: (t,dp) => round(${temperature},dp) + ${js(locale.temperature)},
2020-06-02 11:10:35 +00:00
translate: s => ${locale.trans?`{var t=${js(locale.trans)};s=''+s;return t[s]||t[s.toLowerCase()]||s;}`:`s`},
2020-06-02 21:00:02 +00:00
date: (d,short) => short ? \`${dateS}\` : \`${dateN}\`,
time: (d,short) => short ? \`${timeS}\` : \`${timeN}\`,
2024-08-27 11:51:06 +00:00
meridian: (d,force) => (force||is12Hours()) ? d.getHours() < 12 ? $ { js ( locale . ampm [ 0 ] ) } : $ { js ( locale . ampm [ 1 ] ) } : " " ,
2024-08-15 15:14:17 +00:00
is12Hours,
2020-06-02 20:59:38 +00:00
};
2023-09-11 13:54:18 +00:00
`.trim()
};
var exports;
eval(getLocaleModule(true));
console.log("exports:",exports);
2024-08-07 13:20:13 +00:00
function patternToCode(pattern){
for(const symbol of Object.keys(replaceList)){
pattern = pattern.replaceAll(symbol,"${"+replaceList[symbol]+"}");
}
return pattern;
}
function patternToOutput(pattern){
const code = patternToCode(pattern);
const result = eval(`let d = new Date();\`${code}\``);
return result;
}
function dataList(id, options, formatter){
let output = `< datalist id = "${id}" > `;
for(const option of options){
const formatted = formatter?.(option) || option;
output+=`\n< option value = "${option}" > ${formatted}< / option > `
}
output += "\n< / datalist > ";
return output;
}
2023-09-11 13:54:18 +00:00
var date = new Date();
2024-08-07 13:20:13 +00:00
// TODO: This warning should have a link to an article explaining how the formats work, and how long they are allowed to be
document.getElementById("customize-warning").innerText = customizeLocale ? "⚠️ If you make the formats too long, some apps will not work!" : "";
document.getElementById("examples-short-long").innerHTML = `
2023-09-11 13:54:18 +00:00
< tr > < td class = "table_t" > < / td > < td style = "font-weight:bold" > Short< / td > < td style = "font-weight:bold" > Long< / td > < / tr >
< tr > < td class = "table_t" > Day< / td > < td > ${exports.dow(date,1)}< / td > < td > ${exports.dow(date,0)}< / td > < / tr >
< tr > < td class = "table_t" > Month< / td > < td > ${exports.month(date,1)}< / td > < td > ${exports.month(date,0)}< / td > < / tr >
2024-08-07 13:20:13 +00:00
< tr > < td class = "table_t" > Date< / td >
< td id = "short-date-pattern-output" > ${exports.date(date,1)}< / td >
< td id = "long-date-pattern-output" > ${exports.date(date,0)}< / td >
< / tr >
${customizeLocale ? `< tr > < td class = "table_t" > Date format< / td >
< td >
< input type = text id = "short-date-pattern" list = "short-date-patterns" value = "${locale?.datePattern[" 1 " ] } " / >
${dataList("short-date-patterns", [locale?.datePattern["1"], "%-d.%-m.%y", "%-d/%-m/%y", "%d/%m/%Y"], patternToOutput)}
< / td >
< td >
< input type = text id = "long-date-pattern" list = "long-date-patterns" value = "${locale?.datePattern[" 0 " ] } " / >
${dataList("long-date-patterns", [locale?.datePattern["0"], "%-d. %b %Y", "%b %d, %Y"], patternToOutput)}
< / td >
< / td > `
: ""}
< tr > < td class = "table_t" > Time< / td >
< td id = "short-time-pattern-output" > ${exports.time(date,1)}< / td >
< td id = "long-time-pattern-output" > ${exports.time(date,0)}< / td >
< / tr >
${customizeLocale ? `< tr > < td class = "table_t" > Time format< / td >
< td >
< input type = text id = "short-time-pattern" list = "short-time-patterns" value = "${locale?.timePattern[" 1 " ] } " / >
${dataList("short-time-patterns", [ "%HH.%MM", "%HH:%MM"], patternToOutput)}
< / td >
< td >
< input type = text id = "long-time-pattern" list = "long-time-patterns" value = "${locale?.timePattern[" 0 " ] } " / >
${dataList("long-time-patterns", [locale?.timePattern["0"], "%HH.%MM.%SS", "%HH:%MM:%SS"], patternToOutput)}
< / td >
< / td > `
: ""}
< tr > < td class = "table_t" > Number< / td > < td > ${exports.number(12.3456789)}< / td > < td > ${exports.number(12.3456789,4)}< / td > < / tr >
< tr > < td class = "table_t" > Distance< / td > < td > ${exports.distance(12.34,0)}< / td > < td > ${exports.distance(12345.6,1)}< / td > < / tr >
`;
document.getElementById("examples").innerHTML = `
< tr > < td class = "table_t" > Meridian< / td > < td >
2024-08-27 11:51:06 +00:00
< span id = "meridian-am-output" > ${exports.meridian(new Date(0), true)}< / span > /
< span id = "meridian-pm-output" > ${exports.meridian(new Date(43200000), true)}< / span >
2024-08-07 13:20:13 +00:00
< / td > < / tr >
${customizeLocale ? `< tr > < td class = "table_t" > Meridian names< / td >
< td >
< input type = text id = "meridian-am" list = "meridian-ams" value = "${locale?.ampm[" 0 " ] } " / >
${dataList("meridian-ams", [locale?.ampm["0"], "AM"])}
< / td >
< td >
< input type = text id = "meridian-pm" list = "meridian-pms" value = "${locale?.ampm[" 1 " ] } " / >
${dataList("meridian-pms", [locale?.ampm["1"], "PM"])}
< / td >
< / tr > `
: ""}
< tr > < td class = "table_t" > Speed< / td > < td > ${exports.speed(123)}< / td > < / tr >
< tr > < td class = "table_t" > Temperature< / td > < td > ${exports.temp(12,0)}< / td > < / tr >
2023-09-11 13:54:18 +00:00
`;
2024-08-07 13:20:13 +00:00
if(customizeLocale){
document.querySelector("input#short-date-pattern").addEventListener("input", event => {
locale.datePattern["1"] = event.target.value;
document.querySelector("td#short-date-pattern-output").innerText = patternToOutput(event.target.value);
});
document.querySelector("input#long-date-pattern").addEventListener("input", event => {
locale.datePattern["0"] = event.target.value;
document.querySelector("td#long-date-pattern-output").innerText = patternToOutput(event.target.value);
});
document.querySelector("input#short-time-pattern").addEventListener("input", event => {
locale.timePattern["1"] = event.target.value;
document.querySelector("td#short-time-pattern-output").innerText = patternToOutput(event.target.value);
});
document.querySelector("input#long-time-pattern").addEventListener("input", event => {
locale.timePattern["0"] = event.target.value;
document.querySelector("td#long-time-pattern-output").innerText = patternToOutput(event.target.value);
});
document.querySelector("input#meridian-am").addEventListener("input", event => {
locale.ampm["0"] = event.target.value;
document.querySelector("span#meridian-am-output").innerText = event.target.value;
});
document.querySelector("input#meridian-pm").addEventListener("input", event => {
locale.ampm["1"] = event.target.value;
document.querySelector("span#meridian-pm-output").innerText = event.target.value;
});
}
2023-09-11 13:54:18 +00:00
return getLocaleModule(false);
}
2024-08-07 13:57:40 +00:00
const lastUploadedLocaleID = "last-uploaded-locale";
let lastUploadedLocale;
try{
lastUploadedLocale = JSON.parse(localStorage?.getItem(lastUploadedLocaleID));
}catch(error){
console.warn("Unable to load last uploaded locale", error);
}
if(lastUploadedLocale){
if(!lastUploadedLocale.lang){
lastUploadedLocale = undefined;
console.warn("Unable to load last uploaded locale, it is missing the lang entry");
}else if(lastUploadedLocale.custom){
// Make sure to add any missing data from the original lang
// We don't know if fx a new entry has been added after the locale was last saved
const originalLocale = structuredClone(locales[lastUploadedLocale.lang]);
lastUploadedLocale = {...originalLocale, ...lastUploadedLocale};
// Add a special entry for the custom locale, put it first in the list
locales = {[lastUploadedLocaleID]: lastUploadedLocale, ...locales};
}
}
2024-08-07 13:20:13 +00:00
var lang;
var locale;
2024-08-07 13:57:40 +00:00
var customizeLocale = false;
2023-09-11 13:54:18 +00:00
var languageSelector = document.getElementById("languages");
2024-08-07 13:20:13 +00:00
var customizeSelector = document.getElementById('customize');
2023-09-11 13:54:18 +00:00
languageSelector.innerHTML = Object.keys(locales).map(l=>{
var locale = locales[l];
2024-08-07 13:57:40 +00:00
var name = l === lastUploadedLocaleID ? `Custom locale based on ${locale.lang}` : locale.lang;
var localeParts = locale.lang.split("_"); // en_GB -> ["en","GB"]
2023-09-11 13:54:18 +00:00
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) )+" ";
2024-08-07 13:57:40 +00:00
return `< option value = "${l}" > ${icon}${name}${locale.notes?" - "+locale.notes:""}< / option > `
2023-09-11 13:54:18 +00:00
}).join("\n");
2024-08-07 13:57:40 +00:00
if(lastUploadedLocale){
if(lastUploadedLocale.custom){
// If the last uploaded locale was customized, choose the custom locale as default value
languageSelector.value = lastUploadedLocaleID;
}else{
// If the last uploaded locale was not customized, choose the existing locale in the list as the default value
languageSelector.value = lastUploadedLocale.lang;
}
}
languageSelector.addEventListener('change', handleLanguageChange);
function handleLanguageChange(){
lang = languageSelector.value;
locale = structuredClone(locales[lang]);
// If the locale is customized, make sure the customization option is activated. If not, disable it.
if(Boolean(customizeSelector.checked) !== Boolean(locale.custom)){
customizeSelector.checked = Boolean(locale.custom);
handleCustomizeChange();
}else{
createLocaleModule();
}
}
customizeSelector.addEventListener('change', handleCustomizeChange);
function handleCustomizeChange(){
2024-08-07 13:20:13 +00:00
customizeLocale = customizeSelector.checked;
2024-08-07 13:57:40 +00:00
// If the user no longer wants to customize, make sure to return to the default lang entry
if(!customizeLocale){
languageSelector.value = locales[lang].lang;
handleLanguageChange();
}else{
createLocaleModule();
}
}
// set initial values
handleLanguageChange();
2023-09-11 13:54:18 +00:00
document.getElementById("upload").addEventListener("click", function() {
2024-08-07 13:20:13 +00:00
var localeModule = createLocaleModule();
2020-03-04 16:42:44 +00:00
2024-08-07 13:57:40 +00:00
// Save the locale data to make it easier to upload the same locale next time.
// If the locale is not customized, only save the lang. The rest of the data will be added when the page loads next time.
const savedLocaleData = customizeLocale ? {...locale, custom: true} : {lang: locale.lang};
localStorage?.setItem(lastUploadedLocaleID, JSON.stringify(savedLocaleData));
2020-06-06 20:26:07 +00:00
console.log("Locale Module is:",localeModule);
2020-03-04 16:42:44 +00:00
sendCustomizedApp({
storage:[
2020-09-01 13:43:54 +00:00
{name:"locale", url:"locale.js", content:localeModule}
2020-03-04 16:42:44 +00:00
]
});
});
< / script >
< / body >
< / html >