Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const INIT_OPTIONS = {
fallbackLocale: 'en',
initialLocale: 'en',
loadingDelay: 200,
formats: {},
warnOnMissingMessages: true,
localeOptions: LANGUAGES,
};
let currentLocale = null;
register('en', () => import('./messages/en.json'));
register('de', () => import('./messages/de.json'));
$locale.subscribe((value) => {
if (value == null) return;
currentLocale = value;
// if running in the client, save the language preference in a cookie
if (typeof window !== 'undefined') {
setCookie('locale', value);
}
});
// initialize the i18n library in client
export function startClient() {
console.log('nav', getLocaleFromNavigator());
init({
...INIT_OPTIONS,
initialLocale: getCookie('locale') || INIT_OPTIONS.localeOptions.find(option => option == cropCountryCode(getLocaleFromNavigator())) || INIT_OPTIONS.initialLocale,
export function get(req, res) {
if (!json || process.env.NODE_ENV !== 'production') {
const { slug } = req.params;
locale.subscribe(localecode => {
console.log('sublocale: ' + localecode, LANGUAGES);
if (!LANGUAGES.includes(localecode)) {
console.log(INIT_OPTIONS);
localecode = INIT_OPTIONS.initialLocale || 'en';
}
const seo = generate_seo('docs/', slug, localecode);
// import(`../../../docs/${slug}/seo_${localecode}.jsonld`).then((module) => {
// const seo = module.meta;
// const docs = generate_docs('docs/', slug, localecode);
// json = JSON.stringify({ docs, seo }); // TODO it errors if I send the non-stringified value
// }).catch(error => {
// console.error(error);
const docs = generate_docs('docs/', slug, localecode);