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.