Added translations switch button
This commit is contained in:
@@ -6,6 +6,8 @@ export const defaultLang: Language = 'fr';
|
||||
|
||||
export const translations: LanguageDict = {
|
||||
'fr': {
|
||||
'lang.fr': 'Français',
|
||||
'lang.en': 'English',
|
||||
'common.title': 'Titre',
|
||||
'common.create': 'Créer',
|
||||
'common.by': 'par',
|
||||
@@ -29,6 +31,8 @@ export const translations: LanguageDict = {
|
||||
'maps.markers.newNotice': "Le marqueur sera sauvegardé mais n'apparaîtra que sur votre carte !"
|
||||
},
|
||||
'en': {
|
||||
'lang.fr': 'Français',
|
||||
'lang.en': 'English',
|
||||
'common.title': 'Title',
|
||||
'common.create': 'Create',
|
||||
'common.by': 'by',
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
import { defaultLang, availableLangs, type Language, type LanguageDict } from './ui';
|
||||
import { defaultLang, availableLangs, type Language } from './ui';
|
||||
|
||||
/**
|
||||
* This function will get the language from the URL
|
||||
*
|
||||
* @param url The URL to get the language from
|
||||
* @returns The language found in the URL, or the default language if not found
|
||||
*/
|
||||
export function getLangFromUrl(url: URL): Language {
|
||||
const [, lang] = url.pathname.split('/');
|
||||
if (availableLangs.includes(lang as Language)) return lang as Language;
|
||||
return defaultLang
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will generate a new URL with the given language
|
||||
* It will replace the first part of the path with the new language
|
||||
* For example, if the URL is /fr/quests and the new language is 'en', the new URL will be /en/quests
|
||||
*
|
||||
* @param url The active URL
|
||||
* @param lang The target language to generate the new URL
|
||||
*/
|
||||
export function switchLang(url: URL, lang: Language): URL {
|
||||
const parts = url.pathname.split('/');
|
||||
parts[1] = lang;
|
||||
return new URL(parts.join('/'), url.origin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user