markdown-gettext 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {markdown-gettext-0.1.0 → markdown-gettext-0.1.2}/PKG-INFO +7 -26
- {markdown-gettext-0.1.0 → markdown-gettext-0.1.2}/README.md +5 -23
- markdown-gettext-0.1.2/markdown_gettext/cli.py +102 -0
- markdown-gettext-0.1.0/markdown_gettext/extraction/e_domain.py → markdown-gettext-0.1.2/markdown_gettext/domain_extraction.py +48 -32
- markdown-gettext-0.1.0/markdown_gettext/generation/g_domain.py → markdown-gettext-0.1.2/markdown_gettext/domain_generation.py +11 -10
- {markdown-gettext-0.1.0 → markdown-gettext-0.1.2}/pyproject.toml +2 -4
- markdown-gettext-0.1.2/setup.py +35 -0
- markdown-gettext-0.1.0/markdown_gettext/cli.py +0 -34
- markdown-gettext-0.1.0/markdown_gettext/extraction/__init__.py +0 -4
- markdown-gettext-0.1.0/markdown_gettext/extraction/e_utils.py +0 -41
- markdown-gettext-0.1.0/markdown_gettext/extraction/index.py +0 -28
- markdown-gettext-0.1.0/markdown_gettext/extraction/renderer_i18n.py +0 -120
- markdown-gettext-0.1.0/markdown_gettext/generation/__init__.py +0 -4
- markdown-gettext-0.1.0/markdown_gettext/generation/g_utils.py +0 -36
- markdown-gettext-0.1.0/markdown_gettext/generation/index.py +0 -54
- markdown-gettext-0.1.0/markdown_gettext/generation/renderer_l10n.py +0 -382
- markdown-gettext-0.1.0/markdown_gettext/utils.py +0 -7
- markdown-gettext-0.1.0/setup.py +0 -40
- {markdown-gettext-0.1.0 → markdown-gettext-0.1.2}/markdown_gettext/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: markdown-gettext
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Markdown i18n with gettext
|
|
5
5
|
Home-page: https://github.com/phunh/markdown-gettext
|
|
6
6
|
License: LGPL-2.1-or-later
|
|
@@ -16,10 +16,8 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.8
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
18
|
Classifier: Topic :: Software Development :: Internationalization
|
|
19
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
20
19
|
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist: markdown-it-py[plugins] (>=3.0.0,<4.0.0)
|
|
20
|
+
Requires-Dist: mdit-py-i18n (>=0.1.0,<0.2.0)
|
|
23
21
|
Requires-Dist: polib (>=1.2.0,<2.0.0)
|
|
24
22
|
Project-URL: Repository, https://github.com/phunh/markdown-gettext
|
|
25
23
|
Description-Content-Type: text/markdown
|
|
@@ -31,13 +29,10 @@ SPDX-License-Identifier: CC-BY-SA-4.0
|
|
|
31
29
|
|
|
32
30
|
# markdown-gettext
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
A command line program to do i18n and l10n for individual Markdown files.
|
|
35
33
|
|
|
36
34
|
CommonMark compliant. All core Markdown elements are supported, as well as
|
|
37
|
-
front matter, table, and definition list.
|
|
38
|
-
|
|
39
|
-
The package can be used as a command line program to do i18n and l10n for
|
|
40
|
-
individual Markdown files, and as a library to make larger programs.
|
|
35
|
+
YAML front matter, table, and definition list.
|
|
41
36
|
|
|
42
37
|
## Install
|
|
43
38
|
|
|
@@ -45,8 +40,7 @@ individual Markdown files, and as a library to make larger programs.
|
|
|
45
40
|
pip install markdown-gettext
|
|
46
41
|
```
|
|
47
42
|
|
|
48
|
-
## Usage
|
|
49
|
-
_("Usage as a library" in Development section)_
|
|
43
|
+
## Usage
|
|
50
44
|
|
|
51
45
|
You can use either `md-gettext` or `markdown-gettext` command
|
|
52
46
|
|
|
@@ -86,11 +80,9 @@ Some notes about how different elements are handled:
|
|
|
86
80
|
- Inlines: newlines and consecutive spaces are not kept;
|
|
87
81
|
- Content of each HTML block isn't parsed into finer tokens but processed
|
|
88
82
|
as a whole;
|
|
89
|
-
- Fenced code blocks: only `//` comments are processed;
|
|
90
|
-
|
|
91
|
-
## Development
|
|
83
|
+
- Fenced code blocks: only `//` single comments are processed;
|
|
92
84
|
|
|
93
|
-
|
|
85
|
+
## Development environment
|
|
94
86
|
|
|
95
87
|
- With Conda
|
|
96
88
|
|
|
@@ -100,14 +92,3 @@ conda activate mg
|
|
|
100
92
|
poetry install
|
|
101
93
|
```
|
|
102
94
|
|
|
103
|
-
### Usage as a library
|
|
104
|
-
|
|
105
|
-
#### Extraction
|
|
106
|
-
- Subclass `DomainExtractionProtocol`, implement
|
|
107
|
-
`DomainExtractionProtocol.render_front_matter`
|
|
108
|
-
- Subclass `RendererMarkdownI18N`
|
|
109
|
-
|
|
110
|
-
#### Generation
|
|
111
|
-
- Subclass `DomainGenerationProtocol`, implement
|
|
112
|
-
`DomainGenerationProtocol.render_front_matter`
|
|
113
|
-
- Subclass `RendererMarkdownL10N`
|
|
@@ -5,13 +5,10 @@ SPDX-License-Identifier: CC-BY-SA-4.0
|
|
|
5
5
|
|
|
6
6
|
# markdown-gettext
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
A command line program to do i18n and l10n for individual Markdown files.
|
|
9
9
|
|
|
10
10
|
CommonMark compliant. All core Markdown elements are supported, as well as
|
|
11
|
-
front matter, table, and definition list.
|
|
12
|
-
|
|
13
|
-
The package can be used as a command line program to do i18n and l10n for
|
|
14
|
-
individual Markdown files, and as a library to make larger programs.
|
|
11
|
+
YAML front matter, table, and definition list.
|
|
15
12
|
|
|
16
13
|
## Install
|
|
17
14
|
|
|
@@ -19,8 +16,7 @@ individual Markdown files, and as a library to make larger programs.
|
|
|
19
16
|
pip install markdown-gettext
|
|
20
17
|
```
|
|
21
18
|
|
|
22
|
-
## Usage
|
|
23
|
-
_("Usage as a library" in Development section)_
|
|
19
|
+
## Usage
|
|
24
20
|
|
|
25
21
|
You can use either `md-gettext` or `markdown-gettext` command
|
|
26
22
|
|
|
@@ -60,11 +56,9 @@ Some notes about how different elements are handled:
|
|
|
60
56
|
- Inlines: newlines and consecutive spaces are not kept;
|
|
61
57
|
- Content of each HTML block isn't parsed into finer tokens but processed
|
|
62
58
|
as a whole;
|
|
63
|
-
- Fenced code blocks: only `//` comments are processed;
|
|
64
|
-
|
|
65
|
-
## Development
|
|
59
|
+
- Fenced code blocks: only `//` single comments are processed;
|
|
66
60
|
|
|
67
|
-
|
|
61
|
+
## Development environment
|
|
68
62
|
|
|
69
63
|
- With Conda
|
|
70
64
|
|
|
@@ -73,15 +67,3 @@ conda env create -f environment.yml
|
|
|
73
67
|
conda activate mg
|
|
74
68
|
poetry install
|
|
75
69
|
```
|
|
76
|
-
|
|
77
|
-
### Usage as a library
|
|
78
|
-
|
|
79
|
-
#### Extraction
|
|
80
|
-
- Subclass `DomainExtractionProtocol`, implement
|
|
81
|
-
`DomainExtractionProtocol.render_front_matter`
|
|
82
|
-
- Subclass `RendererMarkdownI18N`
|
|
83
|
-
|
|
84
|
-
#### Generation
|
|
85
|
-
- Subclass `DomainGenerationProtocol`, implement
|
|
86
|
-
`DomainGenerationProtocol.render_front_matter`
|
|
87
|
-
- Subclass `RendererMarkdownL10N`
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
+
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import subprocess
|
|
7
|
+
from argparse import ArgumentParser, RawTextHelpFormatter
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
|
|
10
|
+
from markdown_it import MarkdownIt
|
|
11
|
+
from mdit_py_i18n.renderer_i18n import RendererMarkdownI18N
|
|
12
|
+
from mdit_py_i18n.renderer_l10n import RendererMarkdownL10N
|
|
13
|
+
from mdit_py_i18n.utils import L10NResult
|
|
14
|
+
from mdit_py_plugins.deflist import deflist_plugin
|
|
15
|
+
from mdit_py_plugins.front_matter import front_matter_plugin
|
|
16
|
+
|
|
17
|
+
from .domain_extraction import DomainExtraction
|
|
18
|
+
from .domain_generation import DomainGeneration, gettext_func
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main():
|
|
22
|
+
parser = ArgumentParser(description='Markdown i18n with gettext')
|
|
23
|
+
subparsers = parser.add_subparsers(description='extracting Markdown to POT and generating Markdown from PO')
|
|
24
|
+
|
|
25
|
+
extract_cmd = subparsers.add_parser('extract',
|
|
26
|
+
help='extract messages from a Markdown file to a POT file',
|
|
27
|
+
formatter_class=RawTextHelpFormatter)
|
|
28
|
+
extract_cmd.add_argument('md', help='path of the Markdown file to extract messages from')
|
|
29
|
+
extract_cmd.add_argument('pot', help='path of the POT file to create')
|
|
30
|
+
extract_cmd.add_argument('-p', '--package', default='', help='the package name in POT metadata')
|
|
31
|
+
extract_cmd.add_argument('-r', '--report-addr', default='', help='the report address in POT metadata')
|
|
32
|
+
extract_cmd.add_argument('-t', '--team-addr', default='', help='the team address in POT metadata')
|
|
33
|
+
extract_cmd.set_defaults(func=extract)
|
|
34
|
+
|
|
35
|
+
generate_cmd = subparsers.add_parser('generate',
|
|
36
|
+
help='generate a Markdown file from a source Markdown file and a PO file',
|
|
37
|
+
formatter_class=RawTextHelpFormatter)
|
|
38
|
+
generate_cmd.add_argument('in_md', metavar='in-md', help='path of the source Markdown file')
|
|
39
|
+
generate_cmd.add_argument('po', help='path of the PO file containing translations')
|
|
40
|
+
generate_cmd.add_argument('out_md', metavar='out-md', help='path of the Markdown file to create')
|
|
41
|
+
generate_cmd.add_argument('-l', '--lang', default='en', help='language of translations')
|
|
42
|
+
generate_cmd.set_defaults(func=generate)
|
|
43
|
+
|
|
44
|
+
args = parser.parse_args()
|
|
45
|
+
args.func(args)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def extract(args):
|
|
49
|
+
md_path = args.md
|
|
50
|
+
mdi = MarkdownIt(renderer_cls=RendererMarkdownI18N).use(front_matter_plugin)\
|
|
51
|
+
.enable('table').use(deflist_plugin)
|
|
52
|
+
domain_e = DomainExtraction()
|
|
53
|
+
with open(md_path) as f_md:
|
|
54
|
+
env = {
|
|
55
|
+
'path': md_path,
|
|
56
|
+
'domain_extraction': domain_e
|
|
57
|
+
}
|
|
58
|
+
mdi.render(f_md.read(), env)
|
|
59
|
+
package = args.package or md_path
|
|
60
|
+
target = args.pot
|
|
61
|
+
os.makedirs(os.path.dirname(os.path.abspath(target)), exist_ok=True)
|
|
62
|
+
domain_e.make_pot(package, args.report_addr, args.team_addr, target)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def compile_po(lang: str, po_path: str):
|
|
66
|
+
target_dir = f'locale/{lang}/LC_MESSAGES'
|
|
67
|
+
os.makedirs(target_dir, exist_ok=True)
|
|
68
|
+
po_basename = os.path.basename(po_path)
|
|
69
|
+
mo_path = f'{target_dir}/{po_basename[:-2]}mo'
|
|
70
|
+
command = f'msgfmt {po_path} -o {mo_path}'
|
|
71
|
+
subprocess.run(command, shell=True, check=True)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def generate(args):
|
|
75
|
+
lang = args.lang
|
|
76
|
+
po_path = args.po
|
|
77
|
+
|
|
78
|
+
compile_po(lang, po_path)
|
|
79
|
+
os.environ['LANGUAGE'] = lang
|
|
80
|
+
domain_name = os.path.splitext(os.path.basename(po_path))[0]
|
|
81
|
+
l10n_func = gettext_func(domain_name)
|
|
82
|
+
|
|
83
|
+
mdi = MarkdownIt(renderer_cls=RendererMarkdownL10N).use(front_matter_plugin)\
|
|
84
|
+
.enable('table').use(deflist_plugin)
|
|
85
|
+
domain_g = DomainGeneration(l10n_func)
|
|
86
|
+
|
|
87
|
+
def render_content_file(src_path: str) -> Tuple[L10NResult, L10NResult]:
|
|
88
|
+
with open(src_path) as f_content:
|
|
89
|
+
env = {
|
|
90
|
+
'domain_generation': domain_g
|
|
91
|
+
}
|
|
92
|
+
return mdi.render(f_content.read(), env)
|
|
93
|
+
|
|
94
|
+
def write_content_file(fm: str, content: str, target_path: str):
|
|
95
|
+
os.makedirs(os.path.dirname(os.path.abspath(target_path)), exist_ok=True)
|
|
96
|
+
with open(target_path, 'w+') as f_target:
|
|
97
|
+
f_target.write(fm)
|
|
98
|
+
f_target.write(content)
|
|
99
|
+
|
|
100
|
+
fm_result, content_result = render_content_file(args.in_md)
|
|
101
|
+
write_content_file(fm_result.localized, content_result.localized, args.out_md)
|
|
102
|
+
shutil.rmtree('locale')
|
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
2
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
3
|
|
|
4
|
+
from dataclasses import dataclass, field
|
|
4
5
|
from datetime import datetime
|
|
5
|
-
from typing import
|
|
6
|
+
from typing import List, Tuple
|
|
6
7
|
|
|
7
8
|
import polib
|
|
8
9
|
import yaml
|
|
10
|
+
from mdit_py_i18n import utils
|
|
9
11
|
|
|
10
|
-
from .e_utils import I18NEntry, Occurrence
|
|
11
|
-
from .. import utils
|
|
12
12
|
|
|
13
|
+
@dataclass
|
|
14
|
+
class I18NEntry:
|
|
15
|
+
msgid: str
|
|
16
|
+
occurrences: List[Tuple[str, int]] = field(default_factory=list)
|
|
17
|
+
comment: str = ''
|
|
18
|
+
msgctxt: str = ''
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
def to_poentry(self) -> polib.POEntry:
|
|
21
|
+
return polib.POEntry(msgid=self.msgid,
|
|
22
|
+
msgstr='',
|
|
23
|
+
# 0 passed to polib will be lost, use `str` to keep 0
|
|
24
|
+
occurrences=[(o[0], str(o[1])) for o in self.occurrences],
|
|
25
|
+
comment=self.comment,
|
|
26
|
+
msgctxt=self.msgctxt if self.msgctxt != '' else None)
|
|
16
27
|
|
|
17
|
-
def add_entry(self, src_path: str, msgid: str, line_num: int, comment: str = ''):
|
|
18
|
-
occ = Occurrence(src_path, line_num)
|
|
19
|
-
self.entries.append(I18NEntry(msgid, occ, comment))
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'Report-Msgid-Bugs-To': report_address,
|
|
26
|
-
'POT-Creation-Date': datetime.now().astimezone().strftime('%Y-%m-%d %H:%M%z'),
|
|
27
|
-
'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
|
|
28
|
-
'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
|
|
29
|
-
'Language-Team': f'LANGUAGE <{team_address}>',
|
|
30
|
-
'MIME-Version': '1.0',
|
|
31
|
-
'Content-Type': 'text/plain; charset=utf-8',
|
|
32
|
-
'Content-Transfer-Encoding': '8bit',
|
|
33
|
-
}
|
|
34
|
-
for e in self.entries:
|
|
35
|
-
e.add_to_pot(pot)
|
|
36
|
-
pot.save(dest_path)
|
|
37
|
-
|
|
38
|
-
def render_front_matter(self, path: str, content: str, markup: str) -> Any:
|
|
39
|
-
...
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class DomainExtraction(DomainExtractionProtocol):
|
|
29
|
+
class DomainExtraction:
|
|
30
|
+
"""
|
|
31
|
+
Implements `DomainExtractionProtocol`
|
|
32
|
+
"""
|
|
43
33
|
def __init__(self):
|
|
44
|
-
self.entries = []
|
|
34
|
+
self.entries: List[I18NEntry] = []
|
|
35
|
+
|
|
36
|
+
def add_entry(self, path: str, msgid: str, line_num: int, comment: str = '', msgctxt: str = ''):
|
|
37
|
+
if not msgid:
|
|
38
|
+
return
|
|
39
|
+
for e in self.entries:
|
|
40
|
+
if msgid == e.msgid and msgctxt == e.msgctxt:
|
|
41
|
+
e.occurrences.append((path, line_num))
|
|
42
|
+
return
|
|
43
|
+
self.entries.append(I18NEntry(msgid, [(path, line_num)], comment, msgctxt))
|
|
45
44
|
|
|
46
45
|
def i12ize_front_matter(self, o, path: str):
|
|
47
46
|
"""Internationalize an object in front matter.
|
|
@@ -55,6 +54,23 @@ class DomainExtraction(DomainExtractionProtocol):
|
|
|
55
54
|
for _, value in (enumerate(o) if isinstance(o, list) else o.items()):
|
|
56
55
|
self.i12ize_front_matter(value, path)
|
|
57
56
|
|
|
58
|
-
def render_front_matter(self, path: str, content: str,
|
|
57
|
+
def render_front_matter(self, path: str, content: str, _markup: str):
|
|
59
58
|
fm = yaml.safe_load(content)
|
|
60
59
|
self.i12ize_front_matter(fm, path)
|
|
60
|
+
|
|
61
|
+
def make_pot(self, package: str, report_address: str, team_address: str, dest_path: str):
|
|
62
|
+
pot = polib.POFile()
|
|
63
|
+
pot.metadata = {
|
|
64
|
+
'Project-Id-Version': f'{package} 1.0',
|
|
65
|
+
'Report-Msgid-Bugs-To': report_address,
|
|
66
|
+
'POT-Creation-Date': datetime.now().astimezone().strftime('%Y-%m-%d %H:%M%z'),
|
|
67
|
+
'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
|
|
68
|
+
'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
|
|
69
|
+
'Language-Team': f'LANGUAGE <{team_address}>',
|
|
70
|
+
'MIME-Version': '1.0',
|
|
71
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
72
|
+
'Content-Transfer-Encoding': '8bit',
|
|
73
|
+
}
|
|
74
|
+
for e in self.entries:
|
|
75
|
+
pot.append(e.to_poentry())
|
|
76
|
+
pot.save(dest_path)
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
2
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import gettext
|
|
5
5
|
|
|
6
6
|
import yaml
|
|
7
|
+
from mdit_py_i18n import utils
|
|
8
|
+
from mdit_py_i18n.utils import L10NFunc, L10NResult
|
|
7
9
|
|
|
8
|
-
from .g_utils import L10NFunc, L10NResult
|
|
9
|
-
from .. import utils
|
|
10
10
|
|
|
11
|
+
def gettext_func(domain_name):
|
|
12
|
+
gettext.bindtextdomain(domain_name, 'locale')
|
|
13
|
+
gettext.textdomain(domain_name)
|
|
14
|
+
return gettext.gettext
|
|
11
15
|
|
|
12
|
-
class DomainGenerationProtocol(Protocol):
|
|
13
|
-
l10n_func: L10NFunc
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class DomainGeneration(DomainGenerationProtocol):
|
|
17
|
+
class DomainGeneration:
|
|
18
|
+
"""
|
|
19
|
+
Implements `DomainGenerationProtocol`
|
|
20
|
+
"""
|
|
20
21
|
def __init__(self, l10n_func: L10NFunc):
|
|
21
22
|
self.l10n_func = l10n_func
|
|
22
23
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
[tool.poetry]
|
|
5
5
|
name = "markdown-gettext"
|
|
6
|
-
version = "0.1.
|
|
6
|
+
version = "0.1.2"
|
|
7
7
|
description = "Markdown i18n with gettext"
|
|
8
8
|
authors = ["Phu Hung Nguyen <phuhnguyen@outlook.com>"]
|
|
9
9
|
license = "LGPL-2.1-or-later"
|
|
@@ -12,7 +12,6 @@ repository = "https://github.com/phunh/markdown-gettext"
|
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Development Status :: 3 - Alpha",
|
|
14
14
|
"Intended Audience :: Developers",
|
|
15
|
-
"Topic :: Software Development :: Libraries",
|
|
16
15
|
"Topic :: Software Development :: Internationalization",
|
|
17
16
|
"Programming Language :: Python",
|
|
18
17
|
"Programming Language :: Python :: 3"
|
|
@@ -21,10 +20,9 @@ packages = [{include = "markdown_gettext"}]
|
|
|
21
20
|
|
|
22
21
|
[tool.poetry.dependencies]
|
|
23
22
|
python = "^3.8"
|
|
24
|
-
markdown-it-py = {extras = ["plugins"], version = "^3.0.0"}
|
|
25
23
|
polib = "^1.2.0"
|
|
26
|
-
Pygments = "^2.16.1"
|
|
27
24
|
PyYAML = "^6.0.1"
|
|
25
|
+
mdit-py-i18n = "^0.1.0"
|
|
28
26
|
|
|
29
27
|
[tool.poetry.scripts]
|
|
30
28
|
md-gettext = 'markdown_gettext.cli:main'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['markdown_gettext']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['PyYAML>=6.0.1,<7.0.0', 'mdit-py-i18n>=0.1.0,<0.2.0', 'polib>=1.2.0,<2.0.0']
|
|
12
|
+
|
|
13
|
+
entry_points = \
|
|
14
|
+
{'console_scripts': ['markdown-gettext = markdown_gettext.cli:main',
|
|
15
|
+
'md-gettext = markdown_gettext.cli:main']}
|
|
16
|
+
|
|
17
|
+
setup_kwargs = {
|
|
18
|
+
'name': 'markdown-gettext',
|
|
19
|
+
'version': '0.1.2',
|
|
20
|
+
'description': 'Markdown i18n with gettext',
|
|
21
|
+
'long_description': "<!--\nSPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>\nSPDX-License-Identifier: CC-BY-SA-4.0\n-->\n\n# markdown-gettext\n\nA command line program to do i18n and l10n for individual Markdown files.\n\nCommonMark compliant. All core Markdown elements are supported, as well as\nYAML front matter, table, and definition list.\n\n## Install\n\n```bash\npip install markdown-gettext\n```\n\n## Usage\n\nYou can use either `md-gettext` or `markdown-gettext` command\n\n#### Extraction\n```\nmd-gettext extract [-p PACKAGE] [-r REPORT_ADDR] [-t TEAM_ADDR] md pot\n\npositional arguments:\n md path of the Markdown file to extract messages from\n pot path of the POT file to create\n\noptional arguments:\n -p PACKAGE, --package PACKAGE\n the package name in POT metadata\n -r REPORT_ADDR, --report-addr REPORT_ADDR\n the report address in POT metadata\n -t TEAM_ADDR, --team-addr TEAM_ADDR\n the team address in POT metadata\n```\n\n#### Generation\n```\nmd-gettext generate [-l LANG] in-md po out-md\n\npositional arguments:\n in-md path of the source Markdown file\n po path of the PO file containing translations\n out-md path of the Markdown file to create\n\noptional arguments:\n -l LANG, --lang LANG language of translations\n```\n\n## Notes\n\nSome notes about how different elements are handled:\n- Inlines: newlines and consecutive spaces are not kept;\n- Content of each HTML block isn't parsed into finer tokens but processed\nas a whole;\n- Fenced code blocks: only `//` single comments are processed;\n\n## Development environment\n\n- With Conda\n\n```bash\nconda env create -f environment.yml\nconda activate mg\npoetry install\n```\n",
|
|
22
|
+
'author': 'Phu Hung Nguyen',
|
|
23
|
+
'author_email': 'phuhnguyen@outlook.com',
|
|
24
|
+
'maintainer': None,
|
|
25
|
+
'maintainer_email': None,
|
|
26
|
+
'url': 'https://github.com/phunh/markdown-gettext',
|
|
27
|
+
'packages': packages,
|
|
28
|
+
'package_data': package_data,
|
|
29
|
+
'install_requires': install_requires,
|
|
30
|
+
'entry_points': entry_points,
|
|
31
|
+
'python_requires': '>=3.8,<4.0',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
setup(**setup_kwargs)
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
from argparse import ArgumentParser, RawTextHelpFormatter
|
|
5
|
-
|
|
6
|
-
from .extraction import extract
|
|
7
|
-
from .generation import generate
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def main():
|
|
11
|
-
parser = ArgumentParser(description='Markdown i18n with gettext')
|
|
12
|
-
subparsers = parser.add_subparsers(description='extracting Markdown to POT and generating Markdown from PO')
|
|
13
|
-
|
|
14
|
-
extract_cmd = subparsers.add_parser('extract',
|
|
15
|
-
help='extract messages from a Markdown file to a POT file',
|
|
16
|
-
formatter_class=RawTextHelpFormatter)
|
|
17
|
-
extract_cmd.add_argument('md', help='path of the Markdown file to extract messages from')
|
|
18
|
-
extract_cmd.add_argument('pot', help='path of the POT file to create')
|
|
19
|
-
extract_cmd.add_argument('-p', '--package', default='', help='the package name in POT metadata')
|
|
20
|
-
extract_cmd.add_argument('-r', '--report-addr', default='', help='the report address in POT metadata')
|
|
21
|
-
extract_cmd.add_argument('-t', '--team-addr', default='', help='the team address in POT metadata')
|
|
22
|
-
extract_cmd.set_defaults(func=extract)
|
|
23
|
-
|
|
24
|
-
generate_cmd = subparsers.add_parser('generate',
|
|
25
|
-
help='generate a Markdown file from a source Markdown file and a PO file',
|
|
26
|
-
formatter_class=RawTextHelpFormatter)
|
|
27
|
-
generate_cmd.add_argument('in_md', metavar='in-md', help='path of the source Markdown file')
|
|
28
|
-
generate_cmd.add_argument('po', help='path of the PO file containing translations')
|
|
29
|
-
generate_cmd.add_argument('out_md', metavar='out-md', help='path of the Markdown file to create')
|
|
30
|
-
generate_cmd.add_argument('-l', '--lang', default='en', help='language of translations')
|
|
31
|
-
generate_cmd.set_defaults(func=generate)
|
|
32
|
-
|
|
33
|
-
args = parser.parse_args()
|
|
34
|
-
args.func(args)
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
from dataclasses import dataclass
|
|
5
|
-
|
|
6
|
-
import polib
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclass
|
|
10
|
-
class Occurrence:
|
|
11
|
-
src_path: str
|
|
12
|
-
line_num: int
|
|
13
|
-
|
|
14
|
-
# this is used with tuple()
|
|
15
|
-
def __iter__(self):
|
|
16
|
-
for key in self.__dict__:
|
|
17
|
-
# polib requires an int for line number, but number 0 passed to it would be lost, so we use string
|
|
18
|
-
yield str(self.__getattribute__(key))
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass
|
|
22
|
-
class I18NEntry:
|
|
23
|
-
msgid: str
|
|
24
|
-
occurrence: Occurrence
|
|
25
|
-
comment: str = ''
|
|
26
|
-
|
|
27
|
-
def to_poentry(self) -> polib.POEntry:
|
|
28
|
-
return polib.POEntry(msgid=self.msgid,
|
|
29
|
-
msgstr='',
|
|
30
|
-
occurrences=[tuple(self.occurrence)],
|
|
31
|
-
comment=self.comment)
|
|
32
|
-
|
|
33
|
-
def add_to_pot(self, pot: polib.POFile):
|
|
34
|
-
if self.msgid:
|
|
35
|
-
if old_entry := pot.find(self.msgid):
|
|
36
|
-
old_entry.occurrences.append(tuple(self.occurrence))
|
|
37
|
-
else:
|
|
38
|
-
try:
|
|
39
|
-
pot.append(self.to_poentry())
|
|
40
|
-
except ValueError:
|
|
41
|
-
pass
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
import os
|
|
5
|
-
|
|
6
|
-
from markdown_it import MarkdownIt
|
|
7
|
-
from mdit_py_plugins.deflist import deflist_plugin
|
|
8
|
-
from mdit_py_plugins.front_matter import front_matter_plugin
|
|
9
|
-
|
|
10
|
-
from .e_domain import DomainExtraction
|
|
11
|
-
from .renderer_i18n import RendererMarkdownI18N
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def extract(args):
|
|
15
|
-
md_path = args.md
|
|
16
|
-
mdi = MarkdownIt(renderer_cls=RendererMarkdownI18N).use(front_matter_plugin)\
|
|
17
|
-
.enable('table').use(deflist_plugin)
|
|
18
|
-
domain_e = DomainExtraction()
|
|
19
|
-
with open(md_path) as f_md:
|
|
20
|
-
env = {
|
|
21
|
-
'path': md_path,
|
|
22
|
-
'domain_extraction': domain_e
|
|
23
|
-
}
|
|
24
|
-
mdi.render(f_md.read(), env)
|
|
25
|
-
package = args.package or md_path
|
|
26
|
-
target = args.pot
|
|
27
|
-
os.makedirs(os.path.dirname(target), exist_ok=True)
|
|
28
|
-
domain_e.make_pot(package, args.report_addr, args.team_addr, target)
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
import inspect
|
|
5
|
-
from typing import Sequence, MutableMapping
|
|
6
|
-
|
|
7
|
-
import pygments.token
|
|
8
|
-
from markdown_it.renderer import RendererProtocol
|
|
9
|
-
from markdown_it.token import Token
|
|
10
|
-
from markdown_it.utils import OptionsDict
|
|
11
|
-
from pygments import lexers, util
|
|
12
|
-
|
|
13
|
-
from .. import utils
|
|
14
|
-
from .e_domain import DomainExtractionProtocol
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class _MdCtx:
|
|
18
|
-
def __init__(self, env: MutableMapping):
|
|
19
|
-
self.path: str = env['path']
|
|
20
|
-
self.domain_e: DomainExtractionProtocol = env['domain_extraction']
|
|
21
|
-
|
|
22
|
-
def add_entry(self, msgid: str, line_number: int, comment: str = ''):
|
|
23
|
-
self.domain_e.add_entry(self.path, msgid, line_number, comment)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def _link_ref(env: MutableMapping, md_ctx: _MdCtx):
|
|
27
|
-
refs = env.get('references', {}).items()
|
|
28
|
-
if len(refs) == 0:
|
|
29
|
-
return
|
|
30
|
-
for ref, details in refs:
|
|
31
|
-
if title := details.get('title', ''):
|
|
32
|
-
# TODO: line number?
|
|
33
|
-
md_ctx.add_entry(title, 0)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class RendererMarkdownI18N(RendererProtocol):
|
|
37
|
-
def __init__(self, _):
|
|
38
|
-
self.rules = {
|
|
39
|
-
k: v
|
|
40
|
-
for k, v in inspect.getmembers(self, predicate=inspect.ismethod)
|
|
41
|
-
if not (k.startswith("render") or k.startswith("_"))
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
def render(self, tokens: Sequence[Token], options: OptionsDict, env: MutableMapping):
|
|
45
|
-
"""
|
|
46
|
-
:param tokens: list of block tokens to render
|
|
47
|
-
:param options: properties of parser instance
|
|
48
|
-
:param env: containing:
|
|
49
|
-
- 'path': path of the source file
|
|
50
|
-
- 'domain_extraction': a `DomainExtractionProtocol` object
|
|
51
|
-
:return: None
|
|
52
|
-
"""
|
|
53
|
-
md_ctx = _MdCtx(env)
|
|
54
|
-
|
|
55
|
-
for i, token in enumerate(tokens):
|
|
56
|
-
if token.type in self.rules:
|
|
57
|
-
r = self.rules[token.type](tokens, i, md_ctx)
|
|
58
|
-
if r == -1:
|
|
59
|
-
break
|
|
60
|
-
|
|
61
|
-
_link_ref(env, md_ctx)
|
|
62
|
-
|
|
63
|
-
@classmethod
|
|
64
|
-
def front_matter(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx):
|
|
65
|
-
token = tokens[idx]
|
|
66
|
-
md_ctx.domain_e.render_front_matter(md_ctx.path, token.content, token.markup)
|
|
67
|
-
|
|
68
|
-
@classmethod
|
|
69
|
-
def inline(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx):
|
|
70
|
-
token = tokens[idx]
|
|
71
|
-
content = utils.SPACES_PATTERN.sub(' ', token.content.replace('\n', ' '))
|
|
72
|
-
if content and not utils.SPACES_PATTERN.fullmatch(content):
|
|
73
|
-
md_ctx.add_entry(content, token.map[0] + 1)
|
|
74
|
-
|
|
75
|
-
@classmethod
|
|
76
|
-
def fence(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx):
|
|
77
|
-
token = tokens[idx]
|
|
78
|
-
try:
|
|
79
|
-
lexer = lexers.get_lexer_by_name(token.info)
|
|
80
|
-
except util.ClassNotFound:
|
|
81
|
-
lexer = lexers.guess_lexer(token.content)
|
|
82
|
-
code_toks = lexer.get_tokens(token.content)
|
|
83
|
-
|
|
84
|
-
# temporary content of the comment being parsed
|
|
85
|
-
# also indicates whether we are parsing a comment or not
|
|
86
|
-
comment = ''
|
|
87
|
-
# number of the line where the comment starts
|
|
88
|
-
comment_line_num = 0
|
|
89
|
-
# number of the last line with a comment token
|
|
90
|
-
last_comment_line_num = 0
|
|
91
|
-
# the token starts with one line of the fence, then the content. +1: 0-base -> 1-base
|
|
92
|
-
line_num = token.map[0] + 1 + 1
|
|
93
|
-
|
|
94
|
-
# concatenate comment tokens until either a non-comment token or a blank line or end of token stream
|
|
95
|
-
for tok_type, tok_val in code_toks:
|
|
96
|
-
if tok_type == pygments.token.Token.Comment.Single:
|
|
97
|
-
# when another comment is already being parsed and there's a blank line
|
|
98
|
-
if comment and line_num - last_comment_line_num > 1:
|
|
99
|
-
md_ctx.add_entry(comment, comment_line_num)
|
|
100
|
-
comment = ''
|
|
101
|
-
comment_line_num = 0
|
|
102
|
-
comment_match = utils.SINGLE_COMMENT_PATTERN.match(tok_val)
|
|
103
|
-
if comment != '':
|
|
104
|
-
comment += ' '
|
|
105
|
-
comment += comment_match.group(2).strip()
|
|
106
|
-
if comment_line_num == 0:
|
|
107
|
-
comment_line_num = line_num
|
|
108
|
-
last_comment_line_num = line_num
|
|
109
|
-
elif tok_val.strip() and comment:
|
|
110
|
-
md_ctx.add_entry(comment, comment_line_num)
|
|
111
|
-
comment = ''
|
|
112
|
-
comment_line_num = 0
|
|
113
|
-
line_num += tok_val.count('\n')
|
|
114
|
-
if comment:
|
|
115
|
-
md_ctx.add_entry(comment, comment_line_num)
|
|
116
|
-
|
|
117
|
-
@classmethod
|
|
118
|
-
def html_block(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx):
|
|
119
|
-
token = tokens[idx]
|
|
120
|
-
md_ctx.add_entry(token.content, token.map[0] + 1)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
import gettext
|
|
5
|
-
from typing import Callable
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def gettext_func(domain_name):
|
|
9
|
-
gettext.bindtextdomain(domain_name, 'locale')
|
|
10
|
-
gettext.textdomain(domain_name)
|
|
11
|
-
return gettext.gettext
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class L10NResult:
|
|
15
|
-
"""Localized content, total number of messages, number of translations.
|
|
16
|
-
If there are no messages, rate will be -1
|
|
17
|
-
"""
|
|
18
|
-
def __init__(self, localized, total_count: int, l10n_count: int):
|
|
19
|
-
self.localized = localized
|
|
20
|
-
self.total_count = total_count
|
|
21
|
-
self.l10n_count = l10n_count
|
|
22
|
-
|
|
23
|
-
def __str__(self):
|
|
24
|
-
return f'({self.l10n_count}/{self.total_count})'
|
|
25
|
-
|
|
26
|
-
@property
|
|
27
|
-
def rate(self):
|
|
28
|
-
return self.l10n_count / self.total_count if self.total_count > 0 else -1
|
|
29
|
-
|
|
30
|
-
def sum_rate_with(self, other: 'L10NResult'):
|
|
31
|
-
l10n_count = self.l10n_count + other.l10n_count
|
|
32
|
-
total_count = self.total_count + other.total_count
|
|
33
|
-
return l10n_count / total_count if total_count > 0 else -1
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
L10NFunc = Callable[[str], str]
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
import os
|
|
5
|
-
import subprocess
|
|
6
|
-
from typing import Tuple
|
|
7
|
-
|
|
8
|
-
from markdown_it import MarkdownIt
|
|
9
|
-
from mdit_py_plugins.deflist import deflist_plugin
|
|
10
|
-
from mdit_py_plugins.front_matter import front_matter_plugin
|
|
11
|
-
|
|
12
|
-
from .g_domain import DomainGeneration
|
|
13
|
-
from .g_utils import L10NResult, gettext_func
|
|
14
|
-
from .renderer_l10n import RendererMarkdownL10N
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def compile_po(lang: str, po_path: str):
|
|
18
|
-
target_dir = f'locale/{lang}/LC_MESSAGES'
|
|
19
|
-
os.makedirs(target_dir, exist_ok=True)
|
|
20
|
-
po_basename = os.path.basename(po_path)
|
|
21
|
-
mo_path = f'{target_dir}/{po_basename[:-2]}mo'
|
|
22
|
-
command = f'msgfmt {po_path} -o {mo_path}'
|
|
23
|
-
subprocess.run(command, shell=True, check=True)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def generate(args):
|
|
27
|
-
lang = args.lang
|
|
28
|
-
po_path = args.po
|
|
29
|
-
|
|
30
|
-
compile_po(lang, po_path)
|
|
31
|
-
os.environ['LANGUAGE'] = lang
|
|
32
|
-
|
|
33
|
-
domain_name = os.path.splitext(os.path.basename(po_path))[0]
|
|
34
|
-
l10n_func = gettext_func(domain_name)
|
|
35
|
-
|
|
36
|
-
mdi = MarkdownIt(renderer_cls=RendererMarkdownL10N).use(front_matter_plugin)\
|
|
37
|
-
.enable('table').use(deflist_plugin)
|
|
38
|
-
domain_g = DomainGeneration(l10n_func)
|
|
39
|
-
|
|
40
|
-
def render_content_file(src_path: str) -> Tuple[L10NResult, L10NResult]:
|
|
41
|
-
with open(src_path) as f_content:
|
|
42
|
-
env = {
|
|
43
|
-
'domain_generation': domain_g
|
|
44
|
-
}
|
|
45
|
-
return mdi.render(f_content.read(), env)
|
|
46
|
-
|
|
47
|
-
def write_content_file(fm: str, content: str, target_path: str):
|
|
48
|
-
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
|
49
|
-
with open(target_path, 'w+') as f_target:
|
|
50
|
-
f_target.write(fm)
|
|
51
|
-
f_target.write(content)
|
|
52
|
-
|
|
53
|
-
fm_result, content_result = render_content_file(args.in_md)
|
|
54
|
-
write_content_file(fm_result.localized, content_result.localized, args.out_md)
|
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
|
|
2
|
-
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
3
|
-
|
|
4
|
-
"""Render localized markdown"""
|
|
5
|
-
|
|
6
|
-
import inspect
|
|
7
|
-
import textwrap
|
|
8
|
-
from collections.abc import MutableMapping
|
|
9
|
-
from dataclasses import dataclass
|
|
10
|
-
from typing import Sequence, Tuple
|
|
11
|
-
|
|
12
|
-
import pygments.token
|
|
13
|
-
from markdown_it.renderer import RendererProtocol
|
|
14
|
-
from markdown_it.token import Token
|
|
15
|
-
from markdown_it.utils import OptionsDict
|
|
16
|
-
from pygments import lexers, util
|
|
17
|
-
|
|
18
|
-
from .. import utils
|
|
19
|
-
from .g_utils import L10NResult
|
|
20
|
-
from .g_domain import DomainGenerationProtocol
|
|
21
|
-
|
|
22
|
-
SETEXT_HEADING_MARKUPS = {'-', '='}
|
|
23
|
-
ORDERED_LIST_MARKUPS = {'.', ')'}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class _MdCtx:
|
|
27
|
-
def __init__(self, env: MutableMapping):
|
|
28
|
-
self.line_indent = ''
|
|
29
|
-
self.indent_1st_line = '' # list item, definition detail, atx heading
|
|
30
|
-
self.indent_1st_line_len = 0
|
|
31
|
-
self.indents = []
|
|
32
|
-
self.setext_heading = ''
|
|
33
|
-
self.table_sep = ''
|
|
34
|
-
self.in_table = False
|
|
35
|
-
self.domain_g: DomainGenerationProtocol = env['domain_generation']
|
|
36
|
-
|
|
37
|
-
def get_line_indent(self):
|
|
38
|
-
if not self.indent_1st_line:
|
|
39
|
-
return self.line_indent
|
|
40
|
-
if self.indent_1st_line_len > 0:
|
|
41
|
-
line_indent = self.line_indent[:-self.indent_1st_line_len] + self.indent_1st_line
|
|
42
|
-
else:
|
|
43
|
-
line_indent = self.line_indent + self.indent_1st_line
|
|
44
|
-
self.indent_1st_line = ''
|
|
45
|
-
self.indent_1st_line_len = 0
|
|
46
|
-
return line_indent
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@dataclass
|
|
50
|
-
class _FenceCtx:
|
|
51
|
-
localized: str = '' # the l10n result
|
|
52
|
-
# temporary content of the comment being parsed
|
|
53
|
-
# also indicates whether we are parsing a comment or not
|
|
54
|
-
comment: str = ''
|
|
55
|
-
indent: str = '' # things on the same line before the comment
|
|
56
|
-
next_indent: str = '' # a second field when 'indent' is busy
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# TODO: parameterize: fence code comment i18n, wrap width, comment identifiers
|
|
60
|
-
# TODO: multiline comment?
|
|
61
|
-
def _fence_comment(fence_ctx: _FenceCtx, md_ctx: _MdCtx, content_result: L10NResult):
|
|
62
|
-
localized_comment = md_ctx.domain_g.l10n_func(fence_ctx.comment)
|
|
63
|
-
if localized_comment is not fence_ctx.comment:
|
|
64
|
-
content_result.l10n_count += 1
|
|
65
|
-
content_result.total_count += 1
|
|
66
|
-
subsequent_indent = ' ' * len(fence_ctx.indent) if fence_ctx.indent.strip() else fence_ctx.indent
|
|
67
|
-
comment_lines = textwrap.wrap(localized_comment,
|
|
68
|
-
100,
|
|
69
|
-
initial_indent=f'{fence_ctx.indent}// ',
|
|
70
|
-
subsequent_indent=f'{subsequent_indent}// ')
|
|
71
|
-
for line in comment_lines:
|
|
72
|
-
fence_ctx.localized += f'{line}\n'
|
|
73
|
-
fence_ctx.comment = ''
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def _fence(token: Token, md_ctx: _MdCtx, content_result: L10NResult):
|
|
77
|
-
try:
|
|
78
|
-
lexer = lexers.get_lexer_by_name(token.info)
|
|
79
|
-
except util.ClassNotFound:
|
|
80
|
-
lexer = lexers.guess_lexer(token.content)
|
|
81
|
-
code_toks = lexer.get_tokens(token.content)
|
|
82
|
-
|
|
83
|
-
# values to use in _fence_comment function
|
|
84
|
-
fence_ctx = _FenceCtx()
|
|
85
|
-
# number of the last line with a comment token
|
|
86
|
-
last_comment_line_num = 0
|
|
87
|
-
# the token starts with one line of the fence, then the content. +1: 0-base -> 1-base
|
|
88
|
-
line_num = token.map[0] + 1 + 1
|
|
89
|
-
|
|
90
|
-
# concatenate comment tokens until either a non-comment token or a blank line or end of token stream
|
|
91
|
-
for tok_type, tok_val in code_toks:
|
|
92
|
-
if tok_type == pygments.token.Token.Comment.Single:
|
|
93
|
-
# when another comment is already being parsed and there's a blank line
|
|
94
|
-
if fence_ctx.comment and line_num - last_comment_line_num > 1:
|
|
95
|
-
_fence_comment(fence_ctx, md_ctx, content_result)
|
|
96
|
-
last_nl = fence_ctx.next_indent.rfind('\n')
|
|
97
|
-
fence_ctx.localized += fence_ctx.next_indent[:last_nl + 1]
|
|
98
|
-
fence_ctx.indent = fence_ctx.next_indent[last_nl + 1:]
|
|
99
|
-
comment_match = utils.SINGLE_COMMENT_PATTERN.match(tok_val)
|
|
100
|
-
if fence_ctx.comment != '':
|
|
101
|
-
fence_ctx.comment += ' '
|
|
102
|
-
fence_ctx.comment += comment_match.group(2).strip()
|
|
103
|
-
last_comment_line_num = line_num
|
|
104
|
-
else:
|
|
105
|
-
if fence_ctx.comment:
|
|
106
|
-
if tok_val.strip():
|
|
107
|
-
_fence_comment(fence_ctx, md_ctx, content_result)
|
|
108
|
-
fence_ctx.indent = fence_ctx.next_indent + tok_val
|
|
109
|
-
fence_ctx.next_indent = ''
|
|
110
|
-
else:
|
|
111
|
-
fence_ctx.next_indent = tok_val
|
|
112
|
-
else:
|
|
113
|
-
last_nl = tok_val.rfind('\n')
|
|
114
|
-
if last_nl != -1:
|
|
115
|
-
fence_ctx.localized += fence_ctx.indent + tok_val[:last_nl + 1]
|
|
116
|
-
fence_ctx.indent = tok_val[last_nl + 1:]
|
|
117
|
-
else:
|
|
118
|
-
fence_ctx.indent += tok_val
|
|
119
|
-
line_num += tok_val.count('\n')
|
|
120
|
-
if fence_ctx.comment:
|
|
121
|
-
_fence_comment(fence_ctx, md_ctx, content_result)
|
|
122
|
-
return fence_ctx.localized
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def _front_matter(token: Token, env: MutableMapping) -> L10NResult:
|
|
126
|
-
domain_g: DomainGenerationProtocol = env['domain_generation']
|
|
127
|
-
fm_result = domain_g.render_front_matter(token.content, token.markup)
|
|
128
|
-
return fm_result
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def _link_ref(env: MutableMapping, md_ctx: _MdCtx, content_result: L10NResult):
|
|
132
|
-
refs = env.get('references', {}).items()
|
|
133
|
-
if len(refs) == 0:
|
|
134
|
-
return
|
|
135
|
-
content_result.localized += '\n'
|
|
136
|
-
for ref, details in refs:
|
|
137
|
-
href = details['href']
|
|
138
|
-
content_result.localized += f'[{ref}]: {href}'
|
|
139
|
-
if title := details.get('title', ''):
|
|
140
|
-
localized_title = md_ctx.domain_g.l10n_func(title)
|
|
141
|
-
if localized_title is not title:
|
|
142
|
-
content_result.l10n_count += 1
|
|
143
|
-
content_result.total_count += 1
|
|
144
|
-
content_result.localized += f' "{localized_title}"'
|
|
145
|
-
content_result.localized += '\n'
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
class RendererMarkdownL10N(RendererProtocol):
|
|
149
|
-
__output__ = "md"
|
|
150
|
-
|
|
151
|
-
def __init__(self, _):
|
|
152
|
-
self.rules = {
|
|
153
|
-
k: v
|
|
154
|
-
for k, v in inspect.getmembers(self, predicate=inspect.ismethod)
|
|
155
|
-
if not (k.startswith("render") or k.startswith("_"))
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
def render(
|
|
159
|
-
self, tokens: Sequence[Token], options: OptionsDict, env: MutableMapping
|
|
160
|
-
) -> Tuple[L10NResult, L10NResult]:
|
|
161
|
-
"""
|
|
162
|
-
:param tokens: list of block tokens to render
|
|
163
|
-
:param options: properties of parser instance
|
|
164
|
-
:param env: containing 'domain_generation' a `DomainGenerationProtocol` object
|
|
165
|
-
:return: an `L10NResult`
|
|
166
|
-
"""
|
|
167
|
-
if tokens[0].type == 'front_matter':
|
|
168
|
-
fm_result = _front_matter(tokens[0], env)
|
|
169
|
-
tokens = tokens[1:]
|
|
170
|
-
else:
|
|
171
|
-
fm_result = L10NResult('', 0, 0)
|
|
172
|
-
|
|
173
|
-
md_ctx = _MdCtx(env)
|
|
174
|
-
content_result = L10NResult('', 0, 0)
|
|
175
|
-
|
|
176
|
-
for i, token in enumerate(tokens):
|
|
177
|
-
if token.type in self.rules:
|
|
178
|
-
r = self.rules[token.type](tokens, i, md_ctx, content_result)
|
|
179
|
-
if r == -1:
|
|
180
|
-
break
|
|
181
|
-
|
|
182
|
-
_link_ref(env, md_ctx, content_result)
|
|
183
|
-
|
|
184
|
-
return fm_result, content_result
|
|
185
|
-
|
|
186
|
-
@classmethod
|
|
187
|
-
def inline(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
188
|
-
token = tokens[idx]
|
|
189
|
-
content = utils.SPACES_PATTERN.sub(' ', token.content.replace('\n', ' '))
|
|
190
|
-
if content and not utils.SPACES_PATTERN.fullmatch(content):
|
|
191
|
-
localized_content = md_ctx.domain_g.l10n_func(content)
|
|
192
|
-
else:
|
|
193
|
-
localized_content = content
|
|
194
|
-
if localized_content is not content:
|
|
195
|
-
content_result.l10n_count += 1
|
|
196
|
-
content_result.total_count += 1
|
|
197
|
-
if md_ctx.in_table:
|
|
198
|
-
content_result.localized += localized_content
|
|
199
|
-
else:
|
|
200
|
-
content_result.localized += f'{md_ctx.get_line_indent()}{localized_content}'
|
|
201
|
-
|
|
202
|
-
# blockquote
|
|
203
|
-
# TODO: blockquote inside list
|
|
204
|
-
@classmethod
|
|
205
|
-
def blockquote_open(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, _content_result: L10NResult):
|
|
206
|
-
token = tokens[idx]
|
|
207
|
-
md_ctx.line_indent = f'{md_ctx.get_line_indent()}{token.markup} '
|
|
208
|
-
|
|
209
|
-
@classmethod
|
|
210
|
-
def blockquote_close(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
211
|
-
md_ctx.line_indent = md_ctx.line_indent[:-2]
|
|
212
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
213
|
-
|
|
214
|
-
# heading
|
|
215
|
-
@classmethod
|
|
216
|
-
def heading_open(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, _content_result: L10NResult):
|
|
217
|
-
token = tokens[idx]
|
|
218
|
-
if token.markup not in SETEXT_HEADING_MARKUPS:
|
|
219
|
-
md_ctx.indent_1st_line += f'{token.markup} '
|
|
220
|
-
# md_ctx.indent_1st_line_len += 0
|
|
221
|
-
# md_ctx.line_indent += ' ' * 0
|
|
222
|
-
md_ctx.indents.append(0)
|
|
223
|
-
else:
|
|
224
|
-
md_ctx.setext_heading = token.markup
|
|
225
|
-
|
|
226
|
-
@classmethod
|
|
227
|
-
def heading_close(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
228
|
-
if md_ctx.setext_heading:
|
|
229
|
-
content_result.localized += f'\n{md_ctx.get_line_indent()}{md_ctx.setext_heading}'
|
|
230
|
-
md_ctx.setext_heading = ''
|
|
231
|
-
else:
|
|
232
|
-
md_ctx.indents.pop()
|
|
233
|
-
# the added len is 0, so line_indent remains the same
|
|
234
|
-
content_result.localized += '\n'
|
|
235
|
-
|
|
236
|
-
# thematic break
|
|
237
|
-
@classmethod
|
|
238
|
-
def hr(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
239
|
-
token = tokens[idx]
|
|
240
|
-
# always use '_' here to differentiate this from setext headings and bullet list items
|
|
241
|
-
content_result.localized += f'{md_ctx.get_line_indent()}{len(token.markup) * "_"}\n'
|
|
242
|
-
|
|
243
|
-
# list
|
|
244
|
-
# TODO: loose lists?
|
|
245
|
-
@classmethod
|
|
246
|
-
def list_item_open(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, _content_result: L10NResult):
|
|
247
|
-
token = tokens[idx]
|
|
248
|
-
markup = f'{token.info}{token.markup}' if token.markup in ORDERED_LIST_MARKUPS else f'{token.markup}'
|
|
249
|
-
md_ctx.indent_1st_line += f'{markup} '
|
|
250
|
-
added_len = len(markup) + 1
|
|
251
|
-
md_ctx.indent_1st_line_len += added_len
|
|
252
|
-
md_ctx.line_indent += ' ' * added_len
|
|
253
|
-
md_ctx.indents.append(added_len)
|
|
254
|
-
|
|
255
|
-
@classmethod
|
|
256
|
-
def list_item_close(cls,
|
|
257
|
-
_tokens: Sequence[Token],
|
|
258
|
-
_idx: int,
|
|
259
|
-
md_ctx: _MdCtx,
|
|
260
|
-
_content_result: L10NResult):
|
|
261
|
-
latest_len = md_ctx.indents.pop()
|
|
262
|
-
md_ctx.line_indent = md_ctx.line_indent[:-latest_len]
|
|
263
|
-
|
|
264
|
-
@classmethod
|
|
265
|
-
def bullet_list_close(cls,
|
|
266
|
-
tokens: Sequence[Token],
|
|
267
|
-
idx: int,
|
|
268
|
-
md_ctx: _MdCtx,
|
|
269
|
-
content_result: L10NResult):
|
|
270
|
-
# add a blank line when next token is not a closing one
|
|
271
|
-
if idx < len(tokens) - 1 and tokens[idx + 1].nesting != -1:
|
|
272
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
273
|
-
|
|
274
|
-
@classmethod
|
|
275
|
-
def ordered_list_close(cls,
|
|
276
|
-
tokens: Sequence[Token],
|
|
277
|
-
idx: int,
|
|
278
|
-
md_ctx: _MdCtx,
|
|
279
|
-
content_result: L10NResult):
|
|
280
|
-
# add a blank line when next token is not a closing one
|
|
281
|
-
if idx < len(tokens) - 1 and tokens[idx + 1].nesting != -1:
|
|
282
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
283
|
-
|
|
284
|
-
# paragraph
|
|
285
|
-
@classmethod
|
|
286
|
-
def paragraph_close(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
287
|
-
content_result.localized += '\n'
|
|
288
|
-
if idx < len(tokens) - 1:
|
|
289
|
-
next_token = tokens[idx + 1]
|
|
290
|
-
# add a blank line when next token is a setext heading_open, an indented code block, a paragraph open,
|
|
291
|
-
# or a definition list open
|
|
292
|
-
if (next_token.type == 'heading_open' and next_token.markup in SETEXT_HEADING_MARKUPS) \
|
|
293
|
-
or next_token.type in {'code_block', 'paragraph_open', 'dl_open'}:
|
|
294
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
295
|
-
|
|
296
|
-
# indented code block
|
|
297
|
-
@classmethod
|
|
298
|
-
def code_block(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
299
|
-
token = tokens[idx]
|
|
300
|
-
localized_code_block = token.content.replace('\n', f'\n{md_ctx.line_indent} ')
|
|
301
|
-
content_result.localized += f'{md_ctx.get_line_indent()} {localized_code_block}\n'
|
|
302
|
-
|
|
303
|
-
# fenced code block
|
|
304
|
-
@classmethod
|
|
305
|
-
def fence(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
306
|
-
token = tokens[idx]
|
|
307
|
-
localized_fence = _fence(token, md_ctx, content_result)
|
|
308
|
-
localized_fence = localized_fence.replace('\n', f'\n{md_ctx.line_indent}')
|
|
309
|
-
# a newline is at the end of token.content already, so we only need to append token.markup there
|
|
310
|
-
content_result.localized += f'''{md_ctx.get_line_indent()}{token.markup}{token.info}
|
|
311
|
-
{md_ctx.line_indent}{localized_fence}{token.markup}
|
|
312
|
-
'''
|
|
313
|
-
|
|
314
|
-
# html block
|
|
315
|
-
@classmethod
|
|
316
|
-
def html_block(cls, tokens: Sequence[Token], idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
317
|
-
token = tokens[idx]
|
|
318
|
-
localized_html = md_ctx.domain_g.l10n_func(token.content)
|
|
319
|
-
if localized_html is not token.content:
|
|
320
|
-
content_result.l10n_count += 1
|
|
321
|
-
content_result.total_count += 1
|
|
322
|
-
localized_html = localized_html.replace('\n', f'\n{md_ctx.line_indent}')
|
|
323
|
-
content_result.localized += f'{md_ctx.get_line_indent()}{localized_html}\n'
|
|
324
|
-
|
|
325
|
-
# table
|
|
326
|
-
@classmethod
|
|
327
|
-
def table_open(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, _content_result: L10NResult):
|
|
328
|
-
md_ctx.in_table = True
|
|
329
|
-
|
|
330
|
-
@classmethod
|
|
331
|
-
def tr_open(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
332
|
-
content_result.localized += f'{md_ctx.get_line_indent()}|'
|
|
333
|
-
|
|
334
|
-
@classmethod
|
|
335
|
-
def th_open(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
336
|
-
content_result.localized += ' '
|
|
337
|
-
md_ctx.table_sep += '| --- '
|
|
338
|
-
|
|
339
|
-
@classmethod
|
|
340
|
-
def th_close(cls, _tokens: Sequence[Token], _idx: int, _md_ctx: _MdCtx, content_result: L10NResult):
|
|
341
|
-
content_result.localized += ' |'
|
|
342
|
-
|
|
343
|
-
@classmethod
|
|
344
|
-
def thead_close(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
345
|
-
md_ctx.table_sep += '|\n'
|
|
346
|
-
content_result.localized += f'{md_ctx.line_indent}{md_ctx.table_sep}'
|
|
347
|
-
md_ctx.table_sep = ''
|
|
348
|
-
|
|
349
|
-
@classmethod
|
|
350
|
-
def td_open(cls, _tokens: Sequence[Token], _idx: int, _md_ctx: _MdCtx, content_result: L10NResult):
|
|
351
|
-
content_result.localized += ' '
|
|
352
|
-
|
|
353
|
-
@classmethod
|
|
354
|
-
def td_close(cls, _tokens: Sequence[Token], _idx: int, _md_ctx: _MdCtx, content_result: L10NResult):
|
|
355
|
-
content_result.localized += ' |'
|
|
356
|
-
|
|
357
|
-
@classmethod
|
|
358
|
-
def tr_close(cls, _tokens: Sequence[Token], _idx: int, _md_ctx: _MdCtx, content_result: L10NResult):
|
|
359
|
-
content_result.localized += '\n'
|
|
360
|
-
|
|
361
|
-
@classmethod
|
|
362
|
-
def table_close(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
363
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
364
|
-
md_ctx.in_table = False
|
|
365
|
-
|
|
366
|
-
# definition list
|
|
367
|
-
@classmethod
|
|
368
|
-
def dd_open(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, _content_result: L10NResult):
|
|
369
|
-
md_ctx.indent_1st_line += f': '
|
|
370
|
-
md_ctx.indent_1st_line_len += 2
|
|
371
|
-
md_ctx.line_indent += ' ' * 2
|
|
372
|
-
md_ctx.indents.append(2)
|
|
373
|
-
|
|
374
|
-
@classmethod
|
|
375
|
-
def dd_close(cls, _tokens: Sequence[Token], _idx: int, md_ctx: _MdCtx, content_result: L10NResult):
|
|
376
|
-
latest_len = md_ctx.indents.pop()
|
|
377
|
-
md_ctx.line_indent = md_ctx.line_indent[:-latest_len]
|
|
378
|
-
content_result.localized += f'{md_ctx.line_indent}\n'
|
|
379
|
-
|
|
380
|
-
@classmethod
|
|
381
|
-
def dt_close(cls, _tokens: Sequence[Token], _idx: int, _md_ctx: _MdCtx, content_result: L10NResult):
|
|
382
|
-
content_result.localized += '\n'
|
markdown-gettext-0.1.0/setup.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['markdown_gettext',
|
|
6
|
-
'markdown_gettext.extraction',
|
|
7
|
-
'markdown_gettext.generation']
|
|
8
|
-
|
|
9
|
-
package_data = \
|
|
10
|
-
{'': ['*']}
|
|
11
|
-
|
|
12
|
-
install_requires = \
|
|
13
|
-
['PyYAML>=6.0.1,<7.0.0',
|
|
14
|
-
'Pygments>=2.16.1,<3.0.0',
|
|
15
|
-
'markdown-it-py[plugins]>=3.0.0,<4.0.0',
|
|
16
|
-
'polib>=1.2.0,<2.0.0']
|
|
17
|
-
|
|
18
|
-
entry_points = \
|
|
19
|
-
{'console_scripts': ['markdown-gettext = markdown_gettext.cli:main',
|
|
20
|
-
'md-gettext = markdown_gettext.cli:main']}
|
|
21
|
-
|
|
22
|
-
setup_kwargs = {
|
|
23
|
-
'name': 'markdown-gettext',
|
|
24
|
-
'version': '0.1.0',
|
|
25
|
-
'description': 'Markdown i18n with gettext',
|
|
26
|
-
'long_description': '<!--\nSPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>\nSPDX-License-Identifier: CC-BY-SA-4.0\n-->\n\n# markdown-gettext\n\nMarkdown i18n with gettext.\n\nCommonMark compliant. All core Markdown elements are supported, as well as\nfront matter, table, and definition list.\n\nThe package can be used as a command line program to do i18n and l10n for\nindividual Markdown files, and as a library to make larger programs. \n\n## Install\n\n```bash\npip install markdown-gettext\n```\n\n## Usage as a command line program\n_("Usage as a library" in Development section)_\n\nYou can use either `md-gettext` or `markdown-gettext` command\n\n#### Extraction\n```\nmd-gettext extract [-p PACKAGE] [-r REPORT_ADDR] [-t TEAM_ADDR] md pot\n\npositional arguments:\n md path of the Markdown file to extract messages from\n pot path of the POT file to create\n\noptional arguments:\n -p PACKAGE, --package PACKAGE\n the package name in POT metadata\n -r REPORT_ADDR, --report-addr REPORT_ADDR\n the report address in POT metadata\n -t TEAM_ADDR, --team-addr TEAM_ADDR\n the team address in POT metadata\n```\n\n#### Generation\n```\nmd-gettext generate [-l LANG] in-md po out-md\n\npositional arguments:\n in-md path of the source Markdown file\n po path of the PO file containing translations\n out-md path of the Markdown file to create\n\noptional arguments:\n -l LANG, --lang LANG language of translations\n```\n\n## Notes\n\nSome notes about how different elements are handled:\n- Inlines: newlines and consecutive spaces are not kept;\n- Content of each HTML block isn\'t parsed into finer tokens but processed\nas a whole;\n- Fenced code blocks: only `//` comments are processed;\n\n## Development\n\n### Environment\n\n- With Conda\n\n```bash\nconda env create -f environment.yml\nconda activate mg\npoetry install\n```\n\n### Usage as a library\n\n#### Extraction\n- Subclass `DomainExtractionProtocol`, implement\n`DomainExtractionProtocol.render_front_matter`\n- Subclass `RendererMarkdownI18N`\n\n#### Generation\n- Subclass `DomainGenerationProtocol`, implement\n`DomainGenerationProtocol.render_front_matter`\n- Subclass `RendererMarkdownL10N`',
|
|
27
|
-
'author': 'Phu Hung Nguyen',
|
|
28
|
-
'author_email': 'phuhnguyen@outlook.com',
|
|
29
|
-
'maintainer': None,
|
|
30
|
-
'maintainer_email': None,
|
|
31
|
-
'url': 'https://github.com/phunh/markdown-gettext',
|
|
32
|
-
'packages': packages,
|
|
33
|
-
'package_data': package_data,
|
|
34
|
-
'install_requires': install_requires,
|
|
35
|
-
'entry_points': entry_points,
|
|
36
|
-
'python_requires': '>=3.8,<4.0',
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
setup(**setup_kwargs)
|
|
File without changes
|