mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 00:32:33 +00:00
load language files from list, and init map language
This commit is contained in:
@@ -10,9 +10,9 @@
|
|||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { map } from '$lib/stores';
|
import { map } from '$lib/stores';
|
||||||
import { settings } from '$lib/db';
|
import { settings } from '$lib/db';
|
||||||
import { locale, _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
import { get } from 'svelte/store';
|
|
||||||
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
|
||||||
export let accessToken = PUBLIC_MAPBOX_TOKEN;
|
export let accessToken = PUBLIC_MAPBOX_TOKEN;
|
||||||
export let geolocate = true;
|
export let geolocate = true;
|
||||||
@@ -41,12 +41,21 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let language = $page.params.language;
|
||||||
|
if (language === 'zh') {
|
||||||
|
language = 'zh-Hans';
|
||||||
|
} else if (language?.includes('-')) {
|
||||||
|
language = language.split('-')[0];
|
||||||
|
} else if (language === '' || language === undefined) {
|
||||||
|
language = 'en';
|
||||||
|
}
|
||||||
|
|
||||||
let newMap = new mapboxgl.Map({
|
let newMap = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
style: { version: 8, sources: {}, layers: [] },
|
style: { version: 8, sources: {}, layers: [] },
|
||||||
zoom: 0,
|
zoom: 0,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
language: get(locale),
|
language,
|
||||||
attributionControl: false,
|
attributionControl: false,
|
||||||
logoPosition: 'bottom-right',
|
logoPosition: 'bottom-right',
|
||||||
boxZoom: false
|
boxZoom: false
|
||||||
@@ -71,7 +80,7 @@
|
|||||||
mapboxgl: mapboxgl,
|
mapboxgl: mapboxgl,
|
||||||
collapsed: true,
|
collapsed: true,
|
||||||
flyTo: fitBoundsOptions,
|
flyTo: fitBoundsOptions,
|
||||||
language: get(locale)
|
language
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
|
import { languages } from '$lib/languages';
|
||||||
import { register, init } from 'svelte-i18n';
|
import { register, init } from 'svelte-i18n';
|
||||||
|
|
||||||
register('en', () => import('../locales/en.json'));
|
Object.keys(languages).forEach((lang) => {
|
||||||
|
register(lang, () => import(`../locales/${lang}.json`));
|
||||||
|
});
|
||||||
|
|
||||||
init({
|
init({
|
||||||
fallbackLocale: 'en',
|
fallbackLocale: 'en',
|
||||||
|
Reference in New Issue
Block a user