mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-06 08:02:04 +00:00
The languages were listed in about ten places: the Lang type, the menu, the locale map, the stored-value check, the loaders, defineMessages, the docs links, the first-paint script, the Vite config and three Node tools. src/i18n/languages.ts now holds them, the build injects the locales into tools/stamp.js, and the tools parse the file through tools/languages.mjs. Chunks, detection and the stored key are unchanged.
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
// Normalize appearance before first paint. The build fills the palette list and default from src/shell/palettes.ts, the
|
|
// language locales and default from src/i18n/languages.ts, and the right-to-left scripts from src/i18n/direction.ts.
|
|
(function () {
|
|
var read = function (key) {
|
|
try {
|
|
return localStorage.getItem(key);
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
var scheme = read('doona-scheme');
|
|
var palette = read('doona-palette');
|
|
var lang = read('doona-lang');
|
|
var d = document.documentElement;
|
|
var dark = scheme === 'dark' || (scheme !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
var palettes = '__PALETTES__';
|
|
var parts = (palettes.includes(palette) ? palette : '__DEFAULT_PALETTE__').split('/');
|
|
d.dataset.scheme = dark ? 'dark' : 'light';
|
|
d.dataset.family = parts[0];
|
|
d.dataset.flavour = parts[1];
|
|
d.dataset.wordmark = read('doona-wordmark') === 'plain' ? 'plain' : 'gradient';
|
|
var locales = '__LOCALES__';
|
|
d.lang = Object.hasOwn(locales, lang) ? locales[lang] : '__DEFAULT_LOCALE__';
|
|
// The direction as pageDirection in src/i18n/direction.ts decides it: right to left in the mirrored layout, else the
|
|
// locale's text info, else its likely script.
|
|
var mirrored = read('doona-mirror') === 'on';
|
|
var rtlScripts = '__RTL_SCRIPTS__';
|
|
var dir = mirrored ? 'rtl' : 'ltr';
|
|
if (!mirrored)
|
|
try {
|
|
var tag = new Intl.Locale(d.lang);
|
|
var info = tag.getTextInfo ? tag.getTextInfo() : tag.textInfo;
|
|
if (info && info.direction ? info.direction === 'rtl' : rtlScripts.includes(tag.maximize().script)) dir = 'rtl';
|
|
} catch {
|
|
// Left to right.
|
|
}
|
|
d.dir = dir;
|
|
if (mirrored) d.dataset.mirror = '';
|
|
})();
|