From 8861d356e7bbdd79ce323b0838762ed31d7a5122 Mon Sep 17 00:00:00 2001 From: Bryan Kok Date: Thu, 1 Apr 2021 13:14:35 +0800 Subject: [PATCH] Do not write locl table if no substitutions table needed --- hanazono_lite/generateFeatures.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hanazono_lite/generateFeatures.py b/hanazono_lite/generateFeatures.py index 168ccb7..c2b9744 100644 --- a/hanazono_lite/generateFeatures.py +++ b/hanazono_lite/generateFeatures.py @@ -53,14 +53,23 @@ def generateFeatures( (glyphwiki_to_cid[glyphwiki_code], glyphwiki_to_cid[resolved]) ) - f.write("feature locl {\n") + # is the locl table NOT going to be empty? + has_locales = False for _locale in LOCALES: if _locale != locale and len(substitution_rules[_locale]): - f.write(f""" script hani;\n language {LOCALES[_locale]["tla"]};\n""") + has_locales = True + break - for (_from, _to) in substitution_rules[_locale]: - f.write(f""" substitute \{_from} by \{_to};\n""") + if has_locales: + f.write("feature locl {\n") + for _locale in LOCALES: + if _locale != locale and len(substitution_rules[_locale]): + f.write(f""" script hani;\n language {LOCALES[_locale]["tla"]};\n""") + + for (_from, _to) in substitution_rules[_locale]: + f.write(f""" substitute \{_from} by \{_to};\n""") + + f.write("} locl;\n") - f.write("} locl;\n") f.write(FEATURES_FOOTER_TEMPLATE()) f.close() \ No newline at end of file