package ocsigen-i18n

All checked builds pass
  1. Overview
  2. Docs
Internationalisation of OCaml apps

Install

dune-project
 Dependency

Authors

Maintainers

Sources

6.0.0.tar.gz
md5=dfed0db1af2dc9ceb67cbe1bc57ae606
sha512=ac069ff33ecddb6f730ebb00b28e24cb75d0d788e02192bbede1838ae225f1a8ed00696f09f04a76f5627fac9659095219644e6675266816cec16b4f154abc97

doc/intro.html

Introduction

Ocsigen-i18n provides internationalisation (i18n) support for OCaml applications.

Translations are described in TSV (tab-separated values) files. A code generator produces an OCaml source file with the translations, and a PPX extension provides a convenient syntax to use them in your program.

Ocsigen-i18n supports three modes:

  • Plain OCaml: generates simple string functions (default)
  • Tyxml: generates HTML elements using Tyxml (--tyxml)
  • Eliom: generates client-server code for Eliom apps (--eliom)

Installation

opam install ocsigen-i18n

The package provides three executables:

  • ocsigen-i18n: generates an OCaml (or Eliom) file from a TSV file
  • ocsigen-i18n-rewriter: PPX extension for the [%i18n ...] syntax
  • ocsigen-i18n-checker: PPX checker for i18n expressions

For backward compatibility, ocsigen-i18n-generator is provided as an alias for ocsigen-i18n --eliom.

Quick start

Create a TSV file (e.g. example_i18n.tsv) with your translations:

hello	Hello!	Bonjour !
greeting	Hello {{name}}.	Bonjour {{name}}.

Generate the OCaml file:

ocsigen-i18n --languages en,fr \
  --input-file example_i18n.tsv \
  --output-file example_i18n.ml

For an Eliom application:

ocsigen-i18n --eliom --languages en,fr \
  --input-file example_i18n.tsv \
  --output-file example_i18n.eliom

Use the PPX in your code:

[%i18n hello]
[%i18n greeting ~name:"World"]

With Tyxml or Eliom, variables are HTML elements:

[%i18n greeting ~name:[txt "World"]]

Add the PPX to your dune file:

(preprocess (pps ocsigen-i18n -- --default-module Example_i18n))