mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-29 00:09:14 -04:00
Build 29035725
This commit is contained in:
parent
a1bf54af71
commit
819197031f
64 changed files with 3494 additions and 6921 deletions
|
@ -1,32 +1,31 @@
|
|||
import fr from './fr.json'
|
||||
import en from './en.json'
|
||||
import {getSettingValue} from "../settings";
|
||||
import fr from "./fr.json";
|
||||
import en from "./en.json";
|
||||
import { getSettingValue } from "../settings";
|
||||
|
||||
type translationKeys = keyof typeof en
|
||||
type translation= { [key in translationKeys] : string }
|
||||
const languages:Record<string, translation>= {fr,en}
|
||||
export function getCurrentLang(){
|
||||
return getSettingValue('lang',getFirstBrowserLanguage())
|
||||
type translationKeys = keyof typeof en;
|
||||
type translation = { [key in translationKeys]: string };
|
||||
const languages: Record<string, translation> = { fr, en };
|
||||
export function getCurrentLang() {
|
||||
return getSettingValue("lang", getFirstBrowserLanguage());
|
||||
}
|
||||
|
||||
export function t(key: translationKeys, params: {[key:string]:any} = {}):string {
|
||||
const lang = getCurrentLang()
|
||||
let template=languages[lang]?.[key] || languages.en[key]
|
||||
for(let key in params){
|
||||
template=template.split('{{'+key+'}}').join(`${params[key]}`)
|
||||
}
|
||||
return template
|
||||
export function t(
|
||||
key: translationKeys,
|
||||
params: { [key: string]: any } = {},
|
||||
): string {
|
||||
const lang = getCurrentLang();
|
||||
let template = languages[lang]?.[key] || languages.en[key];
|
||||
for (let key in params) {
|
||||
template = template.split("{{" + key + "}}").join(`${params[key]}`);
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
function getFirstBrowserLanguage() {
|
||||
const preferred_languages = [
|
||||
...navigator.languages,
|
||||
navigator.language,
|
||||
'en'
|
||||
].filter(i => i)
|
||||
.map(i => i.slice(0, 2).toLowerCase())
|
||||
const supported = Object.keys(languages)
|
||||
const preferred_languages = [...navigator.languages, navigator.language, "en"]
|
||||
.filter((i) => i)
|
||||
.map((i) => i.slice(0, 2).toLowerCase());
|
||||
const supported = Object.keys(languages);
|
||||
|
||||
return preferred_languages.find(k=>supported.includes(k)) || 'en'
|
||||
|
||||
};
|
||||
return preferred_languages.find((k) => supported.includes(k)) || "en";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue