EventMapper/assets/scripts/KaplayMap/lang.js

45 lines
957 B
JavaScript

import localization from "./localization.js";
export class LangManager {
#lang;
#units = {
year: 24 * 60 * 60 * 1000 * 365,
month: (24 * 60 * 60 * 1000 * 365) / 12,
week: 7 * 24 * 60 * 60 * 1000,
day: 24 * 60 * 60 * 1000,
hour: 60 * 60 * 1000,
minute: 60 * 1000,
second: 1000,
};
constructor(lang) {
this.#lang = lang;
}
get currentLocalization() {
return localization.get(this.#lang);
}
get langCode() {
return this.#lang;
}
getTimeDuration(d1, d2) {
let elapsed = d2 - d1;
for (var u in this.#units)
if (Math.abs(elapsed) > this.#units[u] || u == "second") {
let currentUnit = this.currentLocalization.time_units[u];
return currentUnit(Math.round(elapsed / this.#units[u]));
}
}
formatList(items) {
const formatter = new Intl.ListFormat("en", {
style: "long",
type: "conjunction",
});
return formatter.format(items);
}
}