Localisation for your Remix Apps with remix-i18next

Localisation for your Remix Apps with remix-i18next

Are you looking to take your Remix apps to the next level by making them multilingual? Say hello to remix-i18next – your ultimate solution for seamless translation integration. As a seasoned frontend developer, you know the importance of user experience, and what better way to enhance it than by breaking language barriers? Let's dive into how remix-i18next can revolutionise your app localisation process.

Why Choose remix-i18next?

Simplicity at its Finest: Setting up remix-i18next is a breeze. With just a few steps, you'll have your app ready to speak multiple languages.

No Extra Dependencies: Say goodbye to cluttered dependencies. remix-i18next streamlines internationalisation for your Remix app without the need for additional packages.

Ready for Production: Worried about performance in production? Fear not! remix-i18next supports passing translations and configuration options into routes from the loader, ensuring your app runs smoothly.

Total Control: With remix-i18next, you're in the driver's seat. We don't hide the configuration, so feel free to add any plugin or customize settings as you please.

Let's Get Started: Setup Guide

Installation

First things first, let's install remix-i18next along with its necessary companions:

npm install remix-i18next i18next react-i18next i18next-browser-languagedetector        

Additionally, if you opt for specific backends and language detectors, you can install them too:

npm install i18next-http-backend i18next-fs-backend        

Configuration

Now, it's time to configure remix-i18next. Start by creating translation files:

  • public/locales/en/common.json
  • public/locales/es/common.json

Next, set up your i18next configuration in app/i18n.ts and app/i18next.server.ts.

Client-side & Server-side Configuration

Configure your entry files (entry.client.tsx and entry.server.tsx) to integrate remix-i18next seamlessly into your app.

Putting It into Practice: Usage

In your app's components, simply use the t() function provided by react-i18next to access translations. You can also split translation files for better organization.

In your root.tsx loader, you can fetch the language from url like below and set the language accordingly.

export async function loader({loader}: LoaderFunctionArgs) {
  const { searchParams } = new URL(request.url)
  const lang = searchParams.get('lang') ?? 'en'
  return json({ locale });
}

export default function App() {
  const { locale } = useLoaderData<typeof loader>();

  const { i18n } = useTranslation();
  useChangeLanguage(locale);
  return (
    <html lang={locale} dir={i18n.dir()}>
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        <Outlet />
        <ScrollRestoration />
        <Scripts />
        <LiveReload />
      </body>
    </html>
  );
}        

For more info, please follow the Readme.md file of the library. It's very clear.


With remix-i18next, language localisation becomes a breeze, enabling you to cater to a global audience effortlessly. So, what are you waiting for? Let's make your Remix app speak the language of your users! ???

#FrontendDevelopment #Localization #RemixFramework #i18n #ReactJS #WebDevelopment

要查看或添加评论,请登录

社区洞察

其他会员也浏览了