ezqms-245: allow configurable languages per deployments (#3579)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2023-08-10 19:17:44 +04:00 committed by GitHub
parent 26d8099f1d
commit 8855f878cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 3 deletions

View File

@ -90,6 +90,7 @@ interface Config {
GMAIL_URL: string GMAIL_URL: string
CALENDAR_URL: string CALENDAR_URL: string
TITLE?: string TITLE?: string
LANGUAGES?: string
DEFAULT_LANGUAGE?: string DEFAULT_LANGUAGE?: string
} }
@ -117,6 +118,9 @@ export async function configurePlatform() {
setMetadata(uiPlugin.metadata.DefaultApplication, login.component.LoginApp) setMetadata(uiPlugin.metadata.DefaultApplication, login.component.LoginApp)
const languages = config.LANGUAGES ? (config.LANGUAGES as string).split(',').map((l) => l.trim()) : ['en', 'ru']
setMetadata(uiPlugin.metadata.Languages, languages)
setMetadata( setMetadata(
uiPlugin.metadata.Routes, uiPlugin.metadata.Routes,
new Map([ new Map([

View File

@ -14,6 +14,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import { getContext } from 'svelte' import { getContext } from 'svelte'
import { getMetadata } from '@hcengineering/platform'
import { showPopup } from '../..' import { showPopup } from '../..'
import LangPopup from './LangPopup.svelte' import LangPopup from './LangPopup.svelte'
import ui from '../../plugin' import ui from '../../plugin'
@ -24,15 +25,34 @@
currentLanguage: string currentLanguage: string
setLanguage: (lang: string) => void setLanguage: (lang: string) => void
} }
const uiLangs = new Set(getMetadata(ui.metadata.Languages))
const langs = [ const langs = [
{ id: 'en', label: ui.string.English }, { id: 'en', label: ui.string.English },
{ id: 'ru', label: ui.string.Russian } { id: 'ru', label: ui.string.Russian }
] ].filter((lang) => uiLangs.has(lang.id))
if (langs.findIndex((l) => l.id === currentLanguage) < 0 && langs.length !== 0) {
setLanguage(langs[0].id)
}
if (langs.length === 0) {
console.error(
`List of configured UI languages: [${getMetadata(ui.metadata.Languages)?.join(
', '
)}] doesn't contain any languages available in the app. Please check you configuration.`
)
}
const isSelectable = langs.length > 1
$: selected = langs.find((item) => item.id === currentLanguage) $: selected = langs.find((item) => item.id === currentLanguage)
let trigger: HTMLElement let trigger: HTMLElement
const selectLanguage = (): void => { const selectLanguage = (): void => {
if (!isSelectable) {
return
}
showPopup(LangPopup, { langs }, trigger, (result) => { showPopup(LangPopup, { langs }, trigger, (result) => {
if (result) { if (result) {
selected = langs.find((item) => item.id === result) selected = langs.find((item) => item.id === result)
@ -45,7 +65,7 @@
<Flags /> <Flags />
{#if selected} {#if selected}
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div bind:this={trigger} class="flex-center cursor-pointer" on:click={selectLanguage}> <div bind:this={trigger} class="flex-center {isSelectable ? 'cursor-pointer' : ''}" on:click={selectLanguage}>
<svg class="svg-16px"> <svg class="svg-16px">
<use href="#{selected.id}-flag" /> <use href="#{selected.id}-flag" />
</svg> </svg>

View File

@ -159,7 +159,7 @@
<div class="clock"> <div class="clock">
<Clock /> <Clock />
</div> </div>
<div class="flex-center widget cursor-pointer"> <div class="flex-center widget">
<LangSelector /> <LangSelector />
</div> </div>
<div class="flex-center widget cursor-pointer"> <div class="flex-center widget cursor-pointer">

View File

@ -88,6 +88,7 @@ export const uis = plugin(uiId, {
metadata: { metadata: {
DefaultApplication: '' as Metadata<AnyComponent>, DefaultApplication: '' as Metadata<AnyComponent>,
Routes: '' as Metadata<Map<string, AnyComponent>>, Routes: '' as Metadata<Map<string, AnyComponent>>,
Languages: '' as Metadata<string[]>,
// Will activate network click button // Will activate network click button
ShowNetwork: '' as Metadata<(evt: MouseEvent) => void> ShowNetwork: '' as Metadata<(evt: MouseEvent) => void>

View File

@ -142,6 +142,7 @@ export function start (
gmailUrl: string gmailUrl: string
calendarUrl: string calendarUrl: string
title?: string title?: string
languages: string
defaultLanguage: string defaultLanguage: string
}, },
port: number, port: number,
@ -182,6 +183,7 @@ export function start (
GMAIL_URL: config.gmailUrl, GMAIL_URL: config.gmailUrl,
CALENDAR_URL: config.calendarUrl, CALENDAR_URL: config.calendarUrl,
TITLE: config.title, TITLE: config.title,
LANGUAGES: config.languages,
DEFAULT_LANGUAGE: config.defaultLanguage, DEFAULT_LANGUAGE: config.defaultLanguage,
...(extraConfig ?? {}) ...(extraConfig ?? {})
}) })

View File

@ -21,6 +21,7 @@ import { start } from '.'
export function startFront (extraConfig?: Record<string, string>): void { export function startFront (extraConfig?: Record<string, string>): void {
const defaultLanguage = process.env.DEFAULT_LANGUAGE ?? 'en' const defaultLanguage = process.env.DEFAULT_LANGUAGE ?? 'en'
const languages = process.env.LANGUAGES ?? 'en,ru'
const SERVER_PORT = parseInt(process.env.SERVER_PORT ?? '8080') const SERVER_PORT = parseInt(process.env.SERVER_PORT ?? '8080')
const transactorEndpoint = process.env.TRANSACTOR_URL const transactorEndpoint = process.env.TRANSACTOR_URL
@ -132,6 +133,7 @@ export function startFront (extraConfig?: Record<string, string>): void {
rekoniUrl, rekoniUrl,
calendarUrl, calendarUrl,
title, title,
languages,
defaultLanguage defaultLanguage
} }
console.log('Starting Front service with', config) console.log('Starting Front service with', config)