i18n feature for MD/MDX #81
Replies: 2 comments 2 replies
-
The problem is that Qwik Optimizer supports What you can do is create the components, and import them into mdx files, for example: index.mdx import { MyComponent } from './my-component.tsx';
<MyComponent />
{/* other components */}
export const head = {
title: 'runtime.head.my-page.title',
meta: [{ name: 'description', content: 'runtime.head.my-page.description' }]
}; If you are using some plugin instead, and want to import mdx files into Qwik components, you should be able to pass
Could you post the configuration of the mdx plugins you are using, and some examples of what you would like to achieve? |
Beta Was this translation helpful? Give feedback.
-
I think if use MD for privacy policy, terms, blog, it would be better to have one MD file for each translation, instead of cluttering translation files.
import PrivacyEn from './privacy/index.mdx';
import PrivacyIt from './it-IT/privacy/index.mdx';
export const Privacy= component$(() => {
const lang = useSpeakLocale().lang;
return (
<div>
{lang === 'it-IT' && <PrivacyIt />}
{lang === 'en-US' && <PrivacyEn />}
</div>
);
});
Ok, in the latter case you have to update export const onRequest: RequestHandler = ({ pathname, params, locale }) => {
let lang: string | undefined = params.lang;
if (!lang) {
const param = pathname.split('/')[1];
lang = config.supportedLocales.find(x => x.lang === param)?.lang;
}
// Set Qwik locale
locale(lang || config.defaultLocale.lang);
}; const navigateByLocale$ = $((newLocale: SpeakLocale) => {
const url = new URL(location.href);
const param = loc.url.pathname.split('/')[1];
const lang = loc.params.lang || config.supportedLocales.find(x => x.lang === param)?.lang;
if (lang) {
if (newLocale.lang !== config.defaultLocale.lang) {
url.pathname = url.pathname.replace(lang, newLocale.lang);
} else {
url.pathname = url.pathname.replace(new RegExp(`(/${lang}/)|(/${lang}$)`), '/');
}
} else if (newLocale.lang !== config.defaultLocale.lang) {
url.pathname = `/${newLocale.lang}${url.pathname}`;
}
location.href = url.toString();
}); Hope this helps |
Beta Was this translation helpful? Give feedback.
-
Hello and Thanks much @robisim74 for lovely Qwik i18n package
I am trying to apply Qwik-speak and found that it may miss/hard-to-apply for MD/MDX file.
MD/MDX files are built-in supported by Qwik or 3rd lib markdown-it.
Please give me your advice.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions