From 0e65981564564bbb2ebfeea4289a4d56c85e9888 Mon Sep 17 00:00:00 2001 From: matze-dd Date: Tue, 8 Dec 2020 16:19:55 +0100 Subject: [PATCH] Closes #147, closes #149 --- HISTORY.md | 2 ++ tests/test_multi_lang.py | 22 ++++++++++++++++++++++ yalafi/packages/babel.py | 18 +++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6922110e..7780112b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,8 @@ Work in progress (PR [#133](../../pull/133)) - new package xspace: macro \\xspace; **thanks to @blipp** (PR [#134](../../pull/134), issue [#140](../../issues/140)) + - package babel: fixed a problem with parsing of package options + (issue [#147](../../issues/147)) - yalafi.shell - added option --no-specials (issue [#131](../../issues/131)) - fixed problem with --add-modules (issue [#144](../../issues/144)) diff --git a/tests/test_multi_lang.py b/tests/test_multi_lang.py index 0cd3dcef..017c812b 100644 --- a/tests/test_multi_lang.py +++ b/tests/test_multi_lang.py @@ -327,3 +327,25 @@ def test_13(): plain = get_ml_txt(latex_13, lang='en-GB') assert plain == plain_13 +# issues 147, 149 +# +latex_14 = r""" +"a +\usepackage[english,ngerman,math=normal]{babel} +"a +""" +plain_14 = { +'de-DE': [ +"""รค +""" +], +'en-GB': [ +""" +"a +""" +] +} +def test_14(): + plain = get_ml_txt(latex_14, lang='en-GB') + assert plain == plain_14 + diff --git a/yalafi/packages/babel.py b/yalafi/packages/babel.py index 540b54ca..70dc29d2 100644 --- a/yalafi/packages/babel.py +++ b/yalafi/packages/babel.py @@ -21,6 +21,7 @@ # 'ca-ES-valencia' 'danish': 'da-DK', 'german': 'de-DE', + 'ngerman': 'de-DE', 'german-at': 'de-AT', 'german-ch': 'de-CH', 'greek': 'el-GR', @@ -87,11 +88,7 @@ def init_module(parser, options): ] - inject_tokens = [] - if options: - # set current language to the last in option list - inject_tokens = [LanguageToken(0, lang=translate_lang(options[-1][0]), - hard=True, brk=True)] + inject_tokens = get_language_token(options) return InitModule(macros_latex=macros_latex, macros_python=macros_python, environments=environments, inject_tokens=inject_tokens) @@ -124,3 +121,14 @@ def h_end_otherlang(parser, buf, mac, args, delim, pos): def h_end_otherlang_star(parser, buf, mac, args, delim, pos): return [LanguageToken(pos, back=True)] +# return a list +# - with LanguageToken corresponding to given option +# - or empty, if no language option found +# +def get_language_token(options): + for opt in reversed(options): + if opt[1] is None and opt[0] in language_map: + return [LanguageToken(0, lang=translate_lang(opt[0]), + hard=True, brk=True)] + return [] +