2021-08-04 23:31:54 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 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 { setContext, onMount } from 'svelte'
|
2022-02-28 03:42:34 +00:00
|
|
|
import platform, { loadPluginStrings, setMetadata } from '@anticrm/platform'
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
const getCurrentTheme = (): string => localStorage.getItem('theme') ?? 'theme-dark'
|
|
|
|
const getCurrnetFontSize = (): string => localStorage.getItem('fontsize') ?? 'normal-font'
|
2022-01-06 11:09:19 +00:00
|
|
|
const getCurrnetLanguage = (): string => localStorage.getItem('lang') ?? 'en'
|
2021-08-04 23:31:54 +00:00
|
|
|
const currentTheme = getCurrentTheme()
|
|
|
|
const currentFontSize = getCurrnetFontSize()
|
2022-02-23 16:10:11 +00:00
|
|
|
let currentLanguage = getCurrnetLanguage()
|
2021-08-04 23:31:54 +00:00
|
|
|
|
|
|
|
const setRootColors = (theme: string) => {
|
2021-08-14 11:42:31 +00:00
|
|
|
document.documentElement.setAttribute('class', `${theme} ${getCurrnetFontSize()}`)
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
const setRootFontSize = (fontsize: string) => {
|
2021-08-14 11:42:31 +00:00
|
|
|
document.documentElement.setAttribute('class', `${getCurrentTheme()} ${fontsize}`)
|
2021-08-04 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setContext('theme', {
|
|
|
|
currentTheme: currentTheme,
|
|
|
|
setTheme: (name: string) => {
|
|
|
|
setRootColors(name)
|
|
|
|
localStorage.setItem('theme', name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
setContext('fontsize', {
|
|
|
|
currentFontSize: currentFontSize,
|
|
|
|
setFontSize: (fontsize: string) => {
|
|
|
|
setRootFontSize(fontsize)
|
|
|
|
localStorage.setItem('fontsize', fontsize)
|
|
|
|
}
|
|
|
|
})
|
2022-01-06 11:09:19 +00:00
|
|
|
setContext('lang', {
|
|
|
|
currentLanguage: currentLanguage,
|
|
|
|
setLanguage: (lang: string) => {
|
2022-02-23 16:10:11 +00:00
|
|
|
currentLanguage = lang
|
2022-01-06 11:09:19 +00:00
|
|
|
localStorage.setItem('lang', lang)
|
2022-02-23 16:10:11 +00:00
|
|
|
location.reload()
|
2022-01-06 11:09:19 +00:00
|
|
|
}
|
|
|
|
})
|
2021-08-04 23:31:54 +00:00
|
|
|
|
2022-05-20 19:40:24 +00:00
|
|
|
const setDocumentLanguage = (): void => {
|
|
|
|
document.documentElement.lang = currentLanguage
|
|
|
|
}
|
|
|
|
|
2021-08-04 23:31:54 +00:00
|
|
|
onMount(() => {
|
|
|
|
setRootColors(currentTheme)
|
|
|
|
setRootFontSize(currentFontSize)
|
2022-02-23 16:10:11 +00:00
|
|
|
setMetadata(platform.metadata.locale, currentLanguage)
|
2022-02-28 03:42:34 +00:00
|
|
|
loadPluginStrings(currentLanguage)
|
2022-05-20 19:40:24 +00:00
|
|
|
setDocumentLanguage()
|
2021-08-04 23:31:54 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
<slot />
|