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/ppx.html

PPX rewriter

The ocsigen-i18n-rewriter PPX extension transforms [%i18n ...] expressions into calls to the generated translation functions.

Setup

Add the PPX to your dune file:

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

where MyI18n is the name of the module generated by ocsigen-i18n-generator (the basename of the output file, capitalized).

Without dune, use:

-ppx 'ocsigen-i18n-rewriter --default-module MyI18n'

Expressions

The PPX supports the following forms:

Expression

Meaning

[%i18n foo]

Calls MyI18n.Tr.foo () (HTML)

[%i18n S.foo]

Calls MyI18n.S.foo () (string)

[%i18n bar ~x:expr]

Passes a labelled argument

[%i18n OtherMod.foo]

Calls OtherMod.Tr.foo ()

[%i18n OtherMod.S.foo]

Calls OtherMod.S.foo ()

Module affixing

To avoid redundancy when using multiple i18n modules, you can auto-prefix and auto-suffix module names:

(preprocess (pps ocsigen-i18n -- --default-module MyI18n --prefix Pr_ --suffix _i18n))

With this configuration, [%i18n Feature.foo] becomes Pr_Feature_i18n.Tr.foo ().

Important: Do not name your i18n file s.tsv, as S is reserved for the string module.