diff --git a/legaltexts/translate.py b/legaltexts/translate.py index 888f496..ad21819 100644 --- a/legaltexts/translate.py +++ b/legaltexts/translate.py @@ -1,14 +1,17 @@ from yamlns import ns from pathlib import Path +from importlib.resources import files as package_files def build_translations(): if hasattr(build_translations, "translations"): return build_translations.translations translations = ns() - for translation_file in (Path(__file__).parent/'i18n').glob('*.yaml'): + for translation_file in package_files('legaltexts.i18n').iterdir(): + if translation_file.suffix != '.yaml': continue lang = translation_file.stem - translations[lang] = ns.load(translation_file) + translations[lang] = ns.loads(translation_file.read_text()) build_translations.translations = translations + print(build_translations.translations) return build_translations.translations def tr(lang, text, *args, **kwds):