mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
translated electron menu
This commit is contained in:
@@ -31,8 +31,14 @@ let mainModule;
|
||||
let appUpdateStatus = '';
|
||||
let settingsJson = {};
|
||||
|
||||
function _t(key, { defaultMessage } = {}) {
|
||||
return global.TRANSLATION_DATA?.[key] || defaultMessage;
|
||||
function getTranslated(key) {
|
||||
if (typeof key === 'string' && global.TRANSLATION_DATA?.[key]) {
|
||||
return global.TRANSLATION_DATA?.[key];
|
||||
}
|
||||
if (typeof key?._transKey === 'string') {
|
||||
return global.TRANSLATION_DATA?.[key._transKey] ?? key._transOptions?.defaultMessage;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
process.on('uncaughtException', function (error) {
|
||||
@@ -96,9 +102,14 @@ function commandItem(item, disableAll = false) {
|
||||
if (item.skipInApp) {
|
||||
return { skip: true };
|
||||
}
|
||||
if (!command) {
|
||||
return { skip: true };
|
||||
}
|
||||
return {
|
||||
id,
|
||||
label: command ? _t(command.menuName) || _t(command.toolbarName) || command.name : id,
|
||||
label: command
|
||||
? getTranslated(command.menuName) || getTranslated(command.toolbarName) || getTranslated(command.name)
|
||||
: id,
|
||||
accelerator: formatKeyText(command ? command.keyText : undefined),
|
||||
enabled: command ? command.enabled && (!disableAll || command.systemCommand) : false,
|
||||
click() {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Link from '../elements/Link.svelte';
|
||||
import { focusedConnectionOrDatabase } from '../stores';
|
||||
import { tick } from 'svelte';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
export let list;
|
||||
export let module;
|
||||
@@ -41,12 +41,12 @@
|
||||
|
||||
$: listTranslated = (list || []).map(data => ({
|
||||
...data,
|
||||
group: data?.group && _val(data.group),
|
||||
title: data?.title && _val(data.title),
|
||||
description: data?.description && _val(data.description),
|
||||
group: data?.group && _tval(data.group),
|
||||
title: data?.title && _tval(data.title),
|
||||
description: data?.description && _tval(data.description),
|
||||
args: (data?.args || []).map(x => ({
|
||||
...x,
|
||||
label: x?.label && _val(x.label),
|
||||
label: x?.label && _tval(x.label),
|
||||
})),
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" context="module">
|
||||
import { copyTextToClipboard } from '../utility/clipboard';
|
||||
import { _t, _val } from '../translations';
|
||||
import { _t, _tval, DefferedTranslationResult } from '../translations';
|
||||
|
||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||
export const createMatcher =
|
||||
@@ -76,7 +76,7 @@
|
||||
}
|
||||
|
||||
interface DbObjMenuItem {
|
||||
label?: string | (() => string);
|
||||
label?: string | DefferedTranslationResult;
|
||||
tab?: string;
|
||||
forceNewTab?: boolean;
|
||||
initialData?: any;
|
||||
@@ -722,7 +722,7 @@
|
||||
if (!item) return item;
|
||||
|
||||
return {...item,
|
||||
label: _val(item.label)
|
||||
label: _tval(item.label)
|
||||
};
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script context="module">
|
||||
function getCommandTitle(command) {
|
||||
let res = _val(command.text);
|
||||
let res = _tval(command.text);
|
||||
if (command.keyText || command.keyTextFromGroup) {
|
||||
res += ` (${formatKeyText(command.keyText || command.keyTextFromGroup)})`;
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
import { formatKeyText } from '../utility/common';
|
||||
import ToolStripButton from './ToolStripButton.svelte';
|
||||
import _ from 'lodash';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
export let command;
|
||||
export let component = ToolStripButton;
|
||||
@@ -34,6 +34,6 @@
|
||||
{iconAfter}
|
||||
{...$$restProps}
|
||||
>
|
||||
{(_val(buttonLabel) || _val(cmd?.toolbarName) || _val(cmd?.name))}
|
||||
{(_tval(buttonLabel) || _tval(cmd?.toolbarName) || _tval(cmd?.name))}
|
||||
</svelte:component>
|
||||
{/if}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import ToolStripCommandButton from './ToolStripCommandButton.svelte';
|
||||
import ToolStripDropDownButton from './ToolStripDropDownButton.svelte';
|
||||
import _ from 'lodash';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
export let quickExportHandlerRef = null;
|
||||
export let command = 'sqlDataGrid.export';
|
||||
export let label = 'Export';
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
{#if hasPermission('dbops/export')}
|
||||
{#if quickExportHandlerRef}
|
||||
<ToolStripDropDownButton menu={getExportMenu} label={_val(label)} icon="icon export" />
|
||||
<ToolStripDropDownButton menu={getExportMenu} label={_tval(label)} icon="icon export" />
|
||||
{:else}
|
||||
<ToolStripCommandButton {command} />
|
||||
{/if}
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
import { getLocalStorage } from '../utility/storageCache';
|
||||
import registerCommand from './registerCommand';
|
||||
import { formatKeyText, switchCurrentDatabase } from '../utility/common';
|
||||
import { _val, __t } from '../translations';
|
||||
import { _tval, __t } from '../translations';
|
||||
|
||||
let domInput;
|
||||
let filter = '';
|
||||
@@ -118,7 +118,7 @@
|
||||
: sortedComands
|
||||
).filter(x => !x.isGroupCommand),
|
||||
{
|
||||
extract: x => _val(x.text),
|
||||
extract: x => _tval(x.text),
|
||||
pre: '<b>',
|
||||
post: '</b>',
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { commands } from '../stores';
|
||||
import { invalidateCommandDefinitions } from './invalidateCommands';
|
||||
import _ from 'lodash';
|
||||
import { _val } from '../translations';
|
||||
import { _tval, DefferedTranslationResult, isDefferedTranslationResult } from '../translations';
|
||||
|
||||
export interface SubCommand {
|
||||
text: string;
|
||||
@@ -10,10 +10,10 @@ export interface SubCommand {
|
||||
|
||||
export interface GlobalCommand {
|
||||
id: string;
|
||||
category: string | (() => string); // null for group commands
|
||||
category: string | DefferedTranslationResult; // null for group commands
|
||||
isGroupCommand?: boolean;
|
||||
name: string | (() => string);
|
||||
text?: string | (() => string);
|
||||
name: string | DefferedTranslationResult;
|
||||
text?: string | DefferedTranslationResult;
|
||||
keyText?: string;
|
||||
keyTextFromGroup?: string; // automatically filled from group
|
||||
group?: string;
|
||||
@@ -25,8 +25,8 @@ export interface GlobalCommand {
|
||||
toolbar?: boolean;
|
||||
enabled?: boolean;
|
||||
showDisabled?: boolean;
|
||||
toolbarName?: string | (() => string);
|
||||
menuName?: string | (() => string);
|
||||
toolbarName?: string | DefferedTranslationResult;
|
||||
menuName?: string | DefferedTranslationResult;
|
||||
toolbarOrder?: number;
|
||||
disableHandleKeyText?: string;
|
||||
isRelatedToTab?: boolean;
|
||||
@@ -44,8 +44,8 @@ export default function registerCommand(command: GlobalCommand) {
|
||||
...x,
|
||||
[command.id]: {
|
||||
text:
|
||||
_.isFunction(command.category) || _.isFunction(command.name)
|
||||
? () => `${_val(command.category)}: ${_val(command.name)}`
|
||||
isDefferedTranslationResult(command.category) || isDefferedTranslationResult(command.name)
|
||||
? () => `${_tval(command.category)}: ${_tval(command.name)}`
|
||||
: `${command.category}: ${command.name}`,
|
||||
...command,
|
||||
enabled: !testEnabled,
|
||||
|
||||
@@ -422,7 +422,7 @@
|
||||
import { openJsonLinesData } from '../utility/openJsonLinesData';
|
||||
import contextMenuActivator from '../utility/contextMenuActivator';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import { __t, _t, _val } from '../translations';
|
||||
import { __t, _t, _tval } from '../translations';
|
||||
import { isProApp } from '../utility/proTools';
|
||||
import SaveArchiveModal from '../modals/SaveArchiveModal.svelte';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
@@ -1799,12 +1799,12 @@
|
||||
text: _t('datagrid.copyAdvanced', { defaultMessage: 'Copy advanced'}),
|
||||
submenu: [
|
||||
_.keys(copyRowsFormatDefs).map(format => ({
|
||||
text: _val(copyRowsFormatDefs[format].label),
|
||||
text: _tval(copyRowsFormatDefs[format].label),
|
||||
onClick: () => copyToClipboardCore(format),
|
||||
})),
|
||||
{ divider: true },
|
||||
_.keys(copyRowsFormatDefs).map(format => ({
|
||||
text: _t('datagrid.setFormat', { defaultMessage: 'Set format: ' }) + (_val(copyRowsFormatDefs[format].name)),
|
||||
text: _t('datagrid.setFormat', { defaultMessage: 'Set format: ' }) + (_tval(copyRowsFormatDefs[format].name)),
|
||||
onClick: () => ($copyRowsFormat = format),
|
||||
})),
|
||||
|
||||
@@ -1874,7 +1874,7 @@
|
||||
return [
|
||||
menu,
|
||||
{
|
||||
text: _val(copyRowsFormatDefs[$copyRowsFormat].label),
|
||||
text: _tval(copyRowsFormatDefs[$copyRowsFormat].label),
|
||||
onClick: () => copyToClipboardCore($copyRowsFormat),
|
||||
keyText: 'CtrlOrCommand+C',
|
||||
tag: 'copy',
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
import { evaluateCondition } from 'dbgate-sqltree';
|
||||
import { compileCompoudEvalCondition } from 'dbgate-filterparser';
|
||||
import { chevronExpandIcon } from '../icons/expandIcons';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
export let columns: (TableControlColumn | false)[];
|
||||
export let rows = null;
|
||||
@@ -369,7 +369,7 @@
|
||||
{/if}
|
||||
{/key}
|
||||
{:else}
|
||||
{ _val(row[col.fieldName]) || '' }
|
||||
{ _tval(row[col.fieldName]) || '' }
|
||||
{/if}
|
||||
</td>
|
||||
{/each}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { getFormContext } from './FormProviderCore.svelte';
|
||||
import TextField from './TextField.svelte';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
export let name;
|
||||
export let defaultValue;
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<TextField
|
||||
{...$$restProps}
|
||||
value={$values?.[name] ? _val($values[name]) : defaultValue}
|
||||
value={$values?.[name] ? _tval($values[name]) : defaultValue}
|
||||
on:input={e => setFieldValue(name, e.target['value'])}
|
||||
on:input={e => {
|
||||
if (saveOnInput) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||
import SelectField from '../forms/SelectField.svelte';
|
||||
import { lastUsedDefaultActions } from '../stores';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
export let label;
|
||||
export let objectTypeField;
|
||||
@@ -19,7 +19,7 @@
|
||||
defaultValue={defaultDatabaseObjectAppObjectActions[objectTypeField][0]?.defaultActionId}
|
||||
options={defaultDatabaseObjectAppObjectActions[objectTypeField].map(x => ({
|
||||
value: x.defaultActionId,
|
||||
label: _val(x.label),
|
||||
label: _tval(x.label),
|
||||
}))}
|
||||
value={$lastUsedDefaultActions[objectTypeField]}
|
||||
on:change={e => {
|
||||
|
||||
@@ -83,10 +83,27 @@ export function _t(key: string, options: TranslateOptions): string {
|
||||
return compliledTranslation(values ?? {});
|
||||
}
|
||||
|
||||
export function __t(key: string, options: TranslateOptions): () => string {
|
||||
return () => _t(key, options);
|
||||
export type DefferedTranslationResult = {
|
||||
_transKey: string;
|
||||
_transOptions: TranslateOptions;
|
||||
};
|
||||
|
||||
export function __t(key: string, options: TranslateOptions): DefferedTranslationResult {
|
||||
return {
|
||||
_transKey: key,
|
||||
_transOptions: options,
|
||||
};
|
||||
}
|
||||
|
||||
export function _val<T>(x: T | (() => T)): T {
|
||||
return typeof x === 'function' ? (x as () => T)() : x;
|
||||
export function _tval(x: string | DefferedTranslationResult): string {
|
||||
if (typeof x === 'string') return x;
|
||||
if (typeof x?._transKey === 'string') {
|
||||
return _t(x._transKey, x._transOptions);
|
||||
}
|
||||
}
|
||||
|
||||
export function isDefferedTranslationResult(
|
||||
x: string | DefferedTranslationResult
|
||||
): x is DefferedTranslationResult {
|
||||
return typeof x !== 'string' && typeof x?._transKey === 'string';
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import invalidateCommands from '../commands/invalidateCommands';
|
||||
import { runGroupCommand } from '../commands/runCommand';
|
||||
import { currentDropDownMenu, visibleCommandPalette } from '../stores';
|
||||
import getAsArray from './getAsArray';
|
||||
import { _val } from '../translations';
|
||||
import { _tval } from '../translations';
|
||||
|
||||
let isContextMenuSupressed = false;
|
||||
|
||||
@@ -115,7 +115,7 @@ function mapItem(item, commands) {
|
||||
if (command) {
|
||||
const commandText = item.text || command.menuName || command.toolbarName || command.name;
|
||||
return {
|
||||
text: _val(commandText),
|
||||
text: _tval(commandText),
|
||||
keyText: command.keyText || command.keyTextFromGroup || command.disableHandleKeyText,
|
||||
onClick: () => {
|
||||
if (command.isGroupCommand) {
|
||||
|
||||
Reference in New Issue
Block a user