In this article, you will learn one of the multiple approaches available for changing the language of content on a dynamic page implemented with Strapi and Next.js.
This is not a tutorial from scratch on creating a website with internationalization.
The central objective of this article is to show you how to redirect a user to the correct route if they change the language of a website while on a dynamic route.

This applies when using Strapi's UUID data type to query a dynamic page.
Why? 🤷♀️
Explanation of the problem.
To illustrate, I have created the following Strapi project:
The project is configured to manage its content in Spanish and English, with Spanish being the default language.

Additionally, it includes a Blog Collection Type, which has a Text field for the Blog Title and a UUID field for its Slug.

Finally, we have an example Blog that in its Spanish version has the title: "Mi Blog Super Épico" and the Slug: mi-blog-super-epico.

And in its English version, it has the title: "My Super Epic Blog" and the Slug: my-super-epic-blog.

By enabling internationalized content in Strapi, it adds a filtering property called "locale," which allows the developer to filter content by locale.
In our case, since we only have two languages, the locale property can take the value of "es," "en," or "all," where "all" instructs Strapi to query all configured locations.
Commonly, you might think that you can query information from a record filtering by its UUID field in a different locale. But this is not the case in Strapi.
Taking our Strapi project as an example, if you try to query the title of the Blog "Mi Blog Super Épico" in its English version using its Spanish Slug, the query will not return any information: 🚨
Why is this important? 🥀
Commonly, websites have a single Language Menu or Language Selector, which adds a suffix to the current route with the locale or language selected by the user.

The above example shows a website I created using Next.js to integrate it with our Strapi project. You can visit it to see the final version of this example at: i18nBlog. You can also view the complete code in the following repository.

The Next.js website has a button that, when clicked, switches the page language between Spanish and English. Where, at the route level, we would have the following:
- Spanish Route:
https://example.com/ - English Route:
https://example.com/en
Taking the above and returning to our example. Let's imagine that we access "Mi Blog Super Épico" in Spanish:
https://example.com/blog/mi-blog-super-epico.
If we change the language of our website to English, our route would change to:
https://example.com/en/blog/mi-blog-super-epico.
Do you notice what the problem is? 🤔
Exactly, that we have the locale of our website in English ("en"), but the Slug is still: mi-blog-super-epico (Spanish). And as we saw in our previous GraphQL query, we need the Slug in English to get the information, i.e., my-super-epic-blog.
How do we solve this problem?
A very simple solution would be to redirect to the route with the Slug in the correct locale when it is detected that the user has changed the language of the website.

✨Very well, let's implement this solution.✨
In my example, I am using Next.js 14 with the App Router. Again, this article solves a specific case, so I will not delve into how to create a website with internationalization in Next.js. But you can learn here: Next.js Internationalization.
To start, we will add the base to have a dynamic page in Next.js that queries our Strapi API and shows the Title of our Blog "Mi Blog Super Épico."