npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@leancodepl/mail-translation

v10.1.2

Published

A command-line tool for processing MJML and plaintext email templates with optional internationalization support

Readme

@leancodepl/mail-translation

A command-line tool for processing MJML and plaintext email templates with optional internationalization support. Compiles MJML templates to HTML and can convert templates with translation placeholders into localized email files for Kratos or Razor templating systems.

Installation

npm install -D @leancodepl/mail-translation

Usage

npx @leancodepl/mail-translation

# Or with custom config file
npx @leancodepl/mail-translation --config custom-config.json

Configuration

Mail translation is configured using lilconfig. Valid configuration sources include:

  • .mail-translationrc.json, .mail-translationrc for JSON format
  • .mail-translationrc.yaml, .mail-translationrc.yml for YAML format
  • mail-translation.config.js, mail-translation.config.cjs, .mail-translationrc.js, .mail-translationrc.cjs for JavaScript configuration files
  • Path to JavaScript/JSON/YAML config file passed via optional --config/-c parameter

Configuration Options

  • mailsPath (string, required) - Path to directory containing MJML email templates
  • outputPath (string, required) - Directory where processed templates will be saved
  • outputMode ("kratos" | "razor", required) - Target templating system format
  • translationsPath (string, optional) - Path to translation files directory. When omitted, templates are compiled without translations
  • plaintextMailsPath (string, optional) - Path to plaintext templates (defaults to mailsPath)
  • defaultLanguage (string, required when translationsPath is provided) - Default language code for templates with translations
  • languages (string[], optional) - Array of language codes to process. When omitted, all languages found in translation files are processed
  • kratosLanguageVariable (string, optional, Kratos mode only) - Variable path used for language detection in Kratos templates (defaults to ".Identity.traits.lang").

JSON Schema

The package exports a JSON Schema file (schema.json) that can be used for configuration validation and IDE autocompletion. For JSON configuration files, add the $schema property to get autocompletion and validation. Example:

{
  "$schema": "./node_modules/@leancodepl/mail-translation/schema.json"
}

Example Configuration

With translations:

{
  "$schema": "./node_modules/@leancodepl/mail-translation/schema.json",
  "translationsPath": "./translations",
  "mailsPath": "./templates/mjml",
  "plaintextMailsPath": "./templates/plaintext",
  "outputPath": "./dist/emails",
  "outputMode": "kratos",
  "defaultLanguage": "en",
  "kratosLanguageVariable": ".Identity.traits.locale", // optional - defaults to .Identity.traits.lang
  "languages": ["en", "pl", "de"] // optional - will auto-detect from translation files
}

MJML compilation only (no translations):

{
  "$schema": "./node_modules/@leancodepl/mail-translation/schema.json",
  "mailsPath": "./templates/mjml",
  "outputPath": "./dist/emails",
  "outputMode": "kratos"
}

Template Structure

MJML Templates

Place MJML files in your mailsPath directory:

templates/
├── welcome.mjml
├── password-reset.mjml
└── components/
    ├── header.mjml
    └── footer.mjml

Translation Files

Create JSON translation files in your translationsPath:

translations/
├── en.json
├── pl.json
└── de.json

Example translation file (en.json):

{
  "welcome_title": "Welcome to our platform!",
  "welcome_greeting": "Hello {name}!",
  "verify_button": "Verify Account",
  "footer_text": "© 2024 Company. All rights reserved."
}

Template Syntax

Use ((t "key")) for simple translations:

<mj-text>((t "welcome_title"))</mj-text>

Use ((t "key", {...})) for parameterized translations with JSON objects:

<mj-text>((t "welcome_greeting", {"name": "{{ .Identity.traits.first_name }}"}))</mj-text>

Use multiple parameters for complex translations:

<mj-text>
  ((t "account_info", {"email": "{{ .Identity.traits.email }}", "plan": "{{ .Identity.traits.plan }}"}))
</mj-text>

Output Modes

Kratos Mode

Generates Go template files compatible with Ory Kratos identity management system:

File Structure:

  • Body templates: template_name.gotmpl (e.g., welcome.gotmpl)
  • Plaintext templates: template_name.plaintext.gotmpl (e.g., welcome.plaintext.gotmpl)
  • Single file with multiple language template definitions

Template Syntax:

  • Uses Go template {{define "language"}} blocks for each language
  • Template selection logic at the bottom using Kratos variables
  • Kratos variables available (e.g., {{ .Identity.traits.email }})
  • Language detection via {{ .Identity.traits.lang }} by default (configurable via kratosLanguageVariable)

Example Output:

{{define "en"}}
<html>
<body>
  <h1>Welcome to our platform!</h1>
  <p>Hello {{ .Identity.traits.first_name }}!</p>
  <p>Thank you for registering with us.</p>
  <p><strong>Verification Code: {{ .VerificationCode }}</strong></p>
  <p>Account: {{ .Identity.traits.email }}</p>
</body>
</html>
{{end}}

{{define "pl"}}
<html>
<body>
  <h1>Witamy na naszej platformie!</h1>
  <p>Witaj {{ .Identity.traits.first_name }}!</p>
  <p>Dziękujemy za rejestrację.</p>
  <p><strong>Kod weryfikacyjny: {{ .VerificationCode }}</strong></p>
  <p>Konto: {{ .Identity.traits.email }}</p>
</body>
</html>
{{end}}

{{- if eq .Identity.traits.lang "pl" -}}
{{ template "pl" . }}
{{- else -}}
{{ template "en" . }}
{{- end -}}

Razor Mode

Generates C# Razor template files:

File Structure:

  • HTML templates: TemplateName.cshtml (default language), TemplateName.language.cshtml (other languages)
  • Plain text templates: TemplateName.txt.cshtml (default language), TemplateName.language.txt.cshtml (other languages)
  • Separate files for each language

Template Syntax:

  • Uses Razor syntax: @Model.Property
  • CSS @ symbols escaped as @@ for media queries

Example Output:

Assuming english is the default language, the output will be:

English template (notification.cshtml):

<html>
  <body>
    <h1>System Notification</h1>
    <p>Dear @Model.User.FullName,</p>
    <p>Your account status has been updated to: @Model.Status as of @Model.UpdateDate.</p>
    <p>Action required: @Model.RequiredAction</p>
    <a href="@Model.ActionUrl">Take Action Now</a>
    <p>Reference: @Model.ReferenceNumber</p>
  </body>
</html>

Polish template (notification.pl.cshtml):

<html>
  <body>
    <h1>Powiadomienie systemowe</h1>
    <p>Szanowny/a @Model.User.FullName,</p>
    <p>Status Twojego konta został zaktualizowany na: @Model.Status z dniem @Model.UpdateDate.</p>
    <p>Wymagane działanie: @Model.RequiredAction</p>
    <a href="@Model.ActionUrl">Wykonaj działanie teraz</a>
    <p>Numer referencyjny: @Model.ReferenceNumber</p>
  </body>
</html>