All checks were successful
CI / update (push) Successful in 1m29s
- Rosary: mystery selection, luminous toggle, and latin toggle fall back to URL params (?mystery=, ?luminous=, ?latin=) for no-JS navigation - Prayers/Angelus: latin toggle uses URL param fallback - Search on prayers page hidden without JS (requires DOM queries) - Toggle component supports href prop for link-based no-JS self-submit - LanguageSelector uses <a> links with computed paths and :focus-within dropdown for no-JS; displays correct language via server-provided prop - Recipe language links use translated slugs from $page.data - URL params cleaned via replaceState after hydration to avoid clutter
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { setContext, getContext, hasContext } from 'svelte';
|
|
import { writable } from 'svelte/store';
|
|
|
|
const LANGUAGE_CONTEXT_KEY = Symbol('language');
|
|
|
|
/**
|
|
* Creates or updates a language context for prayer components
|
|
* @param {Object} options
|
|
* @param {'de' | 'en'} [options.urlLang] - The URL language (de for /glaube, en for /faith)
|
|
* @param {boolean} [options.initialLatin] - Initial state for Latin/bilingual display
|
|
*/
|
|
export function createLanguageContext({ urlLang = 'de', initialLatin = true } = {}) {
|
|
// Check if context already exists (e.g., during navigation)
|
|
if (hasContext(LANGUAGE_CONTEXT_KEY)) {
|
|
const existing = getContext(LANGUAGE_CONTEXT_KEY);
|
|
// Update the lang store with the new URL language
|
|
existing.lang.set(urlLang);
|
|
return existing;
|
|
}
|
|
|
|
const showLatin = writable(initialLatin); // true = bilingual (Latin + vernacular), false = monolingual
|
|
const lang = writable(urlLang); // 'de' or 'en' based on URL
|
|
|
|
setContext(LANGUAGE_CONTEXT_KEY, {
|
|
showLatin,
|
|
lang
|
|
});
|
|
|
|
return { showLatin, lang };
|
|
}
|
|
|
|
export function getLanguageContext() {
|
|
return getContext(LANGUAGE_CONTEXT_KEY);
|
|
}
|