0.1.1 • Published 6 months ago
@mdtx/ssr v0.1.1
Installation
- Install required packages
npm i @mdtx/i18-drawer react next- Add
LocaleTXcomponent to your_appfile. Optionally passapiprop.
import type { AppProps } from 'next/app'
import { LocaleTX } from '@mdtx/i18-drawer';
import '@mdtx/i18-drawer/dist/styles.css';
export default function MyApp({ Component, pageProps }: AppProps) {
return <>
<Component {...pageProps} />
<LocaleTX {...pageProps} />
{/* <LocaleTX {...pageProps} api='/api/i18-drawer' /> */}
</>
}- Add API route
/api/i18-drawer. Setup path to thelocalesfolder.
import { APIHandler } from '@mdtx/i18-drawer';
export default APIHandler('src/locales');If you want to have a bit more control you can write API handler yourself. You can use saveChanges function to save changes in locales.
import { LocaleChanges, saveChanges } from '@mdtx/i18-drawer';
import { NextApiRequest, NextApiResponse } from 'next';
export default (req: NextApiRequest, res: NextApiResponse) => {
saveChanges(req.body as LocaleChanges, 'src/locales');
res.send('OK');
};- If you have error
Can't resolve 'fs'change webpack config innext.config.js.
module.exports = {
webpack: (config) => {
// Disable fallback for the 'fs' module
config.resolve.fallback = { fs: false, path: false };
return config;
}
};