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 translations = new Map<Plugin, Messages | Status>()
const cache = new Map<IntlString, IntlMessageFormat | Status>()
const englishTranslationsForMissing = new Map<Plugin, Messages | Status>()
/**
* @public
* @param plugin -
@ -91,9 +91,23 @@ async function getTranslation (id: _IdInfo, locale: string): Promise<IntlString
if (messages instanceof Status) {
return messages
}
return id.kind !== undefined
? (messages[id.kind] as Record<string, IntlString>)?.[id.name]
: (messages[id.name] as IntlString)
if (id.kind !== undefined) {
if ((messages[id.kind] as Record<string, IntlString>)?.[id.name] !== undefined) {
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) {
const status = unknownError(err)
await setPlatformStatus(status)

View File

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

View File

@ -167,6 +167,15 @@
let placeHolderStr: string = ''
$: 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
})

View File

@ -55,6 +55,15 @@
let placeHolderStr: string = ''
$: 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
})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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