Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZQMS-245: Allow to configure available languages per deployment #3579

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev/prod/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ interface Config {
GMAIL_URL: string
CALENDAR_URL: string
TITLE?: string
LANGUAGES?: string
DEFAULT_LANGUAGE?: string
}

Expand Down Expand Up @@ -117,6 +118,9 @@ export async function configurePlatform() {

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(
uiPlugin.metadata.Routes,
new Map([
Expand Down
24 changes: 22 additions & 2 deletions packages/ui/src/components/internal/LangSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-->
<script lang="ts">
import { getContext } from 'svelte'
import { getMetadata } from '@hcengineering/platform'
import { showPopup } from '../..'
import LangPopup from './LangPopup.svelte'
import ui from '../../plugin'
Expand All @@ -24,15 +25,34 @@
currentLanguage: string
setLanguage: (lang: string) => void
}
const uiLangs = new Set(getMetadata(ui.metadata.Languages))
const langs = [
{ id: 'en', label: ui.string.English },
{ 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)
let trigger: HTMLElement

const selectLanguage = (): void => {
if (!isSelectable) {
return
}

showPopup(LangPopup, { langs }, trigger, (result) => {
if (result) {
selected = langs.find((item) => item.id === result)
Expand All @@ -45,7 +65,7 @@
<Flags />
{#if selected}
<!-- 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">
<use href="#{selected.id}-flag" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/internal/Root.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<div class="clock">
<Clock />
</div>
<div class="flex-center widget cursor-pointer">
<div class="flex-center widget">
<LangSelector />
</div>
<div class="flex-center widget cursor-pointer">
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const uis = plugin(uiId, {
metadata: {
DefaultApplication: '' as Metadata<AnyComponent>,
Routes: '' as Metadata<Map<string, AnyComponent>>,
Languages: '' as Metadata<string[]>,

// Will activate network click button
ShowNetwork: '' as Metadata<(evt: MouseEvent) => void>
Expand Down
2 changes: 2 additions & 0 deletions server/front/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function start (
gmailUrl: string
calendarUrl: string
title?: string
languages: string
defaultLanguage: string
},
port: number,
Expand Down Expand Up @@ -182,6 +183,7 @@ export function start (
GMAIL_URL: config.gmailUrl,
CALENDAR_URL: config.calendarUrl,
TITLE: config.title,
LANGUAGES: config.languages,
DEFAULT_LANGUAGE: config.defaultLanguage,
...(extraConfig ?? {})
})
Expand Down
2 changes: 2 additions & 0 deletions server/front/src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { start } from '.'

export function startFront (extraConfig?: Record<string, string>): void {
const defaultLanguage = process.env.DEFAULT_LANGUAGE ?? 'en'
const languages = process.env.LANGUAGES ?? 'en,ru'
const SERVER_PORT = parseInt(process.env.SERVER_PORT ?? '8080')

const transactorEndpoint = process.env.TRANSACTOR_URL
Expand Down Expand Up @@ -132,6 +133,7 @@ export function startFront (extraConfig?: Record<string, string>): void {
rekoniUrl,
calendarUrl,
title,
languages,
defaultLanguage
}
console.log('Starting Front service with', config)
Expand Down