UBERF-7446 & UBERF-7447: i18n fixes (#5975)

This commit is contained in:
Vyacheslav Tumanov 2024-07-02 16:11:11 +05:00 committed by GitHub
parent 9cd9233685
commit 3dd78b5856
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 72 additions and 40 deletions

View File

@ -33,7 +33,7 @@ type Messages = Record<string, IntlString | Record<string, IntlString>>
const loaders = new Map<Plugin, Loader>() const loaders = new Map<Plugin, Loader>()
const translations = new Map<Plugin, Messages | Status>() const translations = new Map<Plugin, Messages | Status>()
const cache = new Map<IntlString, IntlMessageFormat | Status>() const cache = new Map<IntlString, IntlMessageFormat | Status>()
const englishTranslationsForMissing = new Map<Plugin, Messages | Status>()
/** /**
* @public * @public
* @param plugin - * @param plugin -
@ -91,9 +91,23 @@ async function getTranslation (id: _IdInfo, locale: string): Promise<IntlString
if (messages instanceof Status) { if (messages instanceof Status) {
return messages return messages
} }
return id.kind !== undefined if (id.kind !== undefined) {
? (messages[id.kind] as Record<string, IntlString>)?.[id.name] if ((messages[id.kind] as Record<string, IntlString>)?.[id.name] !== undefined) {
: (messages[id.name] as IntlString) return (messages[id.kind] as Record<string, IntlString>)?.[id.name]
} else {
let eng = englishTranslationsForMissing.get(id.component)
if (eng === undefined) {
eng = await loadTranslationsForComponent(id.component, 'en')
englishTranslationsForMissing.set(id.component, eng)
}
if (eng instanceof Status) {
return eng
}
return (eng[id.kind] as Record<string, IntlString>)?.[id.name]
}
} else {
return messages[id.name] as IntlString
}
} catch (err) { } catch (err) {
const status = unknownError(err) const status = unknownError(err)
await setPlatformStatus(status) await setPlatformStatus(status)

View File

@ -51,6 +51,6 @@
"Unset": "Убрать", "Unset": "Убрать",
"Image": "Изображение", "Image": "Изображение",
"SeparatorLine": "Разделительная линия", "SeparatorLine": "Разделительная линия",
"TodoList": "Action item" "TodoList": "Действие"
} }
} }

View File

@ -167,6 +167,15 @@
let placeHolderStr: string = '' let placeHolderStr: string = ''
$: ph = translate(placeholder, {}, $themeStore.language).then((r) => { $: ph = translate(placeholder, {}, $themeStore.language).then((r) => {
if (editor !== undefined && placeHolderStr !== r) {
const placeholderIndex = editor.extensionManager.extensions.findIndex(
(extension) => extension.name === 'placeholder'
)
if (placeholderIndex !== -1) {
editor.extensionManager.extensions[placeholderIndex].options.placeholder = r
editor.view.dispatch(editor.state.tr)
}
}
placeHolderStr = r placeHolderStr = r
}) })

View File

@ -55,6 +55,15 @@
let placeHolderStr: string = '' let placeHolderStr: string = ''
$: ph = translate(placeholder, {}, $themeStore.language).then((r) => { $: ph = translate(placeholder, {}, $themeStore.language).then((r) => {
if (editor !== undefined && placeHolderStr !== r) {
const placeholderIndex = editor.extensionManager.extensions.findIndex(
(extension) => extension.name === 'placeholder'
)
if (placeholderIndex !== -1) {
editor.extensionManager.extensions[placeholderIndex].options.placeholder = r
editor.view.dispatch(editor.state.tr)
}
}
placeHolderStr = r placeHolderStr = r
}) })

View File

@ -29,10 +29,10 @@
export let withSearch: boolean = true export let withSearch: boolean = true
let search: string = '' let search: string = ''
let phTraslate: string = '' let phTranslate: string = ''
$: if (placeholder) { $: if (placeholder) {
translate(placeholder, {}, $themeStore.language).then((res) => { translate(placeholder, {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
} }
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -82,7 +82,7 @@
bind:this={searchInput} bind:this={searchInput}
type="text" type="text"
bind:value={search} bind:value={search}
placeholder={phTraslate} placeholder={phTranslate}
on:input={(ev) => {}} on:input={(ev) => {}}
on:change on:change
/> />

View File

@ -44,7 +44,7 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let input: HTMLInputElement let input: HTMLInputElement
let phTraslate: string = '' let phTranslate: string = ''
$: { $: {
if ( if (
@ -57,7 +57,7 @@
} }
} }
$: void translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => { $: void translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
function handleInput (): void { function handleInput (): void {
@ -143,7 +143,7 @@
bind:this={input} bind:this={input}
type="Password" type="Password"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
on:input={handleInput} on:input={handleInput}
on:change on:change
on:keydown on:keydown
@ -160,7 +160,7 @@
type="number" type="number"
class="number" class="number"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
on:input={handleInput} on:input={handleInput}
on:change on:change
on:keydown on:keydown
@ -176,7 +176,7 @@
bind:this={input} bind:this={input}
type="text" type="text"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
on:input={handleInput} on:input={handleInput}
on:change on:change
on:keydown on:keydown

View File

@ -41,7 +41,7 @@
let text: HTMLElement let text: HTMLElement
let input: HTMLInputElement let input: HTMLInputElement
let style: string let style: string
let phTraslate: string = '' let phTranslate: string = ''
let parentWidth: number | undefined let parentWidth: number | undefined
$: { $: {
@ -59,7 +59,7 @@
} }
$: style = `max-width: ${maxWidth || (parentWidth ? `${parentWidth}px` : 'max-content')};` $: style = `max-width: ${maxWidth || (parentWidth ? `${parentWidth}px` : 'max-content')};`
$: translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => { $: translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
function computeSize (t: HTMLInputElement | EventTarget | null) { function computeSize (t: HTMLInputElement | EventTarget | null) {
@ -68,7 +68,7 @@
} }
const target = t as HTMLInputElement const target = t as HTMLInputElement
const value = target.value const value = target.value
text.innerHTML = (value === '' ? phTraslate : value) text.innerHTML = (value === '' ? phTranslate : value)
.replaceAll(' ', '&nbsp;') .replaceAll(' ', '&nbsp;')
.replaceAll('<', '&lt;') .replaceAll('<', '&lt;')
.replaceAll('>', '&gt;') .replaceAll('>', '&gt;')
@ -139,7 +139,7 @@
type="number" type="number"
class="number" class="number"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
{style} {style}
on:input={(ev) => { on:input={(ev) => {
if (ev.target) { if (ev.target) {

View File

@ -27,10 +27,10 @@
export let disabled: boolean = false export let disabled: boolean = false
let input: HTMLTextAreaElement let input: HTMLTextAreaElement
let phTraslate: string = '' let phTranslate: string = ''
$: void translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => { $: void translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
onMount(() => { onMount(() => {
@ -62,7 +62,7 @@
bind:value bind:value
bind:this={input} bind:this={input}
{disabled} {disabled}
placeholder={phTraslate} placeholder={phTranslate}
on:keydown on:keydown
on:change on:change
on:keydown on:keydown

View File

@ -30,10 +30,10 @@
export let disabled: boolean = false export let disabled: boolean = false
let input: HTMLTextAreaElement let input: HTMLTextAreaElement
let phTraslate: string = '' let phTranslate: string = ''
$: translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => { $: translate(placeholder, placeholderParam ?? {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
export function focus () { export function focus () {
@ -47,7 +47,7 @@
bind:value bind:value
bind:this={input} bind:this={input}
{disabled} {disabled}
placeholder={phTraslate} placeholder={phTranslate}
on:keydown on:keydown
on:change on:change
on:keydown on:keydown

View File

@ -40,12 +40,12 @@
let text: HTMLElement let text: HTMLElement
let input: HTMLInputElement let input: HTMLInputElement
let style: string let style: string
let phTraslate: string = '' let phTranslate: string = ''
let parentWidth: number | undefined let parentWidth: number | undefined
$: style = `max-width: ${maxWidth || (parentWidth ? `${parentWidth}px` : 'max-content')};` $: style = `max-width: ${maxWidth || (parentWidth ? `${parentWidth}px` : 'max-content')};`
$: translate(placeholder, {}, $themeStore.language).then((res) => { $: translate(placeholder, {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
function computeSize (t: HTMLInputElement | EventTarget | null) { function computeSize (t: HTMLInputElement | EventTarget | null) {
@ -54,7 +54,7 @@
} }
const target = t as HTMLInputElement const target = t as HTMLInputElement
const value = target.value const value = target.value
text.innerHTML = (value === '' ? phTraslate : value) text.innerHTML = (value === '' ? phTranslate : value)
.replaceAll(' ', '&nbsp;') .replaceAll(' ', '&nbsp;')
.replaceAll('<', '&lt;') .replaceAll('<', '&lt;')
.replaceAll('>', '&gt;') .replaceAll('>', '&gt;')
@ -201,7 +201,7 @@
bind:this={input} bind:this={input}
type="text" type="text"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
{style} {style}
on:input={(ev) => { on:input={(ev) => {
computeSize(ev.target) computeSize(ev.target)

View File

@ -46,11 +46,11 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let input: HTMLInputElement let input: HTMLInputElement
let phTraslate: string let phTranslate: string
$: translate(placeholder, {}, $themeStore.language).then((tr) => (phTraslate = tr)) $: translate(placeholder, {}, $themeStore.language).then((tr) => (phTranslate = tr))
let label: IntlString = plugin.string.CopyToClipboard let label: IntlString = plugin.string.CopyToClipboard
let lTraslate: string let lTranslate: string
$: translate(label, {}, $themeStore.language).then((tr) => (lTraslate = tr)) $: translate(label, {}, $themeStore.language).then((tr) => (lTranslate = tr))
let show: boolean = false let show: boolean = false
const copyChannel = (): void => { const copyChannel = (): void => {
@ -98,13 +98,13 @@
<FocusHandler manager={mgr} /> <FocusHandler manager={mgr} />
{#if editable} {#if editable}
<div class="editor-container {dir} buttons-group xsmall-gap"> <div class="editor-container {dir} buttons-group xsmall-gap">
<div class="cover-channel" class:show class:copied={label === view.string.Copied} data-tooltip={lTraslate}> <div class="cover-channel" class:show class:copied={label === view.string.Copied} data-tooltip={lTranslate}>
<input <input
bind:this={input} bind:this={input}
class="search" class="search"
type="text" type="text"
bind:value bind:value
placeholder={phTraslate} placeholder={phTranslate}
style="width: 100%;" style="width: 100%;"
on:keypress={(ev) => { on:keypress={(ev) => {
if (ev.key === 'Enter') { if (ev.key === 'Enter') {
@ -181,7 +181,7 @@
class:show class:show
class:copied={label === view.string.Copied} class:copied={label === view.string.Copied}
class:cursor-pointer={openable} class:cursor-pointer={openable}
data-tooltip={lTraslate} data-tooltip={lTranslate}
on:click={() => { on:click={() => {
if (openable) { if (openable) {
dispatch('update', 'open') dispatch('update', 'open')

View File

@ -26,10 +26,10 @@
export let disabled: boolean = false export let disabled: boolean = false
let input: HTMLElement let input: HTMLElement
let phTraslate: string = '' let phTranslate: string = ''
$: translate(placeholder, placeholderParam ?? {}).then((res) => { $: translate(placeholder, placeholderParam ?? {}).then((res) => {
phTraslate = res phTranslate = res
}) })
afterUpdate(() => { afterUpdate(() => {
@ -50,7 +50,7 @@
rows="1" rows="1"
bind:value bind:value
bind:this={input} bind:this={input}
placeholder={phTraslate} placeholder={phTranslate}
{disabled} {disabled}
on:keydown on:keydown
on:change on:change

View File

@ -45,10 +45,10 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const query = createQuery() const query = createQuery()
let phTraslate: string = '' let phTranslate: string = ''
$: if (placeholder) { $: if (placeholder) {
translate(placeholder, {}, $themeStore.language).then((res) => { translate(placeholder, {}, $themeStore.language).then((res) => {
phTraslate = res phTranslate = res
}) })
} }
@ -116,7 +116,7 @@
bind:this={searchElement} bind:this={searchElement}
type="text" type="text"
bind:value={search} bind:value={search}
placeholder={phTraslate} placeholder={phTranslate}
style="width: 100%;" style="width: 100%;"
on:change on:change
/> />