
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
next-intl-split
Advanced tools
A loader for next-intl to split translation files properly inside a Next.js app. Using next-intl-split
you can separate your translations for maintaining purposes while the package automatically merges the content into a single translation object.
Run the following command to install the package:
npm i next-intl-split
Note: You need to have the next.js
and next-intl
installed to make the next-intl-split
work as expected.
next-intl
built-in split approach?The approach provided by next-intl
itself can be convincing but as it puts everything together, you may end up with duplicated names or very long key names for your translation strings. So in some cases, this can be its cons:
homeHeroMainButtonTitle
namespace
approach properly.On the other hand next-intl-split
is a tiny package (just a few utilities to help you) that lets you have a cleaner way of managing your translations and not worry about naming conflicts.
home.hero.button.main
namespace
approach. Using the namespace the above name could be like button.main
getRequestConfig
utility.JSON
files.JSON
files.After installation,
In your desired path, create your dictionaries (or whatever you name that). It is important to name the translation files index.json
Example view of translation files:
// /src/i18n
└── dictionaries
// English
├── en
| ├── shared
| | └── header
| | └── index.json
| ├── home
| | ├── hero
| | | └── index.json
| | └── featured
| | └── index.json
| └── about
| └── hero
| └── index.json
// Spanish
├── es
| ├── shared
| | └── header
| | └── index.json
| ├── home
| | ├── hero
| | | └── index.json
| | └── featured
| | └── index.json
| └── about
| └── hero
| └── index.json
// Persian
└── fa
├── shared
| └── header
| └── index.json
├── home
| ├── hero
| | └── index.json
| └── featured
| └── index.json
└── about
└── hero
└── index.json
In the getRequestConfig
function, wrap the messages
object with loadI18nTranslations
utility.
import { notFound } from 'next/navigation';
import { getRequestConfig } from 'next-intl/server';
import { loadI18nTranslations } from 'next-intl-split/load';
// Can be imported from a shared config
const locales = ['en', 'es', 'fa'];
export default getRequestConfig(async ({ locale }) => {
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) notFound();
const messages = loadI18nTranslations('./src/i18n/dictionaries/', locale);
return {
messages,
};
});
import { getRequestConfig } from 'next-intl/server';
import { loadI18nTranslations } from 'next-intl-split/load';
export default getRequestConfig(async () => {
const locale = 'en';
const messages = loadI18nTranslations('./src/i18n/dictionaries/', locale);
return {
locale,
messages,
};
});
In the getStaticProps
function, wrap the messages
object with loadI18nTranslations
utility.
// ...
export async function getStaticProps(context) {
const messages = loadI18nTranslations(
'./src/i18n/dictionaries/',
context.locale
);
return {
props: {
messages,
},
};
}
FAQs
A loader for next-intl to split translation files properly.
The npm package next-intl-split receives a total of 842 weekly downloads. As such, next-intl-split popularity was classified as not popular.
We found that next-intl-split demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.