
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
next-intlayer
Advanced tools
Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.
Intlayer is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, Next.js, and Express.js.
The next-intlayer
package allows you to internationalize your Next.js application. It provides context providers and hooks for Next.js internationalization. Additionally, it includes the Next.js plugin for integrating Intlayer with Webpack or Turbopack, as well as middleware for detecting the user's preferred locale, managing cookies, and handling URL redirection.
Internationalizing your Next.js application is essential for serving a global audience effectively. It allows your application to deliver content and messages in the preferred language of each user. This capability enhances user experience and broadens your application's reach by making it more accessible and relevant to people from different linguistic backgrounds.
Install the necessary package using your preferred package manager:
npm install next-intlayer
yarn add next-intlayer
pnpm add next-intlayer
With Intlayer, you can declare your content in a structured way anywhere in your codebase.
By default, Intlayer scans for files with the extension .content.{ts,tsx,js,jsx,mjs,cjs}
.
You can modify the default extension by setting the
contentDir
property in the configuration file.
.
├── intlayer.config.ts
└── src
└── components
├── ClientComponent
│ ├── index.content.ts
│ └── index.tsx
└── ServerComponent
├── index.content.ts
└── index.tsx
next-intlayer
is made to work with the intlayer
package.intlayer
is a package that allows you to declare your content anywhere in your code. It converts multilingual content declarations into structured dictionaries that integrate seamlessly into your application.
Here’s an example of content declaration:
import { t, type Dictionary } from "intlayer";
const clientComponentContent = {
key: "client-component",
content: {
myTranslatedContent: t({
en: "Hello World",
fr: "Bonjour le monde",
es: "Hola Mundo",
}),
numberOfCar: enu({
"<-1": "Less than minus one car",
"-1": "Minus one car",
"0": "No cars",
"1": "One car",
">5": "Some cars",
">19": "Many cars",
}),
},
} satisfies Dictionary;
export default clientComponentContent;
Once you have declared your content, you can use it in your code. Here's an example of how to use the content in a React component:
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
export const ClientComponentExample: FC = () => {
const { myTranslatedContent } = useIntlayer("client-component"); // Create related content declaration
return (
<div>
<p>{myTranslatedContent}</p>
</div>
);
};
"use client";
import { useIntlayer } from "next-intlayer";
const ClientComponentExample = () => {
const { myTranslatedContent } = useIntlayer("client-component"); // Create related content declaration
return (
<div>
<p>{myTranslatedContent}</p>
</div>
);
};
"use client";
const { useIntlayer } = require("next-intlayer");
const ClientComponentExample = () => {
const { myTranslatedContent } = useIntlayer("client-component"); // Create related content declaration
return (
<div>
<p>{myTranslatedContent}</p>
</div>
);
};
Intlayer provides a lot of features to help you internationalize your Next.js application. Here are some of the key features:
generateMetadata
function provided by Next.js. You can use the getTranslation
function to translate your metadata.getMultilingualUrls
function to generate multilingual URLs for your sitemap.getMultilingualUrls
function. This function generates multilingual URLs for your sitemap.To learn more about these features, refer to the Next.js Internationalization (i18n) with Intlayer and Next.js 15 App Router guide.
next-intlayer
packageThe next-intlayer
package also provides some functions to help you to internationalize your application.
FAQs
Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.
The npm package next-intlayer receives a total of 17,524 weekly downloads. As such, next-intlayer popularity was classified as popular.
We found that next-intlayer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.