Internationalization & Localization with Next.js and Hygraph
How can I internationalize my Next.js app using next-intl?
To internationalize your Next.js app, install the next-intl library and configure your project to support multiple locales. This involves creating locale-specific message files (e.g., en.json, fr.json), updating your next.config.mjs with the createNextIntlPlugin, and implementing middleware for locale matching. The useTranslations hook from next-intl allows you to fetch translated strings in your components. Note: For full details, see the next-intl documentation. Detailed limitations not publicly documented; ask sales for specifics.
How do I manage and retrieve localized content from Hygraph in a Next.js application?
To manage and retrieve localized content from Hygraph, first localize your schema fields in the Hygraph schema editor by enabling the "Localize field" option. Add your desired languages in Project Settings > Locales. Update content for each locale and publish. In your Next.js app, use the GraphQL API to query content for the selected locale, passing the locales parameter in your queries. For example, fetch posts with posts(locales: [locale]). Note: Hygraph localization is best suited for dynamic content; static content should be handled via next-intl. Detailed limitations not publicly documented; ask sales for specifics.
What translation management systems does Hygraph integrate with?
Hygraph offers out-of-the-box integrations with four translation management systems (TMS): Smartling, Lokalise, EasyTranslate, and Crowdin. Each integration has a dedicated setup guide. Note: Integration capabilities may vary by TMS; review each guide for details.
How do I fetch localized content from Hygraph using GraphQL in Next.js?
To fetch localized content from Hygraph in Next.js, use the @apollo/client library to send GraphQL queries to your Hygraph endpoint. Pass the locales parameter in your query to specify the desired language. For example, posts(locales: [locale]) retrieves posts in the selected locale. The endpoint URL is available in your Hygraph project settings under Endpoints. Note: Ensure your schema fields are localized in Hygraph before querying. Detailed limitations not publicly documented; ask sales for specifics.
What are the steps to localize fields in Hygraph for multilingual content?
To localize fields in Hygraph, open the schema editor, hover over the field you want to localize, select "Edit field," check the "Localize field" option, and save. Repeat for all fields you wish to localize. Then, add your target languages in Project Settings > Locales. Update and publish content for each locale. Note: Not all field types may support localization; consult Hygraph documentation for specifics.
Can I use both next-intl and Hygraph localization together in a Next.js project?
Yes, you can use both next-intl and Hygraph localization in a Next.js project. Use next-intl for static content (UI labels, navigation, etc.) and Hygraph for dynamic, CMS-managed content. This approach allows you to internationalize both the application interface and the content delivered from Hygraph. Note: Coordination between static and dynamic localization strategies is required for consistency. Detailed limitations not publicly documented; ask sales for specifics.
What translation features does Hygraph offer for enterprise and global teams?
Hygraph supports localization of content fields, integration with translation management systems (Smartling, Lokalise, EasyTranslate, Crowdin), and management of multiple locales per project. These features enable enterprises to deliver consistent, localized content across regions. Note: For advanced translation workflows, integration with a TMS is recommended. Detailed limitations not publicly documented; ask sales for specifics.
Technical Features & Integrations
What APIs does Hygraph provide for content management and localization?
Hygraph provides several APIs: the GraphQL Content API (for querying and manipulating content, optimized for high performance and low latency), the Management API (for project structure), the Asset Upload API (for uploading assets), and the MCP Server API (for AI assistant integration). For localization, use the GraphQL Content API with the locales parameter. Note: API usage may require authentication and permissions. Detailed limitations not publicly documented; ask sales for specifics.
What integrations does Hygraph support for localization and content delivery?
Hygraph supports integrations with translation management systems (Smartling, Lokalise, EasyTranslate, Crowdin), digital asset management (DAM) platforms (Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), hosting/deployment (Netlify, Vercel), and commerce solutions (BigCommerce). For a full list, see the Hygraph Marketplace. Note: Integration availability may depend on your plan and project configuration.
Security, Compliance & Performance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (as of August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications cover infrastructure and data handling, ensuring adherence to international standards for information security and privacy. Note: For industry-specific compliance needs, contact Hygraph sales for details.
How does Hygraph ensure high performance for internationalized content delivery?
Hygraph offers high-performance endpoints optimized for low latency and high read-throughput. The read-only cache endpoint provides a 3-5x latency improvement for content delivery. Performance is actively measured and documented (see the GraphQL Report 2024). Note: Actual performance may vary based on project configuration and geographic distribution.
Implementation & Support
How long does it take to implement Hygraph for a multilingual Next.js project?
Implementation time varies by project complexity. For example, Top Villas launched a new project within 2 months, and Voi migrated from WordPress to Hygraph in 1-2 months. Hygraph provides structured onboarding, starter projects, and extensive documentation to accelerate setup. Note: Large-scale or highly customized projects may require additional time.
What documentation and resources are available for integrating Hygraph with Next.js internationalization?
Hygraph provides comprehensive documentation, including API references, schema guides, integration tutorials (e.g., for Mux, Akeneo, Auth0), and AI feature docs. The Hygraph Documentation and starter projects offer step-by-step guides. Community support is available via Slack at slack.hygraph.com. Note: Some advanced use cases may require direct support or consultation.
Use Cases & Success Stories
What are some real-world examples of companies using Hygraph for internationalized content delivery?
Notable examples include Samsung (improved customer engagement by 15%), Komax (3x faster time-to-market across 40+ markets), and Voi (scaled multilingual content across 12 countries and 10 languages). For more, see Hygraph's case studies. Note: Results may vary based on implementation and business context.
Which industries are represented in Hygraph's internationalization and localization case studies?
Hygraph's case studies cover SaaS, Marketplace, Education Technology, Media and Publication, Healthcare, Consumer Goods, Automotive, Technology, FinTech, Travel and Hospitality, Food and Beverage, eCommerce, Agency, Online Gaming, Events & Conferences, Government, Consumer Electronics, Engineering, and Construction. See case studies for details. Note: Industry-specific requirements may affect implementation details.
How to Internationalize your Next.js app with next-intl in App Router
In this guide, we’ll walk you through how to set up internationalization into your Next.js application utilizing the next-intl library, demonstrate how to configure static localized content through and manage and retrieve localized content from Hygraph.
To follow along with this guide and code, you should have the following:
Basic understanding of HTML, CSS, and JavaScript
At least a little experience or knowledge of Next.js
Node and npm or yarn installed on your local computer
#Leveraging next-intl for Next.js internationalization
Next.js offers robust support for internationalization through its built-in i18n routing. This feature is designed to work well with i18n libraries, among which next-intl stands out as it covers a range of functionalities, including interpolation, pluralization, and handling arrays.
It is fully compatible with the Pages Router of Next.js (up to version 12) and the App Router introduced in version 13, which includes support for React server components.
Getting started with next-intl
To integrate next-intl into your Next.js project, start by installing the library with the following command:
npm install next-intl
Once installed, next-intl integrates with the App Router using a [locale]dynamic segment.
#Setting up your Next.js project for internationalization
Organize your project directory by creating a [locale] directory within the /app folder and adding all files to the folder. For example, this is a simple Next.js application structure with three pages moved into the [locale] folder:
|--/app
|--/[locale]
|--/about
|-- page.js
|--/blog
|--/[postId]
|-- page.js
|-- page.js
|--/components
|-- features.js
|-- hero.js
|-- navbar.js
|-- layout.js
|-- page.js
Next, proceed with the following configuration steps:
1. Localizing messages
Depending on your workflow preference, you can store messages locally or fetch them from a remote source, such as a translation management system.
At the root of your project, create a messages folder where you can create JSON files for each locale, such as messages/en.json:
{
"Home":{
"Hero":{
"Title":"Next.js Internalization Demo",
"Subtitle":"This demo uses Next.js and the next-intl package to create a multi-language website. We later also explore how it works with Hygraph.",
"CallToAction":"Read about us"
}
}
}
This file is organized with keys referencing each value, which simplifies locating, updating, and collaborating on content. For instance, all content related to the Home page is grouped under the Home object. Within this object, further categorization can be done for different sections, such as the Hero section and the Features section.
Also, create a messages/fr.json for the French version:
{
"Home":{
"Hero":{
"Title":"Démonstration de l'internationalisation avec Next.js",
"Subtitle":"Cette démo utilise Next.js et le package next-intl pour créer un site web multilingue. Nous explorons également son fonctionnement avec Hygraph.",
"CallToAction":"Lisez à propos de nous"
}
}
}
Always ensure the keys are the same across all files, as that is what will be used to render the text.
2. Configuring Next.js
Set up a plugin to alias your i18n configuration to Server Components by updating your next.config.mjs if you're utilizing ECMAScript modules:
importcreateNextIntlPluginfrom'next-intl/plugin';
const withNextIntl =createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig ={};
exportdefaultwithNextIntl(nextConfig);
3. Defining locale-specific configurations
next-intl allows for a per-request configuration setup. In src/i18n.js, specify messages and other options based on the user's locale:
For this project, only English and French will be used. You can add more locales.
Having set up next-intl in your Next.js project, activating internationalization involves using the t() method, a function provided by next-intl for fetching translated strings. This method is accessed through the useTranslations hook, which you can import directly from the next-intl library.
This approach utilizes a key to retrieve the corresponding value. For example, navigating to http://localhost:3000/en displays the English version of the Hero section, while http://localhost:3000/fr shows its French counterpart.
Interpolation is a technique for inserting dynamic values into predefined text. It's beneficial for creating adaptable messages that may vary based on user input or other variables. A common use case is greeting users by name:
"message":"Hello {name}!"
By replacing {name} with a dynamic value, the message becomes personalized:
t('message',{name:'Jane'});
Resulting in:
"Hello Jane!"
Cardinal pluralization
This addresses the need to format messages differently based on numerical values, especially to distinguish between singular and plural forms. A classic example involves indicating the number of followers:
"message":"You have {count, plural, =0 {no followers yet} =1 {one follower} other {# followers}}."
This setup allows for different messages based on the value of count. For instance:
If count is 0, the message is: "You have no followers yet."
If count is 1, the message is: "You have one follower."
For any other number, say 3580, the message is: "You have 3,580 followers."
The # symbol is used to represent the actual number, formatted appropriately.
Ordinal pluralization
Ordinal pluralization is similar to cardinal pluralization but is used for ordering rather than quantity. It helps in formatting messages that relate to ranks or positions.
"message":"It's your {year, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} birthday!"
This message would allow for a correct ordinal suffix to be applied based on the year value:
1st, 2nd, 3rd (special cases for one, two, and few in English)
4th, 5th, ... 21st, 22nd, ... (using other for all other numbers)
next-intl offers a comprehensive solution to the complex challenge of internationalizing date and time formats, accommodating the diverse preferences found across global locales. Since date formats can vary widely from region to region, adopting a flexible approach to date and time representation in international applications is crucial.
The next-intl library leverages the ICU (International Components for Unicode) syntax to simplify incorporating dates and times within localization files. This syntax allows for directly embedding dynamic date formats into your messages, utilizing placeholders for dates, thus streamlining the internationalization process.
Here's an example in an English localization file (en.json), demonstrating the use of a placeholder for the current date in a short format:
// en.json
{
"todayDate":"Today's date is {currentDate, date, short}."
}
next-intl supports predefined date formats such as short, full, long, and medium. It also allows defining custom date formats using “date skeletons". For instance, to display a date in a specific custom format, you could specify it in your localization file like so:
// en.json
{
"todayDate":"Today's date is {currentDate, date, ::yyyyMd}."
}
The :: prefix signifies the use of a custom skeleton format, granting developers precise control over how dates are presented. The next-intl documentation offers a detailed guide on the available formats and skeletons.
To integrate a date within a Next.js page or component, the t() function is utilized:
<p>{t('todayDate',{currentDate:newDate()})}</p>
By supplying the current date to this method, next-intl dynamically renders the date in the format appropriate to the user's locale. For example, an English locale might display as "Today's date is 2/25/24," whereas in a French locale, it would appear as "La date d'aujourd'hui est 25/02/24."
Furthermore, next-intl facilitates custom date formats within messages, allowing developers to define formatters based on DateTimeFormat options. These custom formatters can be named and utilized throughout your application:
<p>
{t(
'todayDate',
{currentDate:newDate()},
{
dateTime:{
short:{
day:'numeric',
month:'short',
year:'numeric',
},
},
}
)}
</p>
#Switching languages with App Router using next-intl
next-intl provides drop-in replacements for common Next.js navigation APIs that automatically handle the user locale behind the scenes. There are two strategies to achieving this, but the straightforward method is using shared pathnames.
With this strategy, the pathnames of your app are identical for all locales. This is the simplest case, because the routes you define in Next.js will map directly to the pathnames a user can request.
To create navigation APIs for this strategy, use the createSharedPathnamesNavigation function. Create a navigation.js in your src folder and add the following:
With this configuration, you gain access to routing components and methods like Link and usePathname, enabling intuitive navigation within your Next.js project.
Next, you can incorporate language switch functionality in your Navbar or any page you wish by attaching the pathname to the href property and a locale. For example, here is a navbar.js component:
Link and usePathname are imported from the naviagtion.js file in the above code. Also, you can handle switching between different languages by attaching the pathname to the href property and a locale.
For this guide, let’s use an existing project, aiming to localize it and integrate its content with a Next.js application. Begin by duplicating a simple blog project in the Hygraph marketplace. This action will replicate the schema and all its content, a process that may take a few moments. Once completed, the next step involves localizing the fields.
Navigate to the schema editor through the schema section. This interface allows adding, editing, or deleting fields and establishing model relationships. To localize a field, hover over it, select Edit field, check the Localize field option, and update. Repeat this process for all fields you wish to localize.
Subsequently, add the languages of your choice by accessing Project Settings > Locales.
With languages configured, proceed to Content to update existing content with the localized versions. Enable the localization fields by clicking the eye icon next to the locale.
After publishing the posts, you are ready to consume them into your Next.js application.
#Integrating localized content into Next.js with GraphQL
In Next.js, you can query GraphQL content with the @apollo/client library. Install the library by running the following command in your project directory:
npm i @apollo/client
For this Next.js project, you configured internationalization routing with the next-intl library. Alternatively, you can configure internationalization without the next-intl library since Next.js has inbuilt internalization routing configurations.
With the internalization routing already set up, you have access to the locales parameter, which would be used to query the content.
Once your queries are working, you can use them in the Next.js project. Before you make the request, retrieve the high performance c**ontent API, which gives you access to the Hygraph content. You can get this from the Project settings > Endpoints** page.
Next, implement this in the Blog page of the sample application (blog/page.js). Here is an example where the list of all posts from the Hygraph project is fetched into Next.js:
In the code above, the getPosts function is defined to fetch posts from Hygraph for a specific locale. This function utilizes the ApolloClient from @apollo/client, configured with Hygraph's API endpoint and an in-memory cache for efficient data management. The GraphQL query within this function requests posts for the specified locale, retrieving their id, title, slug, and excerpt.
The query is dynamically constructed to include the locale parameter, allowing for retrieving localized content based on the user's language preference. This is crucial for delivering a localized user experience, as content is fetched and displayed according to the user's selected language.
Fetching dynamic posts
Similarly, dynamic posts can be fetched and displayed on individual blog pages (blog/[slug]/page.js) using a comparable approach:
This guide has walked you through leveraging the next-intl library and Hygraph with Next.js for effective internationalization and localization of a web application.
Following these steps ensures your application reaches a wider audience and provides a more inclusive and user-friendly experience across diverse languages and cultures.
Blog Author
Joel Olawanle
Joel Olawanle is a Frontend Engineer and Technical writer based in Nigeria who is interested in making the web accessible to everyone by always looking for ways to give back to the tech community. He has a love for community building and open source.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.
How to Internationalize your Next.js app with next-intl in App Router
In this guide, we’ll walk you through how to set up internationalization into your Next.js application utilizing the next-intl library, demonstrate how to configure static localized content through and manage and retrieve localized content from Hygraph.
To follow along with this guide and code, you should have the following:
Basic understanding of HTML, CSS, and JavaScript
At least a little experience or knowledge of Next.js
Node and npm or yarn installed on your local computer
#Leveraging next-intl for Next.js internationalization
Next.js offers robust support for internationalization through its built-in i18n routing. This feature is designed to work well with i18n libraries, among which next-intl stands out as it covers a range of functionalities, including interpolation, pluralization, and handling arrays.
It is fully compatible with the Pages Router of Next.js (up to version 12) and the App Router introduced in version 13, which includes support for React server components.
Getting started with next-intl
To integrate next-intl into your Next.js project, start by installing the library with the following command:
npm install next-intl
Once installed, next-intl integrates with the App Router using a [locale]dynamic segment.
#Setting up your Next.js project for internationalization
Organize your project directory by creating a [locale] directory within the /app folder and adding all files to the folder. For example, this is a simple Next.js application structure with three pages moved into the [locale] folder:
|--/app
|--/[locale]
|--/about
|-- page.js
|--/blog
|--/[postId]
|-- page.js
|-- page.js
|--/components
|-- features.js
|-- hero.js
|-- navbar.js
|-- layout.js
|-- page.js
Next, proceed with the following configuration steps:
1. Localizing messages
Depending on your workflow preference, you can store messages locally or fetch them from a remote source, such as a translation management system.
At the root of your project, create a messages folder where you can create JSON files for each locale, such as messages/en.json:
{
"Home":{
"Hero":{
"Title":"Next.js Internalization Demo",
"Subtitle":"This demo uses Next.js and the next-intl package to create a multi-language website. We later also explore how it works with Hygraph.",
"CallToAction":"Read about us"
}
}
}
This file is organized with keys referencing each value, which simplifies locating, updating, and collaborating on content. For instance, all content related to the Home page is grouped under the Home object. Within this object, further categorization can be done for different sections, such as the Hero section and the Features section.
Also, create a messages/fr.json for the French version:
{
"Home":{
"Hero":{
"Title":"Démonstration de l'internationalisation avec Next.js",
"Subtitle":"Cette démo utilise Next.js et le package next-intl pour créer un site web multilingue. Nous explorons également son fonctionnement avec Hygraph.",
"CallToAction":"Lisez à propos de nous"
}
}
}
Always ensure the keys are the same across all files, as that is what will be used to render the text.
2. Configuring Next.js
Set up a plugin to alias your i18n configuration to Server Components by updating your next.config.mjs if you're utilizing ECMAScript modules:
importcreateNextIntlPluginfrom'next-intl/plugin';
const withNextIntl =createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig ={};
exportdefaultwithNextIntl(nextConfig);
3. Defining locale-specific configurations
next-intl allows for a per-request configuration setup. In src/i18n.js, specify messages and other options based on the user's locale:
For this project, only English and French will be used. You can add more locales.
Having set up next-intl in your Next.js project, activating internationalization involves using the t() method, a function provided by next-intl for fetching translated strings. This method is accessed through the useTranslations hook, which you can import directly from the next-intl library.
This approach utilizes a key to retrieve the corresponding value. For example, navigating to http://localhost:3000/en displays the English version of the Hero section, while http://localhost:3000/fr shows its French counterpart.
Interpolation is a technique for inserting dynamic values into predefined text. It's beneficial for creating adaptable messages that may vary based on user input or other variables. A common use case is greeting users by name:
"message":"Hello {name}!"
By replacing {name} with a dynamic value, the message becomes personalized:
t('message',{name:'Jane'});
Resulting in:
"Hello Jane!"
Cardinal pluralization
This addresses the need to format messages differently based on numerical values, especially to distinguish between singular and plural forms. A classic example involves indicating the number of followers:
"message":"You have {count, plural, =0 {no followers yet} =1 {one follower} other {# followers}}."
This setup allows for different messages based on the value of count. For instance:
If count is 0, the message is: "You have no followers yet."
If count is 1, the message is: "You have one follower."
For any other number, say 3580, the message is: "You have 3,580 followers."
The # symbol is used to represent the actual number, formatted appropriately.
Ordinal pluralization
Ordinal pluralization is similar to cardinal pluralization but is used for ordering rather than quantity. It helps in formatting messages that relate to ranks or positions.
"message":"It's your {year, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} birthday!"
This message would allow for a correct ordinal suffix to be applied based on the year value:
1st, 2nd, 3rd (special cases for one, two, and few in English)
4th, 5th, ... 21st, 22nd, ... (using other for all other numbers)
next-intl offers a comprehensive solution to the complex challenge of internationalizing date and time formats, accommodating the diverse preferences found across global locales. Since date formats can vary widely from region to region, adopting a flexible approach to date and time representation in international applications is crucial.
The next-intl library leverages the ICU (International Components for Unicode) syntax to simplify incorporating dates and times within localization files. This syntax allows for directly embedding dynamic date formats into your messages, utilizing placeholders for dates, thus streamlining the internationalization process.
Here's an example in an English localization file (en.json), demonstrating the use of a placeholder for the current date in a short format:
// en.json
{
"todayDate":"Today's date is {currentDate, date, short}."
}
next-intl supports predefined date formats such as short, full, long, and medium. It also allows defining custom date formats using “date skeletons". For instance, to display a date in a specific custom format, you could specify it in your localization file like so:
// en.json
{
"todayDate":"Today's date is {currentDate, date, ::yyyyMd}."
}
The :: prefix signifies the use of a custom skeleton format, granting developers precise control over how dates are presented. The next-intl documentation offers a detailed guide on the available formats and skeletons.
To integrate a date within a Next.js page or component, the t() function is utilized:
<p>{t('todayDate',{currentDate:newDate()})}</p>
By supplying the current date to this method, next-intl dynamically renders the date in the format appropriate to the user's locale. For example, an English locale might display as "Today's date is 2/25/24," whereas in a French locale, it would appear as "La date d'aujourd'hui est 25/02/24."
Furthermore, next-intl facilitates custom date formats within messages, allowing developers to define formatters based on DateTimeFormat options. These custom formatters can be named and utilized throughout your application:
<p>
{t(
'todayDate',
{currentDate:newDate()},
{
dateTime:{
short:{
day:'numeric',
month:'short',
year:'numeric',
},
},
}
)}
</p>
#Switching languages with App Router using next-intl
next-intl provides drop-in replacements for common Next.js navigation APIs that automatically handle the user locale behind the scenes. There are two strategies to achieving this, but the straightforward method is using shared pathnames.
With this strategy, the pathnames of your app are identical for all locales. This is the simplest case, because the routes you define in Next.js will map directly to the pathnames a user can request.
To create navigation APIs for this strategy, use the createSharedPathnamesNavigation function. Create a navigation.js in your src folder and add the following:
With this configuration, you gain access to routing components and methods like Link and usePathname, enabling intuitive navigation within your Next.js project.
Next, you can incorporate language switch functionality in your Navbar or any page you wish by attaching the pathname to the href property and a locale. For example, here is a navbar.js component:
Link and usePathname are imported from the naviagtion.js file in the above code. Also, you can handle switching between different languages by attaching the pathname to the href property and a locale.
For this guide, let’s use an existing project, aiming to localize it and integrate its content with a Next.js application. Begin by duplicating a simple blog project in the Hygraph marketplace. This action will replicate the schema and all its content, a process that may take a few moments. Once completed, the next step involves localizing the fields.
Navigate to the schema editor through the schema section. This interface allows adding, editing, or deleting fields and establishing model relationships. To localize a field, hover over it, select Edit field, check the Localize field option, and update. Repeat this process for all fields you wish to localize.
Subsequently, add the languages of your choice by accessing Project Settings > Locales.
With languages configured, proceed to Content to update existing content with the localized versions. Enable the localization fields by clicking the eye icon next to the locale.
After publishing the posts, you are ready to consume them into your Next.js application.
#Integrating localized content into Next.js with GraphQL
In Next.js, you can query GraphQL content with the @apollo/client library. Install the library by running the following command in your project directory:
npm i @apollo/client
For this Next.js project, you configured internationalization routing with the next-intl library. Alternatively, you can configure internationalization without the next-intl library since Next.js has inbuilt internalization routing configurations.
With the internalization routing already set up, you have access to the locales parameter, which would be used to query the content.
Once your queries are working, you can use them in the Next.js project. Before you make the request, retrieve the high performance c**ontent API, which gives you access to the Hygraph content. You can get this from the Project settings > Endpoints** page.
Next, implement this in the Blog page of the sample application (blog/page.js). Here is an example where the list of all posts from the Hygraph project is fetched into Next.js:
In the code above, the getPosts function is defined to fetch posts from Hygraph for a specific locale. This function utilizes the ApolloClient from @apollo/client, configured with Hygraph's API endpoint and an in-memory cache for efficient data management. The GraphQL query within this function requests posts for the specified locale, retrieving their id, title, slug, and excerpt.
The query is dynamically constructed to include the locale parameter, allowing for retrieving localized content based on the user's language preference. This is crucial for delivering a localized user experience, as content is fetched and displayed according to the user's selected language.
Fetching dynamic posts
Similarly, dynamic posts can be fetched and displayed on individual blog pages (blog/[slug]/page.js) using a comparable approach:
This guide has walked you through leveraging the next-intl library and Hygraph with Next.js for effective internationalization and localization of a web application.
Following these steps ensures your application reaches a wider audience and provides a more inclusive and user-friendly experience across diverse languages and cultures.
Blog Author
Joel Olawanle
Joel Olawanle is a Frontend Engineer and Technical writer based in Nigeria who is interested in making the web accessible to everyone by always looking for ways to give back to the tech community. He has a love for community building and open source.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.