Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
astro-i18n-aut
Advanced tools
astro-i18n-aut
The i18n integration for Astro π§βπBuilt with β€οΈ for all Astro crewmates π§βπ
Provide an internationalization (i18n) integration for Astro that:
defaultLocale
@astrojs/sitemap
Install via npm:
npm install astro-i18n-aut
In your Astro config file:
import { defineConfig } from "astro/config";
import i18n from "astro-i18n-aut";
import sitemap from "@astrojs/sitemap";
const defaultLocale = "en";
const locales = {
en: "en-US", // the `defaultLocale` value must present in `locales` keys
es: "es-ES",
fr: "fr-CA",
};
export default defineConfig({
site: "https://example.com",
trailingSlash: "always",
build: {
format: "directory",
},
integrations: [
i18n({
locales,
defaultLocale,
}),
sitemap({
i18n: {
locales,
defaultLocale,
},
}),
],
});
Now that you have set up the config, each .astro
page will have additional renders with your other languages. For example, src/pages/about.astro
will render as:
/about
/es/about
/fr/about
Please note that the getStaticPaths()
function will only run once. This limitation means that you cannot have translated urls, such as /es/acerca-de
for /about
. However, it also ensures compatibility with @astrojs/sitemap
.
The Astro frontmatter and page content is re-run for every translated page. For example, the Astro.url.pathname
will be:
/about
/es/about
/fr/about
It is up to you to detect which language is being rendered. You can use Astro content collections or any i18n UI framework, such as react-i18next
, for your translations. Here is a pure Hello World
example:
---
import Layout from "../layouts/Layout.astro";
const locale = Astro.url.pathname.slice(1, 3);
let title: string;
switch (locale) {
case "es":
title = "Β‘Hola Mundo!";
break;
case "fr":
title = "Bonjour Monde!";
break;
default:
title = "Hello World!";
}
---
<Layout title={title}>
<h1>{title}</h1>
</Layout>
include
: glob pattern(s) to include (default: ["pages/**/*"]
)exclude
: glob pattern(s) to exclude (default: ["pages/api/**/*"]
)Other Astro page file types:
.astro
.md
.mdx
(with the MDX Integration installed).html
.js
β/β.ts
(as endpoints)cannot be translated. If you choose to use them, please add them to the ignore glob patterns. For example, ["pages/api/**/*", "pages/**/*.md"]
MIT Licensed
PRs welcome! Thank you for your contributions.
Unfortunately, i18n is not a first-class concern for Astro. While Astro documents i18n in their cookbook, they do not support a defaultLocale
.
The other community integrations that Astro links do not support all adapters:
Astro does not easily support two pages having the same content:
/[lang]/about
cannot be undefined or an empty stringrequest.url
is read-only, so it is not possible to retrieve content from a different url'/article': '/blog/[...slug]'
, only '/blog/[...slug]': '/articles/[...slug]'
injectRoute
method cannot inject an entryPoint
that is already being used in the build commandWe duplicate the src/pages
folder multiple times and use injectRoute
as a workaround. You can safely delete any src/astro_tmp_pages_LOCALE
folders, but those will be automatically cleaned on every started and completed build.
FAQs
The i18n integration for Astro π§βπ
The npm package astro-i18n-aut receives a total of 1,389 weekly downloads. As such, astro-i18n-aut popularity was classified as popular.
We found that astro-i18n-aut 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.