mdTranslation is a utility to prepare multi-lingual Markdown documents.

Overview

mdTranslation

mdTranslation is a utility to prepare multi-lingual Markdown documents.

There's also a mdBook preprocessor called mdbook-translation for working with mdBook books.

How does it achieve this?

This is done by associating source contents and their translations together. This association is expressed as a separate Markdown documents within a specific simple format.

This file looks like this:

> Original content 1

* lang_ID1
Translated content written in lang_ID1
* lang_ID2
Translated content written in lang_ID2
****
...

This library can read and compare Markdown contents within each leaf node (paragraphs, list items, etc) to all the original contents here, when there's a match, it will replace it with the corresponding translated content. This makes it possible to do translation without touching the original document.

mdTranslation CLI tools

To use the CLI tools, just type this in the terminal:

cargo install mdtranslation-cli

This allows you to use two commands:

  1. mdtranslation_extract

This tool help you to extract original contents and initial boilerplate into a Markdown file.

For example, if you want to provide a French translation for a.md, you can execute this:

mdtranslation_extract -l fr_FR a.md >> a.i18n.md

The >> here allows the newly generated content be appended to the tail of the file. You can use this method to collect all paragraphs from a book together.

  1. mdtranslation_translate

This tool help you generate a translated and rendered html file for a Markdown file.

For example, if you want to provide a French translation for a.md, and you have the translation file ready at a.i18n.md, you can execute this:

mdtranslation_translate -l fr_FR -t a.i18n.md a.md > a.htm

If you didn't specify the language in a.i18n.md, you can pass an extra -d fr_FR parameter here to tell the program that the language is actually fr_FR. This is useful for single-translated language case, though we encourage you always spell out the actual language for each paragraph.

mdBook-translation preprocessor

There is also a mdBook preprocessor that allows you to use mdTranslation together with mdBook.

  • To install the mdBook preprocessor, just type this in the terminal:
cargo install mdbook-translation
  • After that you can enable this preprocessor for a specific book, by adding this to book.toml:
[preprocessor.translation]
  • Now, before you run mdbook build as usual, you can set up environment variable to ask the preprocessor to generate the book in a specific language.

You need to do this if you're are using Windows cmd.exe:

set MDTRANSLATION_INPUT=book.i18n.md
set MDTRANSLATION_LANG=fr_FR
set MDTRANSLATION_DEFAULT_LANG=fr_FR

Or if you're using a *nix shell:

export MDTRANSLATION_INPUT=book.i18n.md
export MDTRANSLATION_LANG=fr_FR
export MDTRANSLATION_DEFAULT_LANG=fr_FR

The contents of the book will be replaced by the translated contents.

You might also like...
A small utility for tracking the change in opening and closing of issues in a GitHub repo

A small utility for tracking the change in opening and closing of issues in a GitHub repo. This tool can be used to build visualizations for issue triage over time with the hope of motivating closing more issues than are opened.

ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust.
ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust.

gigagei ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust. Installing Use latest pre-built binary from releases Buildi

Utility library to work with tuples.

Utility library to work with tuples.

Devmode is a project management utility for developers.
Devmode is a project management utility for developers.

Dev(mode) Dev(mode) is a project management utility for developers.

Provides utility functions to perform a graceful shutdown on an tokio-rs based service

tokio-graceful-shutdown IMPORTANT: This crate is in an early stage and not ready for production. This crate provides utility functions to perform a gr

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file that you can easily edit or save as backup and apply a saved preset to new repositories.

Progmem utility for the AVR architecture

avr-progmem Progmem utilities for the AVR architectures. This crate provides unsafe utilities for working with data stored in the program memory of an

Emoji-printer - Utility to convert strings with emoji shortcodes to strings with the emoji unicode

Emoji Printer Intro Utility to convert strings with emoji shortcodes (:sushi:) to strings with the emoji unicode ( 🍣 ) Install cargo add emoji-printe

Rs.aws-login - A command line utility to simplify logging into AWS services.

aws-login A command line utility to simplify logging into AWS accounts and services. $ aws-login use ? Please select a profile to use: › ❯ dev-read

Comments
  • Comments are not supported

    Comments are not supported

    <!-- --> comments are not supported. The following errors appear when trying to set a file with comment as translation input:

    mdbook-translation: Failed to process chapter.
    mdbook-translation: Failed to process chapter name.
    
    opened by Endermanbugzjfc 0
  • Splitting translation files for mdBook preprocessor

    Splitting translation files for mdBook preprocessor

    Hi! I'm looking to use mdTranslation and mdbook-translation for ISSOtm/gb-asm-tutorial#25.

    Unfortunately, given that the book is quite large, a single translation file per language is infeasible, much less so one for all translations (as nice as the "many languages per translation file" feature is, I don't think it's useful for this use case). Hence, I would prefer if the preproc read one translation file per input file (i.e. the translation files would be arranged following the same structure as the book's source).

    Here's a command to generate the translation files:

    $ git ls-files -z src | sed -Ez 's,src/(.+\.md)$,\1,;t;d' | xargs -0I {} bash -c 'mkdir -p "$(dirname "translations/@@LANG@@/{}")" && mdtranslation_extract -l @@LANG@@ "src/{}" >"translations/@@LANG@@/{}"'
    

    (Replacing @@LANG@@ with the language of your choice, of course.)

    Would you be interested in upstreaming such changes?

    opened by ISSOtm 0
Owner
Charles Lew
Charles Lew
A safe sync/async multi-producer, multi-consumer channel

Loole A safe async/sync multi-producer multi-consumer channel. Producers can send and consumers can receive messages asynchronously or synchronously:

Mahdi Shojaee 50 Oct 6, 2023
A fast, multi-threaded line counting utility written in Rust.

xloc A fast, multi-threaded line counting utility written in Rust. What is xloc A drop in replacement for bash's wc -l. Your project has x lines of co

null 1 Nov 15, 2021
Incremental, multi-version remote backup tool for block devices.

bsync Incremental, multi-version remote backup tool for block devices. The on-disk backup format is a SQLite database and I've been dogfooding this on

Heyang Zhou 7 Aug 21, 2022
A working example of multi targets compilation for Rust using Github Actions.

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.

Nicolas Vanhoren 41 Dec 17, 2022
Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator

Northstar Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator. Explore the docs » View Demo · Report

Lucas Clerisse 1 Jan 22, 2022
A timer based on a multi-time wheel structure

wheel-timer2 A timer based on a multi-time wheel structure This library uses a multi-layered time wheel structure. When a task is added to the wheel,

orange soeur 1 Jan 25, 2022
Pegasus: A Multi-Node Command Runner

Run a list of commands on a set of SSH nodes. With a bit of optional parametrization.

Jae-Won Chung 19 Dec 7, 2022
Rust library to scan files and expand multi-file crates source code as a single tree

syn-file-expand This library allows you to load full source code of multi-file crates into a single syn::File. Features: Based on syn crate. Handling

Vitaly Shukela 11 Jul 27, 2022
An embedded-hal driver for the TT21100 multi-touch touchscreen controller

tt21100 An embedded-hal driver for the TT21100 multi-touch touchscreen controller. If there is a feature which has not yet been implemented and which

Jesse Braham 5 Jan 9, 2023
Batch rename utility for developers

nomino Batch rename utility for developers How to install Pre-Compiled You can download a pre-compiled executable for Linux, MacOS and Windows operati

Navid 458 Dec 27, 2022