From 9333f242df3f97c1780c4c117f080007f833b69e Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Tue, 25 Feb 2020 22:03:30 +0100 Subject: [PATCH] Allow custom reversed_pre_processor_mapping --- src/transliterate/base.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/transliterate/base.py b/src/transliterate/base.py index 44fd13a..14493dd 100644 --- a/src/transliterate/base.py +++ b/src/transliterate/base.py @@ -102,6 +102,7 @@ class TranslitLanguagePack(object): mapping = None reversed_specific_mapping = None + reversed_pre_processor_mapping = None # Added reversed_pre_processor_mapping_keys = [] reversed_specific_pre_processor_mapping = None @@ -141,14 +142,18 @@ def __init__(self): # If any pre-processor rules defined, reversing them for later use. if self.pre_processor_mapping: - self.reversed_pre_processor_mapping = dict( - zip( - self.pre_processor_mapping.values(), - self.pre_processor_mapping.keys()) - ) self.pre_processor_mapping_keys = self.pre_processor_mapping.keys() + # If no `reversed_pre_processor_mapping` is defined, construct + # from `pre_processor_mapping`. + if not self.reversed_pre_processor_mapping: + self.reversed_pre_processor_mapping = dict( + zip( + self.pre_processor_mapping.values(), + self.pre_processor_mapping.keys() + ) + ) self.reversed_pre_processor_mapping_keys = \ - self.pre_processor_mapping.values() + self.reversed_pre_processor_mapping.keys() else: self.reversed_pre_processor_mapping = None