mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
74 lines
2.3 KiB
Svelte
74 lines
2.3 KiB
Svelte
<!--
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
-->
|
|
<script lang="ts">
|
|
import { getContext } from 'svelte'
|
|
import { getMetadata } from '@hcengineering/platform'
|
|
import { showPopup } from '../..'
|
|
import LangPopup from './LangPopup.svelte'
|
|
import ui, { deviceOptionsStore as deviceInfo } from '../..'
|
|
|
|
let pressed: boolean = false
|
|
|
|
const { currentLanguage, setLanguage } = getContext('lang') as {
|
|
currentLanguage: string
|
|
setLanguage: (lang: string) => void
|
|
}
|
|
const uiLangs = new Set(getMetadata(ui.metadata.Languages))
|
|
const langs = [
|
|
{ id: 'en', label: ui.string.English, logo: '🇺🇸' },
|
|
{ id: 'ru', label: ui.string.Russian, logo: '🇷🇺' }
|
|
].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)
|
|
|
|
const selectLanguage = (): void => {
|
|
if (!isSelectable) {
|
|
return
|
|
}
|
|
pressed = true
|
|
|
|
showPopup(LangPopup, { langs, selected: selected?.id }, 'status', (result) => {
|
|
if (result) {
|
|
selected = langs.find((item) => item.id === result)
|
|
setLanguage(result)
|
|
}
|
|
pressed = false
|
|
})
|
|
}
|
|
$: $deviceInfo.language = selected?.id
|
|
</script>
|
|
|
|
<button
|
|
class="antiButton ghost jf-center bs-none no-focus resetIconSize statusButton square"
|
|
class:pressed
|
|
on:click={selectLanguage}
|
|
>
|
|
{@html selected?.logo}
|
|
</button>
|