downthemall/windows/manager/removaldlg.ts
Nils Maier 8235af22db Implement own locale loader
Why?
* Because i18n sucks multi-browser, especially on Chrome.
* What's more, this will allow overlaying "incomplete" locales with
  missing strings over the base locale and get a semi-translated one,
  which probably is better than nothing.
* Additionally we kinda need that implementation anyway for node-based
  tests.
* Also, while not currently implemented, it could allow (hot) reloading
  of locales, or loading external ones, which would help translators,
  or providing an option to the user to choose a locale.
* And finally, not calling i18n will avoid the "context switch" into
  browserland.

Some implementation details:
* Before code can use a locale, it has to be loaded. Sadly sync loading
  is not really supported. So `await locale` or `await localize`.
* Background force reloads locales right now, and caches them in
  localStorage. Windows will look into localStorage for that cache.
* The locale loader will not verify locales other than some rudimentary
  checks. It is assumed that shipped locales where verified before
  check-in.
2019-08-26 02:37:27 +02:00

71 lines
1.5 KiB
TypeScript

"use strict";
// License: MIT
import ModalDialog from "../../uikit/lib/modal";
import { _, localize } from "../../lib/i18n";
import { Prefs } from "../../lib/prefs";
import { Keys } from "../keys";
import { $ } from "../winutil";
export default class RemovalModalDialog extends ModalDialog {
private readonly text: string;
private readonly pref: string;
private check: HTMLInputElement | null;
constructor(text: string, pref: string) {
super();
this.text = text;
this.pref = `confirmations.${pref}`;
this.check = null;
}
async getContent() {
const content = $<HTMLTemplateElement>("#removal-template").
content.cloneNode(true) as DocumentFragment;
await localize(content);
this.check = content.querySelector(".removal-remember");
$(".removal-text", content).textContent = this.text;
return content;
}
get buttons() {
return [
{
title: _("remove-downloads"),
value: "ok",
default: true,
dismiss: false,
},
{
title: _("cancel"),
value: "cancel",
default: false,
dismiss: true,
}
];
}
async show() {
if (await Prefs.get(this.pref)) {
return "ok";
}
Keys.suppressed = true;
try {
const res = await super.show();
if (this.check && this.check.checked) {
await Prefs.set(this.pref, true);
}
return res;
}
finally {
Keys.suppressed = false;
}
}
shown() {
this.focusDefault();
}
}