Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungGit con contexto: tu primer flujo de ramas y commits en GitKraken(21.09.2026 um 20:38 Uhr)
Sichere ProgrammierungFaster Starts, Less JavaScript Overhead(21.09.2026 um 20:40 Uhr)
Sichere ProgrammierungPolymarket TWAP Market Maker: Quote Engine Design(21.09.2026 um 20:40 Uhr)
Sichere ProgrammierungAgentic Flow for a Simple SPA Anyone Can Build(21.09.2026 um 20:42 Uhr)
Sichere Programmierungephemora-cell 1.0.4: a stateless MCP tool server, now on PyPI!!(21.09.2026 um 20:44 Uhr)
Sichere ProgrammierungBeeLadybug Ironic: Debugging the Code vs. Debugging the Mind(21.09.2026 um 20:49 Uhr)
Sichere ProgrammierungHow Code Reviews Made Me a Happier Developer(21.09.2026 um 20:53 Uhr)
Linux Tipps & HardeningGNOME vs KDE vs Cinnamon for daily use?(21.09.2026 um 20:11 Uhr)
Sichere ProgrammierungGit con contexto: tu primer flujo de ramas y commits en GitKraken(21.09.2026 um 20:38 Uhr)
Sichere ProgrammierungFaster Starts, Less JavaScript Overhead(21.09.2026 um 20:40 Uhr)
Sichere ProgrammierungPolymarket TWAP Market Maker: Quote Engine Design(21.09.2026 um 20:40 Uhr)
Sichere ProgrammierungAgentic Flow for a Simple SPA Anyone Can Build(21.09.2026 um 20:42 Uhr)
Sichere Programmierungephemora-cell 1.0.4: a stateless MCP tool server, now on PyPI!!(21.09.2026 um 20:44 Uhr)
Sichere ProgrammierungBeeLadybug Ironic: Debugging the Code vs. Debugging the Mind(21.09.2026 um 20:49 Uhr)
Sichere ProgrammierungHow Code Reviews Made Me a Happier Developer(21.09.2026 um 20:53 Uhr)
Linux Tipps & HardeningGNOME vs KDE vs Cinnamon for daily use?(21.09.2026 um 20:11 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Astro + Nx + Paraglide - Creating i18n module

As I told in this my other article, I'm learning Astro.build. And one of things that I don't like in the integration with Astro and Paraglide is keep all things in /src folder. In case that you have a large codebase, it could be a…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

As I told in this my other article, I'm learning Astro.build.



And one of things that I don't like in the integration with Astro and Paraglide is keep all things in /src folder.



In case that you have a large codebase, it could be a problem to manage and keep code clean in future. Okay, I know that Astro can manage very well large codebase in final bundle, but the developer experience isn't very well to put all files together.



I'm very familiar with monorepos and specially with Nx, I've working in another projects, small and very large projects, and Nx really helps to organize code by splitting in modules/libs.



The idea in this article is share how to integrate Astro with Nx and create an i18n module to centralize all messages and paraglide things in one module.






Creating repo



First of all we need to create our start repository.



Just to skip Astro and Paraglide setup, I will start from my last article repository: https://github.com/alancpazetto/astro-i18n-dynamic



So, to use it, just clone repository, run install and start project:




git clone https://github.com/alancpazetto/astro-i18n-dynamic
cd astro-i18n-dynamic
npm install
npm start






If you want to start from scratch, you can follow these nice articles:








Adding Nx



Before we continue to 18n module, we need to setup Nx.



This is simple, Nx has the init command that helps to init Nx workspace in an existing code, so just run this:




npx nx@latest init






When Nx command ask for cacheable script, you can select build and setup folder to ./dist (it could be changed in future)



Nx Init console



Feel free to select any other option that command show, this won't impact in this tutorial.






Adding i18n module



If you already uses Nx, you are familiar with Nx Plugins, but if not I will introduce you.



Nx uses a plugin architecture, which you can add or remove a plugin to add or remove features in your workspace.



These plugins can add generators, executors or any other Nx feature.



In our case, we need to create a JS library module, so we will need to plugin JS plugin, called @nx/js.



You can find all Nx Plugins here: https://nx.dev/plugin-registry



So, lets install JS Plugin, by running below command:




npm install -D @nx/js






As installed we can generate our i18n module.



Here I would like to make a recommendation, I really like to use command line tools, however Nx has a nice VSCode Extension that make all generators visually (there are other feature too). So I highly recommend to install this.



But if you doesn't want to use extension or don't use VSCode, no problem, we can run this in terminal:




npx nx generate @nx/js:library --name=i18n --bundler=swc --directory=libs/i18n --importPath=@astro-nx-paraglide/i18n --projectNameAndRootFormat=as-provided --unitTestRunner=none --no-interactive






This will create a module as JS Library using JS plugin, inside libs/i18n path with import path @astro-nx-paraglide/i18n.



You can change to your configs here.



If you want to use VSCode extension, open command palette, search for Nx generate (ui) and select @nx/js:library, add these information in new window:



Nx generate ui






Meeting i18n module



New module will be created inside libs/i18n, and basically it's a JS library, with index.ts as entrypoint and lib folder that could add all library code.



i18n module fodler structure






Setup Paraglide to i18n module



To configure Paraglide in our i18n module, we need to change some things in Paraglide config.



First of all, open your Astro config (like astro.config.mjs) and change paraglide integration outdir:




import { defineConfig } from 'astro/config';
import paraglide from '@inlang/paraglide-astro';

export default defineConfig({
// Use astro's i18n routing for deciding which language to use
i18n: {
locales: ['en', 'pt-br'],
defaultLocale: 'en',
},
output: 'server',
integrations: [
paraglide({
// recommended settings
project: './project.inlang',
outdir: './libs/i18n/src/paraglide', // <=== HERE
}),
],
});







It will setup Astro + Paraglide to looks inside this folder (in code we will import in other way).



We need to setup package.json scripts changing paraglide output dir in build time (build and postinstall script):




{
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "paraglide-js compile --project ./project.inlang --outdir ./libs/i18n/src/paraglide && astro check && astro build",
"preview": "astro preview",
"astro": "astro",
"postinstall": "paraglide-js compile --project ./project.inlang --outdir ./libs/i18n/src/paraglide"
},
}






Now we can rerun postinstall script to regenerate paraglide folder: npm run postinstall



After all we have this folder strucuture:



new module structure



Now we need to export to all code generated paragrlide files.



Paraglide exports 2 folders:





  • messages.js: that contains all translated message functions


  • runtime.js: that contains all runtime function, like which language is setted



So we need to edit library entrypoint (index.ts) to export these files:




export * as messages from './paraglide/messages';
export * as runtime from './paraglide/runtime';







Note: By default Nx setup project "verbatimModuleSyntax": true in tsconfig.json and it cause an erro in i18n module, but you can configure your library tsconfig.json to disable this by editing libs/i18n/tsconfig.json adding "verbatimModuleSyntax": false inside compilerOptions.




By now, we don't need libs/i18n/src/lib folder anymore, just delete it.






Integration Astro app with i18n module



Now it's time to integrate all our code.



If you check ./tsconfig.json, a new compilerOptions.path was added by Nx with importPath informed previously appoint to our library entrypoint.




Note: if you get an import error here, you need to setup compilerOptions.baseUrl to ./.




So to integrate our code with module we'll use this import path in our code:




import { messages, runtime } from '@astro-nx-paraglide/i18n';






In our application files, inside src we need to change all imports from ../paraglide/messages (or runtime) to new import path.



For example in src/components/LanguagePicker.astro:




---
import * as m from '../paraglide/messages';
- import { languageTag } from '../paraglide/runtime';
+ import { runtime } from '@astro-nx-paraglide/i18n';

- const makeUrlForLanguage = (lang: string) => `/${lang}${Astro.url.pathname.replace(`/${languageTag()}`, '')}`;
+ const makeUrlForLanguage = (lang: string) => `/${lang}${Astro.url.pathname.replace(`/${runtime.languageTag()}`, '')}`;
---






And inside our pages, like src/pages/index.astro:




---
import Layout from '../layouts/Layout.astro';
- import * as m from '../paraglide/messages';
- import { languageTag } from '../paraglide/runtime';
+ import { messages as m, runtime } from '@astro-nx-paraglide/i18n';
---

<Layout title={m.homePageTitle()}>
<h1>{m.homePageHeading()}</h1>
- <p>{m.homePageContent({ languageTag: languageTag() })}</p>
+ <p>{m.homePageContent({ languageTag: runtime.languageTag() })}</p>
</Layout>









Cleanning src folder



As module was setted and all imports changed, we can delete the src/paraglide folder, as we don't use it anymore.






Example repository



Here is the example repository: https://github.com/alancpazetto/astro-nx-paraglide



Just clone repository, run install and start project:




git clone https://github.com/alancpazetto/astro-nx-paraglide
cd astro-nx-paraglide
npm install
npm start






Thanks to read and don't forget to give a heat in this article if you like and leave a comment.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Astro + Nx + Paraglide - Creating i18n module

Thematisch verwandte Begriffe: Astro, Paraglide, Creating, i18n · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-77582 | Tinyauth is an authentication and authorization server. Prior to 5.1.0, …
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick