Skip to content

Commit

Permalink
:meth: and :class: in front not trim
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 23, 2023
1 parent a86a13f commit 976a1da
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/aiida_core_i18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ def str_post_processing(raw_str: str) -> str:

# r"请访问 ``话语论坛 <https://aiida.discourse.group> `__``。" -> r"请访问 `话语论坛 <https://aiida.discourse.group>`__。"
res = re.sub(r"``(.*?)\s+`__``", r"`\1`__ ", res, flags=re.ASCII)

# Strip the space in both ends, otherwise the next pp will be revert
res = res.strip()

# Add a space in front if string start with :meth: like ":meth: {context}" -> "_space:meth: {context}"
# :class: -> _space:class:
if res.startswith(":meth:"):
res = " " + res
if res.startswith(":class:"):
res = " " + res

return res.strip()
return res

def met_skip_rule(inp_str: str) -> bool:
"""The rule when met, skip the translation
Expand Down
2 changes: 2 additions & 0 deletions tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def test_replace_protect():
('input', 'expected'),
[
(r"请访问 ``话语论坛 <https://aiida.discourse.group> `__``。", r"请访问 `话语论坛 <https://aiida.discourse.group>`__ 。"),
(r":meth:`ProcessNodeCaching.is_valid_cache <aiida.orm.nodes.process.process.ProcessNodeCaching.is_valid_cache>` 调用", " " + ":meth:`ProcessNodeCaching.is_valid_cache <aiida.orm.nodes.process.process.ProcessNodeCaching.is_valid_cache>` 调用"),
(r":class:`~aiida.engine.processes.process.Process` 子类", " " + ":class:`~aiida.engine.processes.process.Process` 子类"),
]
)
def test_str_post_processing(input: str, expected: str):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_translate/test_po_translate_max_chars_100_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr ""
2 changes: 1 addition & 1 deletion tests/test_translate/test_po_translate_max_chars_20_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr ""
2 changes: 1 addition & 1 deletion tests/test_translate/test_po_translate_max_chars_3_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr ""
4 changes: 2 additions & 2 deletions tests/test_translate/test_po_translate_max_chars_500_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`_"
4 changes: 2 additions & 2 deletions tests/test_translate/test_po_translate_override_False_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`_"
4 changes: 2 additions & 2 deletions tests/test_translate/test_po_translate_override_True_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ msgid ""
"engine for robust and modular computational workflows*, Computational "
"Materials Science **187**, 110086 (2021); DOI: "
"`10.1016/j.commatsci.2020.110086 "
"<https://doi.org/10.1016/j.commatsci.2020.110086>`"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`"
"<https://doi.org/10.1016/j.commatsci.2020.110086>`_"
msgstr "Martin Uhrin, Sebastiaan. P. Huber, Jusong Yu, Nicola Marzari, and Giovanni Pizzi, *Workflows in AiiDA: Engineering a high-throughput, event-based engine for robust and modular computational workflows*, Computational Materials Science **187**, 110086 (2021); DOI: `10.1016/j.commatsci.2020.110086 <https://doi.org/10.1016/j.commatsci.2020.110086>`_"

0 comments on commit 976a1da

Please sign in to comment.