There are three ways to determine the languages and the regions. First of all, there is the way to detect the location from the IP address, which we are not going to cover in this talk. But secondly, here is the example of respecting users, you know, like configured in their browser setting, you know, like which languages to choose. And lastly, there is a way to identify in the URL. And I'm going to show you the three patterns to identify URLs.
So pattern one is differentiating, you know, by domains, but it will not follow the same origin policy. The pattern two is using the URL parameters, but it doesn't look user friendly, right? And the last pattern is localized sub directories. This looks much cleaner and much more user friendly.
So moving on to the framework examples, there are in general two approaches to choose. So the first approach would be like using an npm package that is, you know, related with I18next. And the other approach is with a combination of the content management system. So this talk is about the Remix, so I'm going to show you the Remix I18next example first. And moving on to show you the content management system example.
So Remix I18next is an npm package for Remix to use the I18next. So first step would be creating the translation files. In this case, I have a default language in English saying greeting hello and translated, you know, like the translation file greeting says hello in Japanese, and let's create I18next configuration file. So in here, what I'm defining is supported languages, fallback language and the default namespace. This namespace common is actually what I gave the names into these translation file. Moving on to, you know, like the other file called I18nextserver.js file. So in here what I'm doing is importing what we configured in I18next config file, and you know, like from the previous file, what we configured, the values are actually arrays in the strings. So we iterate them from the configuration file from the previous slide. And the rest we are setting the translation file path. So next up is creating the client side and the server side configuration files. From the time I have, I'm going to focus on the client side, but don't worry about it, server side, you know, config files looks pretty much the same and a few differences. So entry.client.jsx file. What I want you to pay attention to is with the orange highlighted, you know, line of the code, which is an API called i18xProvider. So with this, by using this API, we want to ensure the translations are loaded before the hydration happens. And we're going to see why together in one of the following slides. And next up, you know, we wrap the remix browser component in between i18xProvider component. So we're also going to see the reasons in one of the following slides.
Comments