Tools for multilanguage & Markdown multilang
In a Markdown or HTML-like file is written the documentation in multiple languages.
One of these languages is the main, the others are commented with <!-- and -->
Then with multilang
the other languages are extracted to generate one file for each of the other languages defined
$ npm install multilang -g
$ multilang doc-en.md
A .md file is generated for the other languages written in doc-en.md
file
Any HTML or Markdown document is a multilenguage document if it has a main multilanguage directive.
<!--multilanguage v0 en:README.md es:LEEME.md fr:LISEZMOI.md-->
<!--multilanguage buttons-->
language: English see also: [Spanish](README.md) [French](LISEZMOI.md)
<!--lang:es-->
Este es un pequeño ejemplo
<!--lang:en--]
This is a little example
[!--lang:fr--]
Ce est un petit exemple
[!--lang:*-->
All you need is multilang!
<!--lang:es-->
"*" means all languages
<!--lang:en--]
"*" es para indicar todos los idiomas
[!--lang:fr--]
"*" est d'indiquer toutes les langues
In this example:
<!--multilanguage v0 en:README.md es:LEEME.md fr:LISEZMOI.md-->
is the directive for declare the languages
<!--multilanguage buttons-->
is the directive for declaring the place for the button section
[!--lang:fr--]
is the directive for declaring the language of the next section (use * from all languages)
var fs = require('fs');
var multilang = require('multilang');
var englishText = fs.readFileSync('README.md', {encoding:'utf8'});
var warnings = multilang.getWarnings(englishText);
if(warnings.lengt){
console.log('WARN', warnings);
}
var spanishText = multilang.changeDoc(englishText,'es');
console.log('spanish.md',spanishText);
(note about the example: do not use Sync functions in production, use async or promise version as you can see in codenautas
function | use |
---|---|
changeDoc(text,lang) | receives a multilang text and a language code and returns de text of specified lang |
warnings(text) | receives a list of warnings and returns a multilang text |
...................................