mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-23 00:06:18 -04:00
adjustments to add right-to-left language
This commit is contained in:
parent
8d0e560b1d
commit
117a4d3eb9
8 changed files with 240 additions and 62 deletions
|
@ -2,10 +2,12 @@ class Localization {
|
|||
constructor() {
|
||||
Localization.defaultLocale = "en";
|
||||
Localization.supportedLocales = ["en", "nb", "ru", "zh-CN", "de", "ro", "id", "fr"];
|
||||
Localization.supportedLocalesRTL = [];
|
||||
|
||||
Localization.translations = {};
|
||||
Localization.defaultTranslations = {};
|
||||
|
||||
Localization.systemLocale = Localization.supportedOrDefault(navigator.languages);
|
||||
Localization.systemLocale = Localization.getSupportedOrDefault(navigator.languages);
|
||||
|
||||
let storedLanguageCode = localStorage.getItem("language-code");
|
||||
|
||||
|
@ -24,7 +26,11 @@ class Localization {
|
|||
return Localization.supportedLocales.indexOf(locale) > -1;
|
||||
}
|
||||
|
||||
static supportedOrDefault(locales) {
|
||||
static isRTLLanguage(locale) {
|
||||
return Localization.supportedLocalesRTL.indexOf(locale) > -1;
|
||||
}
|
||||
|
||||
static getSupportedOrDefault(locales) {
|
||||
return locales.find(Localization.isSupported) || Localization.defaultLocale;
|
||||
}
|
||||
|
||||
|
@ -34,6 +40,17 @@ class Localization {
|
|||
await Localization.setLocale(locale)
|
||||
await Localization.translatePage();
|
||||
|
||||
const htmlRootNode = document.querySelector('html');
|
||||
|
||||
if (Localization.isRTLLanguage(locale)) {
|
||||
htmlRootNode.setAttribute('dir', 'rtl');
|
||||
} else {
|
||||
htmlRootNode.removeAttribute('dir');
|
||||
}
|
||||
|
||||
htmlRootNode.setAttribute('lang', locale);
|
||||
|
||||
|
||||
console.log("Page successfully translated",
|
||||
`System language: ${Localization.systemLocale}`,
|
||||
`Selected language: ${locale}`
|
||||
|
|
|
@ -398,7 +398,7 @@ class PeerUI {
|
|||
<div class="name font-subheading"></div>
|
||||
<div class="device-name font-body2"></div>
|
||||
<div class="status font-body2"></div>
|
||||
<span class="connection-hash font-body2" title="${ Localization.getTranslation("peer-ui.connection-hash") }"></span>
|
||||
<span class="connection-hash font-body2" dir="ltr" title="${ Localization.getTranslation("peer-ui.connection-hash") }"></span>
|
||||
</div>
|
||||
</label>`;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue