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