loctool for Markdown devs
loctool have a ilib-loctool-ghfm plugin for github-flavored markdown file localization.
loctool reads the markdown file, extracts the translatable parts into a file, and creates a file to pass to the translator. Then use the xliff file with the translations to generate a localized md file.
Input file type | Output file type | Sample |
---|---|---|
md | md | here |
1) Extract localizable Strings
Normal Markdown is broken into paragraphs and phrases using the remark family of parsers.
Things to know
Whenever there is syntax in the markdown that translators should not touch, this plugin converts them into xml-like components.
This is _bold_ and *italic* text.
⟶
This is <c0>bold</c0> and <c1>italic</c1> text.
- Snippets of code are not processed.
There are many instances of `numcount` used in the code.
⟶There are many instances of <c0/> used in the code.
Embed HTML in the markdown and it will be processed as above using the XML-like components.
This text is <b>bold</b> and contains a <span font="foo">different font</span>.
⟶
This text is <c0>bold</c0> and contains a <c1>different font</c1>.
2) Prepre XLIFF files
Prepare multi-language XLIFF files with translation.
With loctool parameter or through a config file, It can set xliff files location.
// a) loctool option-x or --xliffsSpecify the dir where the xliffs files live. Default: "."// b) set in project.json config file..."settings": {"xliffsDir": "./xliffs",...
3) Write config file for loctool
Make sure plugin
are written correctly in config file.
i.e) project.json
..."plugins": ["ilib-loctool-ghfm],"settings": {...."markdown": {"mappings": {"**/en-US/*.md": {"template": "locale/[locale]/[filename]","frontmatter": ["Title", "Description"]}}}}
This plugin now supports mappings:
The mappings allow you to match a particular path name and apply particular settings to that path, such as an output path name template.
The template follows the syntax for path name templates defined in the the loctool itself.
The frontmatter setting specifies an array of strings that represent the names of the fields in the frontmatter that should be localized.
The frontmatter is parsed as a yaml file using the ilib-loctool-yaml plugin.
Any fields not listed in the frontmatter list will be preserved but not be localized.
If frontmatter is set to "true" instead of an array, all fields will be localized. If frontmatter is set to "false", or if it is not given, then no fields will be localized.
4) Run the loctool - Generate localization data
There is a sample application to see md file localization. Visit here. ➡ link
If you run loctool according to the configuration above, the output will be generated under the locale
directory.