product icon

Paraglide JS

App

#Architecture

Paraglide uses a compiler to generate JS functions from your messages. We call these "message functions".

Message Functions are fully typed using JSDoc. They are exported individually from the messages.js file making them tree-shakable. When called, they return a translated string. Message functions aren't reactive in any way, if you want a translation in another language you will need to re-call them.

This design avoids many edge cases with reactivity, lazy-loading, and namespacing that other i18n libraries have to work around.

In addition to the message functions, ParaglideJS also emits a runtime. The runtime is used to set the language tag. It contains less than 50 LOC (lines of code) and is less than 300 bytes minified & gzipped.

Diagram of the Paraglide Compiler Architecture

Paraglide consists of four main parts:

PartDescription
CompilerCompiles messages into tree-shakable message functions
MessagesThe compiled tree-shakable message functions
RuntimeA runtime that resolves the language tag of the current user
Framework Library(optional) A framework library that adjusts the runtime for different frameworks

#Compiler

The compiler loads an Inlang project and compiles the messages into tree-shakable and typesafe message functions.

Input

// messages/en.json
{
  "hello": "Hello {name}!"
}

Output

// src/paraglide/messages/en.js

/**
 * @param {object} params
 * @param {string} params.name
 */
export const hello = (params) => `Hello ${params.name}!`