t

transl

@preview

Easy and simple translations for words and expressions, with support for localization

v0.2.1
MIT-0

Package Information

Last Updated
Categories
languagesutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/transl:0.2.1

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/transl:0.2.1": *

Version History

0.2.1
3e4aeeada2ab...
0.2.0
681f8ff9cce0...
0.1.1
84da074d531a...
0.1.0
b697171704e2...

Translator

Get Manual
Usage tips
Example PDF
Example source code
Changelog file
Contribute with development

Quick Start

#import "@preview/transl:0.2.1": transl
#set text(lang: "es")

#transl(data: yaml("database.yaml"))

#transl("I love you")

#show: transl.with("love")

Description

Get comprehensive and localized translations, with support for regular
expressions and Fluent files. This package
comes with only one #transl command used to both set the translation database
and retrieve translations.

The expressions are the texts to be translated; they can be words, phrases, or
regular expression strings. Multiple expressions can be used in a single command,
where each one will be retrieved and concatenated (separated by space).

Feature List

  • Automatic translation to #text.lang language
  • Support for #text.region
  • Language id notation (lang-REGION)
  • Robust translation formats
    • YAML/TOML (multilingual)
    • Fluent markup (single language)
    • YAML/TOML + Fluent (multilingual)
  • Support for #show rules
  • Regular expressions
  • Multiple ways to obtain values
    • Retrieve opaque #context() values
    • Retrieve context-dependent strings
    • Retrieve plain strings
  • Localization arguments
    • Standard databases (basic)
    • Fluent databases

Translation databases

The command needs to be fed with translation database files to function correctly.
These databases can be written in YAML/TOML and/or Fluent each.

Standard databases

l10n: std
lang:
  expression: Translation

Allows to define translations for expressions in various languages. Set as:

#transl(data: yaml("std.yaml"))

Fluent databases

l10n: ftl
lang: |
  identifier = Translation

Allows to define multiple Fluent files (as strings) with translations for
various languages. Set as:

#transl(data: yaml("ftl.yaml"))

Fluent files

identifier = Translation

Allows to define an individual Fluent file with translations for a single language.
Set as:

#transl(data: read("xy.ftl"), lang: "xy")

Although written from scratch, the conceptual structure of the package is
heavily inspired by the linguify
package; the Fluent WASM plugin was forked from this excellent package.