Skip to content

codenautas/multilang

Repository files navigation

multilang

Tools for multilanguage & Markdown multilang

npm-version downloads build coverage

language: English also available in: Spanish - German

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 open and close

Then with multilang the other languages ​​are extracted to generate one file for each of the other languages ​​defined

Install

$ npm install multilang -g

How to use

$ multilang doc-en.md

A .md file is generated for the other languages written in doc-en.md file

Multilanguage document format

Any HTML or Markdown document is a multilenguage document if it has a main multilanguage directive.

Example

<!--multilang v0 en:README.md es:LEEME.md fr:LISEZMOI.md de:LIESMICH.md -->
<!--multilang buttons-->

language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
also available in:
[Spanish](LEEME.md)  [French](LISEZMOI.md)  [German](LIESMICH.md)

<!--lang:en-->
This is a little example
<!--lang:es--]
Este es un pequeño ejemplo
[!--lang:fr--]
Ce est un petit exemple
[!--lang:de--]
Das ist ein Beispiel
[!--lang:*-->

<!--lang:en-->
"*" means all languages
<!--lang:es--]
"*" es para indicar todos los idiomas
[!--lang:fr--]
"*" est d'indiquer toutes les langues
[!--lang:de--]
"*" steht für alle Sprachen
[!--lang:*-->
All you need is multilang!

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 * for all languages)

API

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

License

MIT

...................................

About

Tools for multilanguage & Markdown multilang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •