markdown-gettext 0.2.1__tar.gz → 0.3.0__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.
@@ -1,27 +1,20 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: markdown-gettext
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Markdown i18n with gettext
5
- Home-page: https://github.com/phunh/markdown-gettext
5
+ Author-email: Phu Hung Nguyen <phuhnguyen@outlook.com>
6
6
  License: LGPL-2.1-or-later
7
- Author: Phu Hung Nguyen
8
- Author-email: phuhnguyen@outlook.com
9
- Requires-Python: >=3.8,<4.0
7
+ Project-URL: Repository, https://invent.kde.org/sdk/markdown-gettext.git
10
8
  Classifier: Development Status :: 3 - Alpha
11
9
  Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved
10
+ Classifier: Topic :: Software Development :: Internationalization
13
11
  Classifier: Programming Language :: Python
14
12
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Topic :: Software Development :: Internationalization
19
- Requires-Dist: PyYAML (>=5.3,<6.0); python_version >= "3.8" and python_version < "3.10"
20
- Requires-Dist: PyYAML (>=6.0.1,<7.0.0); python_version >= "3.10"
21
- Requires-Dist: mdit-py-i18n (>=0.2.1,<0.3.0)
22
- Requires-Dist: polib (>=1.2.0,<2.0.0)
23
- Project-URL: Repository, https://github.com/phunh/markdown-gettext
13
+ Requires-Python: >=3.8
24
14
  Description-Content-Type: text/markdown
15
+ Requires-Dist: mdit-py-i18n>=0.3.0
16
+ Requires-Dist: polib>=1.2.0
17
+ Requires-Dist: pyyaml>=6.0.3
25
18
 
26
19
  <!--
27
20
  SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
@@ -92,4 +85,3 @@ conda env create -f environment.yml
92
85
  conda activate mg
93
86
  poetry install
94
87
  ```
95
-
@@ -0,0 +1,77 @@
1
+ # SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
2
+ # SPDX-License-Identifier: CC0-1.0
3
+
4
+ [project]
5
+ name = "markdown-gettext"
6
+ version = "0.3.0"
7
+ description = "Markdown i18n with gettext"
8
+ authors = [
9
+ { name = "Phu Hung Nguyen", email = "phuhnguyen@outlook.com" }
10
+ ]
11
+ # This is a legacy way to specifiy the license
12
+ license = {text = "LGPL-2.1-or-later"}
13
+ # The below is be the modern replacement but not supported by setuptools with Python 3.8
14
+ # See https://setuptools.pypa.io/en/stable/userguide/license_migration.html
15
+ #license = "LGPL-2.1-or-later"
16
+
17
+ readme = "README.md"
18
+ classifiers = [
19
+ "Development Status :: 3 - Alpha",
20
+ "Intended Audience :: Developers",
21
+ "Topic :: Software Development :: Internationalization",
22
+ "Programming Language :: Python",
23
+ "Programming Language :: Python :: 3"
24
+ ]
25
+
26
+ # The KDE Scripty host runs an ancient Python 3.8. Check if this has changed,
27
+ # before raising the minimum required Python version here!
28
+ requires-python = ">=3.8"
29
+ dependencies = [
30
+ "mdit-py-i18n>=0.3.0",
31
+ "polib>=1.2.0",
32
+ "pyyaml>=6.0.3",
33
+ ]
34
+
35
+ [project.urls]
36
+ Repository = "https://invent.kde.org/sdk/markdown-gettext.git"
37
+
38
+ [project.scripts]
39
+ md-gettext = 'markdown_gettext.cli:main'
40
+ markdown-gettext = 'markdown_gettext.cli:main'
41
+
42
+ [tool.isort]
43
+ profile = "black"
44
+
45
+ [tool.tox]
46
+ requires = ["tox>=4.19"]
47
+ envlist = ["sort-imports"]
48
+
49
+ [tool.tox.env.tests]
50
+ description = "Runs pytest"
51
+ deps = ["pytest"]
52
+ commands = [["pytest"]]
53
+
54
+ [tool.tox.env.lint]
55
+ description = "runs flake8"
56
+ skip_install = true
57
+ deps = ["flake8==7.3.0"]
58
+ commands = [["flake8", "."]]
59
+
60
+ [tool.tox.env.check-imports]
61
+ description = "runs isort --check"
62
+ skip_install = true
63
+ deps = ["isort==7.0.0"]
64
+ commands = [["isort", "--check", "."]]
65
+
66
+ [tool.tox.env.sort-imports]
67
+ description = "runs isort"
68
+ skip_install = true
69
+ deps = ["isort==7.0.0"]
70
+ commands = [["isort", "."]]
71
+
72
+ [tool.tox.env.format]
73
+ description = "runs black"
74
+ skip_install = true
75
+ deps = ["black==25.12.0"]
76
+ commands = [["black", "."]]
77
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -20,26 +20,46 @@ from .domain_generation import DomainGeneration, gettext_func
20
20
 
21
21
 
22
22
  def main():
23
- parser = ArgumentParser(description='Markdown i18n with gettext')
24
- subparsers = parser.add_subparsers(description='extracting Markdown to POT and generating Markdown from PO')
25
-
26
- extract_cmd = subparsers.add_parser('extract',
27
- help='extract messages from a Markdown file to a POT file',
28
- formatter_class=RawTextHelpFormatter)
29
- extract_cmd.add_argument('md', help='path of the Markdown file to extract messages from')
30
- extract_cmd.add_argument('pot', help='path of the POT file to create')
31
- extract_cmd.add_argument('-p', '--package', default='', help='the package name in POT metadata')
32
- extract_cmd.add_argument('-r', '--report-addr', default='', help='the report address in POT metadata')
33
- extract_cmd.add_argument('-t', '--team-addr', default='', help='the team address in POT metadata')
23
+ parser = ArgumentParser(description="Markdown i18n with gettext")
24
+ subparsers = parser.add_subparsers(
25
+ description="extracting Markdown to POT and generating Markdown from PO"
26
+ )
27
+
28
+ extract_cmd = subparsers.add_parser(
29
+ "extract",
30
+ help="extract messages from a Markdown file to a POT file",
31
+ formatter_class=RawTextHelpFormatter,
32
+ )
33
+ extract_cmd.add_argument(
34
+ "md", help="path of the Markdown file to extract messages from"
35
+ )
36
+ extract_cmd.add_argument("pot", help="path of the POT file to create")
37
+ extract_cmd.add_argument(
38
+ "-p", "--package", default="", help="the package name in POT metadata"
39
+ )
40
+ extract_cmd.add_argument(
41
+ "-r", "--report-addr", default="", help="the report address in POT metadata"
42
+ )
43
+ extract_cmd.add_argument(
44
+ "-t", "--team-addr", default="", help="the team address in POT metadata"
45
+ )
34
46
  extract_cmd.set_defaults(func=extract)
35
47
 
36
- generate_cmd = subparsers.add_parser('generate',
37
- help='generate a Markdown file from a source Markdown file and a PO file',
38
- formatter_class=RawTextHelpFormatter)
39
- generate_cmd.add_argument('in_md', metavar='in-md', help='path of the source Markdown file')
40
- generate_cmd.add_argument('po', help='path of the PO file containing translations')
41
- generate_cmd.add_argument('out_md', metavar='out-md', help='path of the Markdown file to create')
42
- generate_cmd.add_argument('-l', '--lang', default='en', help='language of translations')
48
+ generate_cmd = subparsers.add_parser(
49
+ "generate",
50
+ help="generate a Markdown file from a source Markdown file and a PO file",
51
+ formatter_class=RawTextHelpFormatter,
52
+ )
53
+ generate_cmd.add_argument(
54
+ "in_md", metavar="in-md", help="path of the source Markdown file"
55
+ )
56
+ generate_cmd.add_argument("po", help="path of the PO file containing translations")
57
+ generate_cmd.add_argument(
58
+ "out_md", metavar="out-md", help="path of the Markdown file to create"
59
+ )
60
+ generate_cmd.add_argument(
61
+ "-l", "--lang", default="en", help="language of translations"
62
+ )
43
63
  generate_cmd.set_defaults(func=generate)
44
64
 
45
65
  args = parser.parse_args()
@@ -48,14 +68,15 @@ def main():
48
68
 
49
69
  def extract(args):
50
70
  md_path = args.md
51
- mdi = MarkdownIt(renderer_cls=RendererMarkdownI18N).use(front_matter_plugin)\
52
- .enable('table').use(deflist_plugin)
71
+ mdi = (
72
+ MarkdownIt(renderer_cls=RendererMarkdownI18N)
73
+ .use(front_matter_plugin)
74
+ .enable("table")
75
+ .use(deflist_plugin)
76
+ )
53
77
  domain_e = DomainExtraction()
54
78
  with open(md_path) as f_md:
55
- env = {
56
- 'path': md_path,
57
- 'domain_extraction': domain_e
58
- }
79
+ env = {"path": md_path, "domain_extraction": domain_e}
59
80
  mdi.render(f_md.read(), env)
60
81
  package = args.package or md_path
61
82
  target = args.pot
@@ -64,13 +85,13 @@ def extract(args):
64
85
 
65
86
 
66
87
  def compile_po(lang: str, po_path: str):
67
- target_dir = f'locale/{lang}/LC_MESSAGES'
88
+ target_dir = f"locale/{lang}/LC_MESSAGES"
68
89
  os.makedirs(target_dir, exist_ok=True)
69
90
  po_basename = os.path.basename(po_path)
70
- mo_path = f'{target_dir}/{po_basename[:-2]}mo'
91
+ mo_path = f"{target_dir}/{po_basename[:-2]}mo"
71
92
 
72
93
  with_gettext = True
73
- test_cmd = 'msgfmt -V'
94
+ test_cmd = "msgfmt -V"
74
95
  try:
75
96
  # do not show the output of running test_cmd
76
97
  subprocess.run(test_cmd, shell=True, check=True, capture_output=True)
@@ -78,7 +99,7 @@ def compile_po(lang: str, po_path: str):
78
99
  with_gettext = False
79
100
 
80
101
  if with_gettext:
81
- command = f'msgfmt {po_path} -o {mo_path}'
102
+ command = f"msgfmt {po_path} -o {mo_path}"
82
103
  subprocess.run(command, shell=True, check=True)
83
104
  else:
84
105
  polib.pofile(po_path).save_as_mofile(mo_path)
@@ -89,27 +110,29 @@ def generate(args):
89
110
  po_path = args.po
90
111
 
91
112
  compile_po(lang, po_path)
92
- os.environ['LANGUAGE'] = lang
113
+ os.environ["LANGUAGE"] = lang
93
114
  domain_name = os.path.splitext(os.path.basename(po_path))[0]
94
115
  l10n_func = gettext_func(domain_name)
95
116
 
96
- mdi = MarkdownIt(renderer_cls=RendererMarkdownL10N).use(front_matter_plugin)\
97
- .enable('table').use(deflist_plugin)
117
+ mdi = (
118
+ MarkdownIt(renderer_cls=RendererMarkdownL10N)
119
+ .use(front_matter_plugin)
120
+ .enable("table")
121
+ .use(deflist_plugin)
122
+ )
98
123
  domain_g = DomainGeneration(l10n_func)
99
124
 
100
125
  def render_content_file(src_path: str) -> Tuple[L10NResult, L10NResult]:
101
126
  with open(src_path) as f_content:
102
- env = {
103
- 'domain_generation': domain_g
104
- }
127
+ env = {"domain_generation": domain_g}
105
128
  return mdi.render(f_content.read(), env)
106
129
 
107
130
  def write_content_file(fm: str, content: str, target_path: str):
108
131
  os.makedirs(os.path.dirname(os.path.abspath(target_path)), exist_ok=True)
109
- with open(target_path, 'w+') as f_target:
132
+ with open(target_path, "w+") as f_target:
110
133
  f_target.write(fm)
111
134
  f_target.write(content)
112
135
 
113
136
  fm_result, content_result = render_content_file(args.in_md)
114
137
  write_content_file(fm_result.localized, content_result.localized, args.out_md)
115
- shutil.rmtree('locale')
138
+ shutil.rmtree("locale")
@@ -0,0 +1,103 @@
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, field
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+ from typing import List, Tuple
8
+
9
+ import polib
10
+ import yaml
11
+ from mdit_py_i18n import utils
12
+
13
+
14
+ @dataclass
15
+ class I18NEntry:
16
+ msgid: str
17
+ occurrences: List[Tuple[str, int]] = field(default_factory=list)
18
+ comment: str = ""
19
+ msgctxt: str = ""
20
+
21
+ def to_poentry(self) -> polib.POEntry:
22
+ return polib.POEntry(
23
+ msgid=self.msgid,
24
+ msgstr="",
25
+ # 0 passed to polib will be lost, use `str` to keep 0
26
+ occurrences=[(o[0], str(o[1])) for o in self.occurrences],
27
+ comment=self.comment,
28
+ msgctxt=self.msgctxt if self.msgctxt != "" else None,
29
+ )
30
+
31
+
32
+ class DomainExtraction:
33
+ """
34
+ Implements `DomainExtractionProtocol`
35
+ """
36
+
37
+ def __init__(self):
38
+ self.entries: List[I18NEntry] = []
39
+
40
+ def add_entry(
41
+ self, path: str, msgid: str, line_num: int, comment: str = "", msgctxt: str = ""
42
+ ):
43
+ if not msgid:
44
+ return
45
+ for e in self.entries:
46
+ if msgid == e.msgid and msgctxt == e.msgctxt:
47
+ e.occurrences.append((path, line_num))
48
+ return
49
+ self.entries.append(I18NEntry(msgid, [(path, line_num)], comment, msgctxt))
50
+
51
+ def i12ize_front_matter(self, o, path: str):
52
+ """Internationalize an object in front matter.
53
+ :param o: the object being processed
54
+ :param path: path of the source file
55
+ :return: None. Messages are added to the `entries` list.
56
+ """
57
+ if isinstance(o, str) and o and not utils.SPACES_PATTERN.fullmatch(o):
58
+ self.add_entry(path, o, 0)
59
+ elif isinstance(o, list) or isinstance(o, dict):
60
+ for _, value in (enumerate(o) if isinstance(o, list) else o.items()):
61
+ self.i12ize_front_matter(value, path)
62
+
63
+ def render_front_matter(self, path: str, content: str, _markup: str):
64
+ fm = yaml.safe_load(content)
65
+ self.i12ize_front_matter(fm, path)
66
+
67
+ def open_existing_pot(self, dest_path: str):
68
+ """
69
+ Open existing pot file if present and create a map to fast access to
70
+ messages by msgid
71
+ """
72
+ if not Path(dest_path).exists():
73
+ return None
74
+ existing_pot = polib.pofile(dest_path)
75
+ existing_pot.map_by_id = {e.msgid: e for e in existing_pot}
76
+ return existing_pot
77
+
78
+ def make_pot(
79
+ self, package: str, report_address: str, team_address: str, dest_path: str
80
+ ):
81
+ pot = polib.POFile()
82
+ pot.metadata = {
83
+ "Project-Id-Version": f"{package} 1.0",
84
+ "Report-Msgid-Bugs-To": report_address,
85
+ "POT-Creation-Date": datetime.now()
86
+ .astimezone()
87
+ .strftime("%Y-%m-%d %H:%M%z"),
88
+ "PO-Revision-Date": "YEAR-MO-DA HO:MI+ZONE",
89
+ "Last-Translator": "FULL NAME <EMAIL@ADDRESS>",
90
+ "Language-Team": f"LANGUAGE <{team_address}>",
91
+ "MIME-Version": "1.0",
92
+ "Content-Type": "text/plain; charset=utf-8",
93
+ "Content-Transfer-Encoding": "8bit",
94
+ }
95
+
96
+ existing_pot = self.open_existing_pot(dest_path)
97
+ for e in self.entries:
98
+ # preserve existing comments
99
+ if not e.comment and existing_pot and e.msgid in existing_pot.map_by_id:
100
+ e.comment = existing_pot.map_by_id[e.msgid].comment
101
+
102
+ pot.append(e.to_poentry())
103
+ pot.save(dest_path)
@@ -9,7 +9,7 @@ from mdit_py_i18n.utils import L10NFunc, L10NResult
9
9
 
10
10
 
11
11
  def gettext_func(domain_name):
12
- gettext.bindtextdomain(domain_name, 'locale')
12
+ gettext.bindtextdomain(domain_name, "locale")
13
13
  gettext.textdomain(domain_name)
14
14
  return gettext.gettext
15
15
 
@@ -18,6 +18,7 @@ class DomainGeneration:
18
18
  """
19
19
  Implements `DomainGenerationProtocol`
20
20
  """
21
+
21
22
  def __init__(self, l10n_func: L10NFunc):
22
23
  self.l10n_func = l10n_func
23
24
 
@@ -44,6 +45,8 @@ class DomainGeneration:
44
45
  def render_front_matter(self, content: str, markup: str) -> L10NResult:
45
46
  fm = yaml.safe_load(content)
46
47
  fm_result = self.localize_front_matter(fm)
47
- rendered_localized_fm = yaml.dump(fm, default_flow_style=False, allow_unicode=True)
48
- fm_result.localized = f'{markup}\n{rendered_localized_fm}\n{markup}\n'
48
+ rendered_localized_fm = yaml.dump(
49
+ fm, default_flow_style=False, allow_unicode=True
50
+ )
51
+ fm_result.localized = f"{markup}\n{rendered_localized_fm}\n{markup}\n"
49
52
  return fm_result
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.4
2
+ Name: markdown-gettext
3
+ Version: 0.3.0
4
+ Summary: Markdown i18n with gettext
5
+ Author-email: Phu Hung Nguyen <phuhnguyen@outlook.com>
6
+ License: LGPL-2.1-or-later
7
+ Project-URL: Repository, https://invent.kde.org/sdk/markdown-gettext.git
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Internationalization
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: mdit-py-i18n>=0.3.0
16
+ Requires-Dist: polib>=1.2.0
17
+ Requires-Dist: pyyaml>=6.0.3
18
+
19
+ <!--
20
+ SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
21
+ SPDX-License-Identifier: CC-BY-SA-4.0
22
+ -->
23
+
24
+ # markdown-gettext
25
+
26
+ A command line program to do i18n and l10n for individual Markdown files.
27
+
28
+ CommonMark compliant. All core Markdown elements are supported, as well as
29
+ YAML front matter, table, and definition list.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pip install markdown-gettext
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ You can use either `md-gettext` or `markdown-gettext` command
40
+
41
+ #### Extraction
42
+ ```
43
+ md-gettext extract [-p PACKAGE] [-r REPORT_ADDR] [-t TEAM_ADDR] md pot
44
+
45
+ positional arguments:
46
+ md path of the Markdown file to extract messages from
47
+ pot path of the POT file to create
48
+
49
+ optional arguments:
50
+ -p PACKAGE, --package PACKAGE
51
+ the package name in POT metadata
52
+ -r REPORT_ADDR, --report-addr REPORT_ADDR
53
+ the report address in POT metadata
54
+ -t TEAM_ADDR, --team-addr TEAM_ADDR
55
+ the team address in POT metadata
56
+ ```
57
+
58
+ #### Generation
59
+ ```
60
+ md-gettext generate [-l LANG] in-md po out-md
61
+
62
+ positional arguments:
63
+ in-md path of the source Markdown file
64
+ po path of the PO file containing translations
65
+ out-md path of the Markdown file to create
66
+
67
+ optional arguments:
68
+ -l LANG, --lang LANG language of translations
69
+ ```
70
+
71
+ ## Notes
72
+
73
+ Some notes about how different elements are handled:
74
+ - Inlines: hard line breaks are replaced with `<br />`, newlines and
75
+ consecutive spaces are not kept;
76
+ - Content of each HTML block isn't parsed into finer tokens but processed
77
+ as a whole;
78
+
79
+ ## Development environment
80
+
81
+ - With Conda
82
+
83
+ ```bash
84
+ conda env create -f environment.yml
85
+ conda activate mg
86
+ poetry install
87
+ ```
@@ -0,0 +1,12 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/markdown_gettext/__init__.py
4
+ src/markdown_gettext/cli.py
5
+ src/markdown_gettext/domain_extraction.py
6
+ src/markdown_gettext/domain_generation.py
7
+ src/markdown_gettext.egg-info/PKG-INFO
8
+ src/markdown_gettext.egg-info/SOURCES.txt
9
+ src/markdown_gettext.egg-info/dependency_links.txt
10
+ src/markdown_gettext.egg-info/entry_points.txt
11
+ src/markdown_gettext.egg-info/requires.txt
12
+ src/markdown_gettext.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ markdown-gettext = markdown_gettext.cli:main
3
+ md-gettext = markdown_gettext.cli:main
@@ -0,0 +1,3 @@
1
+ mdit-py-i18n>=0.3.0
2
+ polib>=1.2.0
3
+ pyyaml>=6.0.3
@@ -0,0 +1 @@
1
+ markdown_gettext
@@ -1,76 +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, field
5
- from datetime import datetime
6
- from typing import List, Tuple
7
-
8
- import polib
9
- import yaml
10
- from mdit_py_i18n import utils
11
-
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 = ''
19
-
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)
27
-
28
-
29
- class DomainExtraction:
30
- """
31
- Implements `DomainExtractionProtocol`
32
- """
33
- def __init__(self):
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))
44
-
45
- def i12ize_front_matter(self, o, path: str):
46
- """Internationalize an object in front matter.
47
- :param o: the object being processed
48
- :param path: path of the source file
49
- :return: None. Messages are added to the `entries` list.
50
- """
51
- if isinstance(o, str) and o and not utils.SPACES_PATTERN.fullmatch(o):
52
- self.add_entry(path, o, 0)
53
- elif isinstance(o, list) or isinstance(o, dict):
54
- for _, value in (enumerate(o) if isinstance(o, list) else o.items()):
55
- self.i12ize_front_matter(value, path)
56
-
57
- def render_front_matter(self, path: str, content: str, _markup: str):
58
- fm = yaml.safe_load(content)
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,36 +0,0 @@
1
- # SPDX-FileCopyrightText: 2023 Phu Hung Nguyen <phuhnguyen@outlook.com>
2
- # SPDX-License-Identifier: CC0-1.0
3
-
4
- [tool.poetry]
5
- name = "markdown-gettext"
6
- version = "0.2.1"
7
- description = "Markdown i18n with gettext"
8
- authors = ["Phu Hung Nguyen <phuhnguyen@outlook.com>"]
9
- license = "LGPL-2.1-or-later"
10
- readme = "README.md"
11
- repository = "https://github.com/phunh/markdown-gettext"
12
- classifiers = [
13
- "Development Status :: 3 - Alpha",
14
- "Intended Audience :: Developers",
15
- "Topic :: Software Development :: Internationalization",
16
- "Programming Language :: Python",
17
- "Programming Language :: Python :: 3"
18
- ]
19
- packages = [{include = "markdown_gettext"}]
20
-
21
- [tool.poetry.dependencies]
22
- python = "^3.8"
23
- polib = "^1.2.0"
24
- PyYAML = [
25
- {version = "^5.3", python = ">=3.8,<3.10"},
26
- {version = "^6.0.1", python = ">=3.10"}
27
- ]
28
- mdit-py-i18n = "^0.2.1"
29
-
30
- [tool.poetry.scripts]
31
- md-gettext = 'markdown_gettext.cli:main'
32
- markdown-gettext = 'markdown_gettext.cli:main'
33
-
34
- [build-system]
35
- requires = ["poetry-core"]
36
- build-backend = "poetry.core.masonry.api"
@@ -1,40 +0,0 @@
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
- ['mdit-py-i18n>=0.2.1,<0.3.0', 'polib>=1.2.0,<2.0.0']
12
-
13
- extras_require = \
14
- {':python_version >= "3.10"': ['PyYAML>=6.0.1,<7.0.0'],
15
- ':python_version >= "3.8" and python_version < "3.10"': ['PyYAML>=5.3,<6.0']}
16
-
17
- entry_points = \
18
- {'console_scripts': ['markdown-gettext = markdown_gettext.cli:main',
19
- 'md-gettext = markdown_gettext.cli:main']}
20
-
21
- setup_kwargs = {
22
- 'name': 'markdown-gettext',
23
- 'version': '0.2.1',
24
- 'description': 'Markdown i18n with gettext',
25
- '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: hard line breaks are replaced with `<br />`, newlines and\nconsecutive spaces are not kept;\n- Content of each HTML block isn't parsed into finer tokens but processed\nas a whole;\n\n## Development environment\n\n- With Conda\n\n```bash\nconda env create -f environment.yml\nconda activate mg\npoetry install\n```\n",
26
- 'author': 'Phu Hung Nguyen',
27
- 'author_email': 'phuhnguyen@outlook.com',
28
- 'maintainer': None,
29
- 'maintainer_email': None,
30
- 'url': 'https://github.com/phunh/markdown-gettext',
31
- 'packages': packages,
32
- 'package_data': package_data,
33
- 'install_requires': install_requires,
34
- 'extras_require': extras_require,
35
- 'entry_points': entry_points,
36
- 'python_requires': '>=3.8,<4.0',
37
- }
38
-
39
-
40
- setup(**setup_kwargs)