Command Line Interface to Generate i18n Markdown
Project description
Multilingual Markdown Generator
This package provides a command-line interface to manage multilingual contents and generate i18n markdown from a single base file.
🚀 version 1.0.1 🌏 English, Français, 한국어 日本語)
Table of Contents ⚡
Overview 🔎
How It Works
Features
- Auto suffix to file name
- IETF language tags are also available.
- Remove suffix option for one main language
- UTF-8 encoding. So this would support almost all languages. :) 🍷
- Auto table of contents
- Table of contents level options
- Table of contents emoji on-off options
Install
pip3 install mmg --user
Now when you open a new terminal you can use the new command mmg
.
$ mmg --help
mmg [OPTIONS] [FILENAMES]...
Options:
--version Show the current version.
-r, --recursive This recursive option searches all subfolders
based on current directory and converts all base
files.
-y, --yes Confirm the action without prompting
-c, --check / -s, --skip Check the number of language tags of each file
(defualt: --check)
-v, --verbose For example, -v:1, -vv:2, -vvv:3 [x>=0]
--help Show this message and exit.
Update
pip3 install mmg --upgrade --user
Uninstall
pip3 uninstall mmg
How to Use
(0) Make a Base Markdown File
Make {something}.base.md
files. See README.base.md and example.base.md for examples, and Command Tags for rules.
(Note) A wrong format of base-file will break generated style.
(1) File Designation
Enter the *.base.md
files that you want to create in multiple languages as arguments to the mmg
command.
mmg FileName.base.md
Multiple arguments are separated by spaces.
mmg Foo.base.md Bar.base.md Baz.base.md
(2) Recursive Option
If you want to convert all base files in the current directory and subdirectories, use the --recursive
or -r
option.
The recursive option searches all subfolders based on where the command is entered.
You cannot specify a folder as an argument yet.
mmg --recursive
(3) Base File Validation
When your file may have a problem. (Normal is shown in green and abnormal in red.)
$ mmg -r --verbose
----------------------
+ .\README.base.md
[O] Tag count: {'en': 37, 'fr': 37, 'kr': 37}
+ .\example\example.base.md
[X] 4 language(s) not translated.
Tag count: {'en-US': 4, 'fr-FR': 4, 'ko-KR': 5, 'ja-JP': 4, '<Unknown>': 1}
Line 28: This language reappeared before all languages appeared once.
Line 36: A common area appeared before all languages come out.
Line 57: Unknown suffix detected.
Line 59: This language reappeared before all languages appeared once.
----------------------
=> 2 base markdowns were found.
Do you want to convert these files? [y/N]
When your files are ok.
$ mmg -r --verbose
----------------------
+ .\README.base.md
[O] Tag count: {'en': 37, 'fr': 37, 'kr': 37}
+ .\example\example.base.md
[O] Tag count: {'en-US': 4, 'fr-FR': 4, 'ko-KR': 4, 'ja-JP': 4}
----------------------
=> 2 base markdowns were found.
Do you want to convert these files? [y/N]
(4) More explanations
- You can find the
{something}.{suffix}.md
files in the same directory. For example:- By default:
{something}.en.md
,{something}.kr.md
,{something}.es.md
, ... - When no-suffix option on
en
:{something}.md
,{something}.kr.md
,{something}.es.md
, ...
- By default:
- Since this generator overwrites the auto-generated files each time, you do not have to delete them every time when you modify the
{something}.base.md
. Just run step 2 again.
Command Tags
Headers
Headers must be declared before the body begins.
-
Suffix Declaration
Declare the language you want to use. The following example declares
en
andkr
and others as keywords. These keywords are used as suffixes.<!-- multilingual suffix: en, kr, fr, es, jp, cn -->
-
Hidden Suffix (Optional)
The
no suffix
option can prevent the suffix from being appended when creating the file. In other words, settingno suffix
toen
will generateFileName.md
instead ofFileName.en.md
. This is useful because the mainREADME
in GitHub is not recognized when it has a suffix.<!-- no suffix: en -->
Badges
[![Multilingual Markdown Generator](https://img.shields.io/badge/markdown-multilingual%20🌐-ff69b4.svg)](https://github.com/ryul1206/multilingual-markdown)
Main Text
Everything that the parser reads after the tag below is recognized as the main text. (So you have to write the header before main).
-
Keywords
-
Language Classification
The tags that distinguish languages are written in the form
<!-- [keyword] -->
. If one keyword is recognized, it will be recognized as that keyword until another keyword is seen.<!-- [en] --> <!-- [kr] --> <!-- [fr] --> <!-- [es] --> <!-- [jp] --> <!-- [cn] --> ...
-
Common Section
You can use the 'common' keyword to create a common entry for all files to be generated.
<!-- [common] -->
-
Ignored Section
Sometimes you do not want to include some items such as comments or TODOs in the files to be generated. If so, use the
ignore
keyword.<!-- [ignore] -->
-
-
Table of contents
The tags below are automatically replaced to the table of contents by the generator. The level of the table of contents can be determined through the
level
option. The highest-level of title(# title
) is level 1 because it is<h1>
in HTML.(Note) If you skip the title level of the markdown marked with
#
, an error will occur. In other words, the subtitle of##
must be###
.<!-- [[ multilingual toc: level=2~3 ]] -->
-
level
option- There are four ways to mark
level
. You can change the numbers below.level=2
: Make the 2nd level to table of contents.level=2~
: Make the 2nd ~ 9th level to table of contents.level=~4
: Make the 1st ~ 4th level to table of contents.level=2~4
: Make the 2nd ~ 4th level to table of contents.
- You can write the
table of contents
tags multiple times in one document, and also put differentlevel
options each time. - CAUTION💥: If you omit this
level
, the parser will not recognize it. - CAUTION💥: The
table of contents
tag automatically changes the current keyword tocommon
. So this tag is also implicitly incommon
.
- There are four ways to mark
-
no-emoji
option- You may want to subtract emoji from the table of contents while inserting emoji in a section title.😱 If you are in this situation, apply the
no-emoji
option as shown below.😎
<!-- [[ multilingual toc: level=2~3 no-emoji ]] -->
- You may want to subtract emoji from the table of contents while inserting emoji in a section title.😱 If you are in this situation, apply the
-
Contribution
I would appreciate anything you send. (e.g. translations, simple improvements, bug reports, and so on.)
How to build locally for development
- Linux and MacOS
- Required packages:
pip3 install -r requirements_dev.txt --user
- Install:
python3 setup.py install --user --record temp.txt
- Usage:
mmg [OPTIONS] [FILENAMES]...
- Uninstall:
xargs rm -rf < temp.txt
- Required packages:
- Windows
- Required packages:
pip3 install -r .\requirements_dev.txt --user
- Install:
python3 setup.py install --user --record temp.txt
- Usage:
python3 -m mmgcli [OPTIONS] [FILENAMES]...
- Uninstall (PowerShell):
python3 -m pip uninstall mmg
- Required packages:
Changelog
Contributors
The contributor list is available in English only.
- @bkg2018 (Francis Piérot): Added french translation to README and example. PR #1
- @mathben (Mathieu Benoit): Update README pip installation with requirements.txt PR #2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.