translated electron menu

This commit is contained in:
SPRINX0\prochazka
2025-11-18 12:29:48 +01:00
parent d80c368ccb
commit f047ec787a
13 changed files with 70 additions and 42 deletions

View File

@@ -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),
})),
}));

View File

@@ -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 {

View File

@@ -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}

View File

@@ -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}

View File

@@ -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>',
}

View File

@@ -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,

View File

@@ -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',

View File

@@ -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}

View File

@@ -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) {

View File

@@ -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 => {

View File

@@ -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';
}

View File

@@ -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) {