mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-11 00:02:28 -04:00
locale: fix locale override persisting even when not explicitly set
This commit is contained in:
@@ -8,7 +8,9 @@ import Quickshell.Io
|
|||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property string _rawLocale: SettingsData.locale === "" ? Qt.locale().name : SettingsData.locale
|
property string _resolvedLocale: "en"
|
||||||
|
|
||||||
|
readonly property string _rawLocale: SessionData.locale === "" ? Qt.locale().name : SessionData.locale
|
||||||
readonly property string _lang: _rawLocale.split(/[_-]/)[0]
|
readonly property string _lang: _rawLocale.split(/[_-]/)[0]
|
||||||
readonly property var _candidates: {
|
readonly property var _candidates: {
|
||||||
const fullUnderscore = _rawLocale;
|
const fullUnderscore = _rawLocale;
|
||||||
@@ -49,22 +51,21 @@ Singleton {
|
|||||||
try {
|
try {
|
||||||
root.translations = JSON.parse(text());
|
root.translations = JSON.parse(text());
|
||||||
root.translationsLoaded = true;
|
root.translationsLoaded = true;
|
||||||
console.info(`I18n: Loaded translations for '${SettingsData.locale}' (${Object.keys(root.translations).length} contexts)`);
|
console.info(`I18n: Loaded translations for '${root._resolvedLocale}' (${Object.keys(root.translations).length} contexts)`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`I18n: Error parsing '${SettingsData.locale}':`, e, "- falling back to English");
|
console.warn(`I18n: Error parsing '${root._resolvedLocale}':`, e, "- falling back to English");
|
||||||
root._fallbackToEnglish();
|
root._fallbackToEnglish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoadFailed: error => {
|
onLoadFailed: error => {
|
||||||
console.warn(`I18n: Failed to load '${SettingsData.locale}' (${error}), ` + "falling back to English");
|
console.warn(`I18n: Failed to load '${root._resolvedLocale}' (${error}), ` + "falling back to English");
|
||||||
root._fallbackToEnglish();
|
root._fallbackToEnglish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for replacing Qt.locale()
|
|
||||||
function locale() {
|
function locale() {
|
||||||
return presentLocales[SettingsData.locale] ?? presentLocales["en"];
|
return presentLocales[_resolvedLocale] ?? presentLocales["en"];
|
||||||
}
|
}
|
||||||
|
|
||||||
function _loadPresentLocales() {
|
function _loadPresentLocales() {
|
||||||
@@ -83,16 +84,18 @@ Singleton {
|
|||||||
function _pickTranslation() {
|
function _pickTranslation() {
|
||||||
for (let i = 0; i < _candidates.length; i++) {
|
for (let i = 0; i < _candidates.length; i++) {
|
||||||
const cand = _candidates[i];
|
const cand = _candidates[i];
|
||||||
if (presentLocales[cand] !== undefined) {
|
if (presentLocales[cand] === undefined) continue;
|
||||||
SettingsData.set("locale", cand);
|
_resolvedLocale = cand;
|
||||||
return;
|
useLocale(cand, cand.startsWith("en") ? "" : translationsFolder + "/" + cand + ".json");
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_resolvedLocale = "en";
|
||||||
_fallbackToEnglish();
|
_fallbackToEnglish();
|
||||||
}
|
}
|
||||||
|
|
||||||
function useLocale(localeTag, fileUrl) {
|
function useLocale(localeTag, fileUrl) {
|
||||||
|
_resolvedLocale = localeTag || "en";
|
||||||
_selectedPath = fileUrl;
|
_selectedPath = fileUrl;
|
||||||
translationsLoaded = false;
|
translationsLoaded = false;
|
||||||
translations = ({});
|
translations = ({});
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ Singleton {
|
|||||||
property bool _isReadOnly: false
|
property bool _isReadOnly: false
|
||||||
property bool _hasUnsavedChanges: false
|
property bool _hasUnsavedChanges: false
|
||||||
property var _loadedSessionSnapshot: null
|
property var _loadedSessionSnapshot: null
|
||||||
readonly property var _hooks: ({})
|
readonly property var _hooks: ({
|
||||||
|
"updateLocale": updateLocale
|
||||||
|
})
|
||||||
readonly property string _stateUrl: StandardPaths.writableLocation(StandardPaths.GenericStateLocation)
|
readonly property string _stateUrl: StandardPaths.writableLocation(StandardPaths.GenericStateLocation)
|
||||||
readonly property string _stateDir: Paths.strip(_stateUrl)
|
readonly property string _stateDir: Paths.strip(_stateUrl)
|
||||||
|
|
||||||
@@ -126,6 +128,8 @@ Singleton {
|
|||||||
property var hiddenOutputDeviceNames: []
|
property var hiddenOutputDeviceNames: []
|
||||||
property var hiddenInputDeviceNames: []
|
property var hiddenInputDeviceNames: []
|
||||||
|
|
||||||
|
property string locale: ""
|
||||||
|
|
||||||
property string launcherLastMode: "all"
|
property string launcherLastMode: "all"
|
||||||
property string appDrawerLastMode: "apps"
|
property string appDrawerLastMode: "apps"
|
||||||
property string niriOverviewLastMode: "apps"
|
property string niriOverviewLastMode: "apps"
|
||||||
@@ -1104,6 +1108,14 @@ Singleton {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateLocale() {
|
||||||
|
if (!locale) {
|
||||||
|
I18n._pickTranslation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
I18n.useLocale(locale, locale.startsWith("en") ? "" : I18n.folder + "/" + locale + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
function setLauncherLastMode(mode) {
|
function setLauncherLastMode(mode) {
|
||||||
launcherLastMode = mode;
|
launcherLastMode = mode;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ Singleton {
|
|||||||
property int mangoLayoutRadiusOverride: -1
|
property int mangoLayoutRadiusOverride: -1
|
||||||
property int mangoLayoutBorderSize: -1
|
property int mangoLayoutBorderSize: -1
|
||||||
|
|
||||||
property string locale: ""
|
|
||||||
property bool use24HourClock: true
|
property bool use24HourClock: true
|
||||||
property bool showSeconds: false
|
property bool showSeconds: false
|
||||||
property bool padHours12Hour: false
|
property bool padHours12Hour: false
|
||||||
@@ -1131,10 +1130,6 @@ Singleton {
|
|||||||
Quickshell.execDetached(["sh", "-lc", script]);
|
Quickshell.execDetached(["sh", "-lc", script]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLocale() {
|
|
||||||
I18n.useLocale(locale, locale.startsWith("en") ? "" : I18n.folder + "/" + locale + ".json");
|
|
||||||
}
|
|
||||||
|
|
||||||
readonly property var _hooks: ({
|
readonly property var _hooks: ({
|
||||||
"applyStoredTheme": applyStoredTheme,
|
"applyStoredTheme": applyStoredTheme,
|
||||||
"regenSystemThemes": regenSystemThemes,
|
"regenSystemThemes": regenSystemThemes,
|
||||||
@@ -1142,7 +1137,6 @@ Singleton {
|
|||||||
"applyStoredIconTheme": applyStoredIconTheme,
|
"applyStoredIconTheme": applyStoredIconTheme,
|
||||||
"updateBarConfigs": updateBarConfigs,
|
"updateBarConfigs": updateBarConfigs,
|
||||||
"updateCompositorCursor": updateCompositorCursor,
|
"updateCompositorCursor": updateCompositorCursor,
|
||||||
"updateLocale": updateLocale,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function set(key, value) {
|
function set(key, value) {
|
||||||
@@ -2646,7 +2640,6 @@ Singleton {
|
|||||||
_hasLoaded = true;
|
_hasLoaded = true;
|
||||||
applyStoredTheme();
|
applyStoredTheme();
|
||||||
updateCompositorCursor();
|
updateCompositorCursor();
|
||||||
updateLocale();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_parseError = true;
|
_parseError = true;
|
||||||
const msg = e.message;
|
const msg = e.message;
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ var SPEC = {
|
|||||||
hiddenOutputDeviceNames: { def: [] },
|
hiddenOutputDeviceNames: { def: [] },
|
||||||
hiddenInputDeviceNames: { def: [] },
|
hiddenInputDeviceNames: { def: [] },
|
||||||
|
|
||||||
|
locale: { def: "", onChange: "updateLocale" },
|
||||||
|
|
||||||
launcherLastMode: { def: "all" },
|
launcherLastMode: { def: "all" },
|
||||||
appDrawerLastMode: { def: "apps" },
|
appDrawerLastMode: { def: "apps" },
|
||||||
niriOverviewLastMode: { def: "apps" }
|
niriOverviewLastMode: { def: "apps" }
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ var SPEC = {
|
|||||||
mangoLayoutRadiusOverride: { def: -1, onChange: "updateCompositorLayout" },
|
mangoLayoutRadiusOverride: { def: -1, onChange: "updateCompositorLayout" },
|
||||||
mangoLayoutBorderSize: { def: -1, onChange: "updateCompositorLayout" },
|
mangoLayoutBorderSize: { def: -1, onChange: "updateCompositorLayout" },
|
||||||
|
|
||||||
locale: { def: "", onChange: "updateLocale" },
|
|
||||||
use24HourClock: { def: true },
|
use24HourClock: { def: true },
|
||||||
showSeconds: { def: false },
|
showSeconds: { def: false },
|
||||||
padHours12Hour: { def: false },
|
padHours12Hour: { def: false },
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import qs.Widgets
|
|||||||
import qs.Modules.Settings.Widgets
|
import qs.Modules.Settings.Widgets
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: localeTab
|
||||||
|
|
||||||
|
readonly property string _systemDefaultLabel: I18n.tr("System Default")
|
||||||
|
|
||||||
function capitalizeNativeLanguageName(localeCode) {
|
function capitalizeNativeLanguageName(localeCode) {
|
||||||
if (I18n.presentLocales[localeCode] == undefined) {
|
if (I18n.presentLocales[localeCode] == undefined) {
|
||||||
@@ -15,6 +17,11 @@ Item {
|
|||||||
return nativeName[0].toUpperCase() + nativeName.slice(1);
|
return nativeName[0].toUpperCase() + nativeName.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _displayValue() {
|
||||||
|
if (!SessionData.locale) return _systemDefaultLabel;
|
||||||
|
return capitalizeNativeLanguageName(SessionData.locale);
|
||||||
|
}
|
||||||
|
|
||||||
DankFlickable {
|
DankFlickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
clip: true
|
clip: true
|
||||||
@@ -41,17 +48,21 @@ Item {
|
|||||||
settingKey: "locale"
|
settingKey: "locale"
|
||||||
text: I18n.tr("Current Locale")
|
text: I18n.tr("Current Locale")
|
||||||
description: I18n.tr("Change the locale used by the DMS interface.")
|
description: I18n.tr("Change the locale used by the DMS interface.")
|
||||||
options: Object.keys(I18n.presentLocales).map(root.capitalizeNativeLanguageName)
|
options: [localeTab._systemDefaultLabel].concat(Object.keys(I18n.presentLocales).map(localeTab.capitalizeNativeLanguageName))
|
||||||
enableFuzzySearch: true
|
enableFuzzySearch: true
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
currentValue = root.capitalizeNativeLanguageName(SettingsData.locale);
|
currentValue = localeTab._displayValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
onValueChanged: value => {
|
onValueChanged: value => {
|
||||||
|
if (value === localeTab._systemDefaultLabel) {
|
||||||
|
SessionData.set("locale", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (let code of Object.keys(I18n.presentLocales)) {
|
for (let code of Object.keys(I18n.presentLocales)) {
|
||||||
if (root.capitalizeNativeLanguageName(code) === value) {
|
if (localeTab.capitalizeNativeLanguageName(code) === value) {
|
||||||
SettingsData.set("locale", code);
|
SessionData.set("locale", code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user