Skip to content

Commit

Permalink
Moving i18n_config.py and en.json into main package, and adding abili…
Browse files Browse the repository at this point in the history
…ty to specify a i18n config directory via environment variable or use the current migration project base directory, falling back to packaged. Fixes i18n changes require files not included in the package distribution #703
  • Loading branch information
bltravis committed Nov 6, 2023
1 parent 6b43f62 commit c89c2fc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

import pytest


Expand All @@ -10,7 +11,7 @@ def pytest_addoption(parser):
# parser.addoption("--folio_release", action="store")


i18n_config_file = Path(__file__).parent / "i18n_config.py"
i18n_config_file = Path(__file__).parent / "src/folio_migration_tools/i18n_config.py"


@pytest.fixture(scope="session", autouse=True)
Expand Down
17 changes: 11 additions & 6 deletions src/folio_migration_tools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import json
import logging
import sys
from pathlib import Path
from os import environ
from pathlib import Path

import httpx
import humps
import i18n
from argparse_prompt import PromptParser
from pydantic import ValidationError

from folio_migration_tools.config_file_load import merge_load
from folio_migration_tools.custom_exceptions import TransformationProcessError
from folio_migration_tools.library_configuration import LibraryConfiguration
from folio_migration_tools.migration_tasks import * # noqa: F403, F401
from folio_migration_tools.migration_tasks import migration_task_base
from folio_migration_tools.config_file_load import merge_load

import i18n

i18n.load_config(Path(__file__).parents[2] / "i18n_config.py")


def parse_args(args):
Expand Down Expand Up @@ -68,6 +65,14 @@ def main():
task_classes = list(inheritors(migration_task_base.MigrationTaskBase))

args = parse_args(sys.argv[1:])
try:
i18n.load_config(
Path(
environ.get(
"FOLIO_MIGRATION_TOOLS_I18N_CONFIG_BASE_PATH"
) or args.base_folder_path) / "i18n_config.py")
except i18n.I18nFileLoadError:
i18n.load_config(Path(__file__).parent / "i18n_config.py")
i18n.set("locale", args.report_language)
config_file_humped = merge_load(args.configuration_path)
config_file_humped["libraryInformation"]["okapiPassword"] = args.okapi_password
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,4 @@
"legacy id from %{fro}": "legacy id from %{fro}",
"naturalId mapped from %{fro}": "naturalId mapped from %{fro}",
"no matching identifier_types in %{names}": "no matching identifier_types in %{names}"
}
}
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_dedupe():


def test_blurb_internationalization():
i18n.load_config(Path(__file__).parents[1] / "i18n_config.py")
i18n.load_config(Path(__file__).parents[1] / "src/folio_migration_tools/i18n_config.py")
assert i18n.t("blurbs.Introduction.title") == "Introduction"


Expand Down

0 comments on commit c89c2fc

Please sign in to comment.