fixed translations set during module startup - use __t

This commit is contained in:
SPRINX0\prochazka
2025-10-30 10:37:06 +01:00
parent 70284ac440
commit 9884ace309
5 changed files with 23 additions and 10 deletions

View File

@@ -27,7 +27,7 @@
import SettingsListener from './utility/SettingsListener.svelte';
import { handleAuthOnStartup } from './clientAuth';
import { initializeAppUpdates } from './utility/appUpdate';
import { _t } from './translations';
import { _t, saveSelectedLanguageToCache } from './translations';
import { installCloudListeners } from './utility/cloudListeners';
export let isAdminPage = false;
@@ -61,6 +61,7 @@
initializeAppUpdates();
installCloudListeners();
refreshPublicCloudFiles();
saveSelectedLanguageToCache();
}
loadedApi = loadedApiValue;

View File

@@ -10,8 +10,8 @@ export interface GlobalCommand {
id: string;
category: string; // null for group commands
isGroupCommand?: boolean;
name: string;
text?: string /* category: name */;
name: string | (() => string);
text?: string | (() => string);
keyText?: string;
keyTextFromGroup?: string; // automatically filled from group
group?: string;
@@ -27,7 +27,7 @@ export interface GlobalCommand {
menuName?: string;
toolbarOrder?: number;
disableHandleKeyText?: string;
isRelatedToTab?: boolean,
isRelatedToTab?: boolean;
systemCommand?: boolean;
}

View File

@@ -152,7 +152,7 @@
id: 'dataGrid.editJsonDocument',
category: 'Data grid',
keyText: 'CtrlOrCommand+J',
name: _t('command.datagrid.editJsonDocument', { defaultMessage: 'Edit row as JSON document' }),
name: __t('command.datagrid.editJsonDocument', { defaultMessage: 'Edit row as JSON document' }),
testEnabled: () => getCurrentDataGrid()?.editJsonEnabled(),
onClick: () => getCurrentDataGrid().editJsonDocument(),
});
@@ -421,7 +421,7 @@
import { openJsonLinesData } from '../utility/openJsonLinesData';
import contextMenuActivator from '../utility/contextMenuActivator';
import InputTextModal from '../modals/InputTextModal.svelte';
import { _t } from '../translations';
import { __t, _t } from '../translations';
import { isProApp } from '../utility/proTools';
import SaveArchiveModal from '../modals/SaveArchiveModal.svelte';
import hasPermission from '../utility/hasPermission';

View File

@@ -15,15 +15,22 @@ const compiledMessages: Partial<Record<string, Record<string, MessageFunction<'s
const defaultLanguage = 'en';
let selectedLanguageCache: string | null = null;
export function getSelectedLanguage(): string {
const borwserLanguage = getBrowserLanguage();
const selectedLanguage = getStringSettingsValue('localization.language', borwserLanguage);
if (selectedLanguageCache) return selectedLanguageCache;
const browserLanguage = getBrowserLanguage();
const selectedLanguage = getStringSettingsValue('localization.language', browserLanguage);
if (!supportedLanguages.includes(selectedLanguage)) return defaultLanguage;
return selectedLanguage;
}
export function saveSelectedLanguageToCache() {
selectedLanguageCache = getSelectedLanguage();
}
export function getBrowserLanguage(): string {
return 'en';
// if (typeof window !== 'undefined') {
@@ -70,3 +77,7 @@ export function _t(key: string, options: TranslateOptions): string {
return compliledTranslation(values ?? {});
}
export function __t(key: string, options: TranslateOptions): () => string {
return () => _t(key, options);
}

View File

@@ -112,8 +112,9 @@ function mapItem(item, commands) {
if (item.command) {
const command = commands[item.command];
if (command) {
const commandText = item.text || command.menuName || command.toolbarName || command.name;
return {
text: item.text || command.menuName || command.toolbarName || command.name,
text: _.isFunction(commandText) ? commandText() : commandText,
keyText: command.keyText || command.keyTextFromGroup || command.disableHandleKeyText,
onClick: () => {
if (command.isGroupCommand) {