From 4bd065f871d5ee318c5f5a4835be025b13ae28e8 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 10 Mar 2019 13:00:10 +0100 Subject: [PATCH] use revert_language in more cases --- lib/lyx2lyx/lyx_2_0.py | 16 ++------------- lib/lyx2lyx/lyx_2_1.py | 44 ++++++++++++------------------------------ lib/lyx2lyx/lyx_2_2.py | 13 +++---------- 3 files changed, 17 insertions(+), 56 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 3faf944a97..480971b531 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -30,7 +30,7 @@ from parser_tools import del_complete_lines, \ from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \ put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \ - revert_font_attrs, hex2ratio, str2bool + revert_font_attrs, hex2ratio, str2bool, revert_language #################################################################### # Private helper functions @@ -1281,19 +1281,7 @@ def revert_notefontcolor(document): def revert_turkmen(document): "Set language Turkmen to English" - if document.language == "turkmen": - document.language = "english" - i = find_token(document.header, "\\language", 0) - if i != -1: - document.header[i] = "\\language english" - - j = 0 - while True: - j = find_token(document.body, "\\lang turkmen", j) - if j == -1: - return - document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english") - j += 1 + revert_language(document, "turkmen", "turkmen", "turkmen") def revert_fontcolor(document): diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index 63d7621ab1..8838a64042 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -34,7 +34,7 @@ from parser_tools import count_pars_in_inset, del_complete_lines, del_token, \ #find_end_of_inset, find_end_of_layout, \ #is_in_inset, del_token, check_token -from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert +from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, revert_language #from lyx2lyx_tools import insert_to_preamble, \ # lyx2latex, latex_length, revert_flex_inset, \ @@ -1169,24 +1169,16 @@ def revert_ancientgreek(document): def revert_languages(document): "Set the document language for new supported languages to English" - languages = [ - "coptic", "divehi", "hindi", "kurmanji", "lao", "marathi", "occitan", "sanskrit", - "syriac", "tamil", "telugu", "urdu" - ] - for n in range(len(languages)): - if document.language == languages[n]: - document.language = "english" - i = find_token(document.header, "\\language", 0) - if i != -1: - document.header[i] = "\\language english" - j = 0 - while j < len(document.body): - j = find_token(document.body, "\\lang " + languages[n], j) - if j != -1: - document.body[j] = document.body[j].replace("\\lang " + languages[n], "\\lang english") - j += 1 - else: - j = len(document.body) + # polyglossia-only + polyglossia_languages = ["coptic", "divehi", "hindi", "lao", "marathi", + "occitan", "sanskrit", "syriac", "tamil", + "telugu", "urdu"] + # babel-only + babel_languages = ["kurmanji"] + for lang in polyglossia_languages: + revert_language(document, lang, "", lang) + for lang in babel_languages: + revert_language(document, lang, lang, "") def convert_armenian(document): @@ -4561,19 +4553,7 @@ def revert_aa2(document): def revert_tibetan(document): "Set the document language for Tibetan to English" - if document.language == "tibetan": - document.language = "english" - i = find_token(document.header, "\\language", 0) - if i != -1: - document.header[i] = "\\language english" - j = 0 - while j < len(document.body): - j = find_token(document.body, "\\lang tibetan", j) - if j != -1: - document.body[j] = document.body[j].replace("\\lang tibetan", "\\lang english") - j += 1 - else: - j = len(document.body) + revert_language(document, "tibetan", "", "tibetan") ############# diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index ec5cfdbd0c..9011c66975 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -25,7 +25,8 @@ import sys, os # Uncomment only what you need to import, please. from lyx2lyx_tools import (add_to_preamble, put_cmd_in_ert, get_ert, - lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets, insert_document_option) + lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets, insert_document_option, + revert_language) from parser_tools import (check_token, del_complete_lines, find_end_of_inset, find_end_of_layout, find_nonempty_line, find_re, @@ -852,15 +853,7 @@ def revert_specialchar(document): def revert_georgian(document): "Set the document language to English but assure Georgian output" - if document.language == "georgian": - document.language = "english" - i = find_token(document.header, "\\language georgian", 0) - if i != -1: - document.header[i] = "\\language english" - j = find_token(document.header, "\\language_package default", 0) - if j != -1: - document.header[j] = "\\language_package babel" - insert_document_option(document, "georgian") + revert_language(document, "georgian", "georgian", "") def revert_sigplan_doi(document):