![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
nextjs-i18n
Advanced tools
I18n hook and component for Next.js with support for plurals, interpolations and JSX substitutions
I18n hook and component for Next.js with support for plurals, interpolations and JSX substitutions
Tested with React and Preact
npm i -S nextjs-i18n
<I18n />
Componentimport { I18n } from "nextjs-i18n"
function Component = () => (
<div>
<I18n en="Hello {{name}}" pt="Olá, {{name}}" params={{
name: "John Doe"
}} />
</div>
)
useI18n
hookimport { useI18n } from "nextjs-i18n"
function Component = () => {
const { t } = useI18n()
return (
<Header howdy={
t({
en: "Hello {{name}}",
pt: "Olá, {{name}}",
params: {
name: "John Doe",
},
})
} />
)
}
import { I18n } from "nextjs-i18n"
function Component = (articles: Article[]) => (
<div>
<I18n
en={{
0: "Zero articles",
1: "One article",
2: "Two articles",
n: "Many articles",
}}
pt={{
0: "Zero artigos",
1: "Um artigo",
2: "Dois artigos",
n: "Vários artigos",
}}
count={articles.length}
/>
</div>
)
import { I18n } from "nextjs-i18n"
function Component = (articles: Article[]) => (
<div>
<I18n
en={`Hi, {{uppercase name.first}}. See your <link>messages</link> of <b>{{today "m/d/Y"}}</b>`}
pt={`Olá {{name.first}}. Acesse suas <link>mensagens</link> do dia <b>{{today "d/m/Y"}}</b>`}
params={{
name: {
first: "Jane",
last: "Doe",
},
link: <a href="/messages" />,
b: <strong />,
uppercase: (value: string) => {
return value.toUpperCase()
},
today: (format: string) => {
const date = new Date()
return format.replace(/d|m|Y/g, (match) => {
switch (match) {
case "d": return date.getDate()
case "m": return date.getMonth() + 1
case "Y": return date.getFullYear()
}})
},
}}
/>
</div>
)
The example above would return the following JSX.Element
(using locale en
):
<>
Hi, JANE. See your <a href="/messages">messages</a> of{" "}
<strong>2/28/2021</strong>
</>
{{variable}}
performs a direct variable substitution{{func variable}}
invokes func
and passes the result of variable substitution{{func "123"}}
invokes func
and passes literal string 123
<tag>Something</tag>
does JSX interpolation using JSX Element passed in tag
key.Note: A valid JSX.Element
array is returned by I18n when at least one parameter is a JSX.Element
.
Be careful when using t
in contexts that only expect strings, such as backends.
This is a list of things we want to provide in the future:
FAQs
I18n hook and component for Next.js with support for plurals, interpolations and JSX substitutions
The npm package nextjs-i18n receives a total of 5 weekly downloads. As such, nextjs-i18n popularity was classified as not popular.
We found that nextjs-i18n demonstrated a not healthy version release cadence and project activity because the last version was released 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.