mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 18:26:00 +00:00
fixed translations set during module startup - use __t
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
import SettingsListener from './utility/SettingsListener.svelte';
|
import SettingsListener from './utility/SettingsListener.svelte';
|
||||||
import { handleAuthOnStartup } from './clientAuth';
|
import { handleAuthOnStartup } from './clientAuth';
|
||||||
import { initializeAppUpdates } from './utility/appUpdate';
|
import { initializeAppUpdates } from './utility/appUpdate';
|
||||||
import { _t } from './translations';
|
import { _t, saveSelectedLanguageToCache } from './translations';
|
||||||
import { installCloudListeners } from './utility/cloudListeners';
|
import { installCloudListeners } from './utility/cloudListeners';
|
||||||
|
|
||||||
export let isAdminPage = false;
|
export let isAdminPage = false;
|
||||||
@@ -61,6 +61,7 @@
|
|||||||
initializeAppUpdates();
|
initializeAppUpdates();
|
||||||
installCloudListeners();
|
installCloudListeners();
|
||||||
refreshPublicCloudFiles();
|
refreshPublicCloudFiles();
|
||||||
|
saveSelectedLanguageToCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedApi = loadedApiValue;
|
loadedApi = loadedApiValue;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ export interface GlobalCommand {
|
|||||||
id: string;
|
id: string;
|
||||||
category: string; // null for group commands
|
category: string; // null for group commands
|
||||||
isGroupCommand?: boolean;
|
isGroupCommand?: boolean;
|
||||||
name: string;
|
name: string | (() => string);
|
||||||
text?: string /* category: name */;
|
text?: string | (() => string);
|
||||||
keyText?: string;
|
keyText?: string;
|
||||||
keyTextFromGroup?: string; // automatically filled from group
|
keyTextFromGroup?: string; // automatically filled from group
|
||||||
group?: string;
|
group?: string;
|
||||||
@@ -27,7 +27,7 @@ export interface GlobalCommand {
|
|||||||
menuName?: string;
|
menuName?: string;
|
||||||
toolbarOrder?: number;
|
toolbarOrder?: number;
|
||||||
disableHandleKeyText?: string;
|
disableHandleKeyText?: string;
|
||||||
isRelatedToTab?: boolean,
|
isRelatedToTab?: boolean;
|
||||||
systemCommand?: boolean;
|
systemCommand?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@
|
|||||||
id: 'dataGrid.editJsonDocument',
|
id: 'dataGrid.editJsonDocument',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
keyText: 'CtrlOrCommand+J',
|
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(),
|
testEnabled: () => getCurrentDataGrid()?.editJsonEnabled(),
|
||||||
onClick: () => getCurrentDataGrid().editJsonDocument(),
|
onClick: () => getCurrentDataGrid().editJsonDocument(),
|
||||||
});
|
});
|
||||||
@@ -421,7 +421,7 @@
|
|||||||
import { openJsonLinesData } from '../utility/openJsonLinesData';
|
import { openJsonLinesData } from '../utility/openJsonLinesData';
|
||||||
import contextMenuActivator from '../utility/contextMenuActivator';
|
import contextMenuActivator from '../utility/contextMenuActivator';
|
||||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
import { _t } from '../translations';
|
import { __t, _t } from '../translations';
|
||||||
import { isProApp } from '../utility/proTools';
|
import { isProApp } from '../utility/proTools';
|
||||||
import SaveArchiveModal from '../modals/SaveArchiveModal.svelte';
|
import SaveArchiveModal from '../modals/SaveArchiveModal.svelte';
|
||||||
import hasPermission from '../utility/hasPermission';
|
import hasPermission from '../utility/hasPermission';
|
||||||
|
|||||||
@@ -15,15 +15,22 @@ const compiledMessages: Partial<Record<string, Record<string, MessageFunction<'s
|
|||||||
|
|
||||||
const defaultLanguage = 'en';
|
const defaultLanguage = 'en';
|
||||||
|
|
||||||
|
let selectedLanguageCache: string | null = null;
|
||||||
|
|
||||||
export function getSelectedLanguage(): string {
|
export function getSelectedLanguage(): string {
|
||||||
const borwserLanguage = getBrowserLanguage();
|
if (selectedLanguageCache) return selectedLanguageCache;
|
||||||
const selectedLanguage = getStringSettingsValue('localization.language', borwserLanguage);
|
|
||||||
|
const browserLanguage = getBrowserLanguage();
|
||||||
|
const selectedLanguage = getStringSettingsValue('localization.language', browserLanguage);
|
||||||
|
|
||||||
if (!supportedLanguages.includes(selectedLanguage)) return defaultLanguage;
|
if (!supportedLanguages.includes(selectedLanguage)) return defaultLanguage;
|
||||||
|
|
||||||
return selectedLanguage;
|
return selectedLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function saveSelectedLanguageToCache() {
|
||||||
|
selectedLanguageCache = getSelectedLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
export function getBrowserLanguage(): string {
|
export function getBrowserLanguage(): string {
|
||||||
return 'en';
|
return 'en';
|
||||||
// if (typeof window !== 'undefined') {
|
// if (typeof window !== 'undefined') {
|
||||||
@@ -70,3 +77,7 @@ export function _t(key: string, options: TranslateOptions): string {
|
|||||||
|
|
||||||
return compliledTranslation(values ?? {});
|
return compliledTranslation(values ?? {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function __t(key: string, options: TranslateOptions): () => string {
|
||||||
|
return () => _t(key, options);
|
||||||
|
}
|
||||||
|
|||||||
@@ -112,8 +112,9 @@ function mapItem(item, commands) {
|
|||||||
if (item.command) {
|
if (item.command) {
|
||||||
const command = commands[item.command];
|
const command = commands[item.command];
|
||||||
if (command) {
|
if (command) {
|
||||||
|
const commandText = item.text || command.menuName || command.toolbarName || command.name;
|
||||||
return {
|
return {
|
||||||
text: item.text || command.menuName || command.toolbarName || command.name,
|
text: _.isFunction(commandText) ? commandText() : commandText,
|
||||||
keyText: command.keyText || command.keyTextFromGroup || command.disableHandleKeyText,
|
keyText: command.keyText || command.keyTextFromGroup || command.disableHandleKeyText,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (command.isGroupCommand) {
|
if (command.isGroupCommand) {
|
||||||
|
|||||||
Reference in New Issue
Block a user