Skip to content

Commit

Permalink
Enhance transtion to discover multiple translation from same Python p…
Browse files Browse the repository at this point in the history
…lugin

Fixes #1917
  • Loading branch information
aaltat committed Sep 8, 2024
1 parent c55cb9c commit b5986f4
Show file tree
Hide file tree
Showing 6 changed files with 1,872 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/SeleniumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,20 @@ def _get_translation(language: Union[str, None]) -> Union[Path, None]:
for _, name, _ in pkgutil.iter_modules()
if name.startswith("robotframework_seleniumlibrary_translation")
}
lang = language.lower()
for plugin in discovered_plugins.values():
try:
data = plugin.get_language()
except AttributeError:
continue
if data.get("language", "").lower() == language.lower() and data.get(
"path"
if (
isinstance(data, dict)
and data.get("language", "").lower() == lang
and data.get("path")
):
return Path(data.get("path")).absolute()
if isinstance(data, list):
for item in data:
if item.get("language", "").lower() == lang and item.get("path"):
return Path(item.get("path")).absolute()
return None

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path


def get_language() -> list:
curr_dir = Path(__file__).parent.absolute()
return [
{
"language": "eng",
"path": curr_dir / "translate1.json"
},
{
"language": "swe",
"path": curr_dir / "translate2.json"
}
]

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion utest/test/translation/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ def test_translation(sl: SeleniumLibrary):
assert spec.argument_specification
doc: str = spec.documentation
assert doc.startswith(
"1 SeleniumLibrary is a web testing library for Robot Framework"
"00 SeleniumLibrary is a web testing library for Robot Framework"
)

spec = sl.keywords_spec["hallinnoi_hälytys"]
doc: str = spec.documentation
assert doc == "Hallinnoi hälytyksen uusi dokkari\n\nToinen rivi"


def test_provide_translation_as_list(sl: SeleniumLibrary):
lang_plugin = "robotframework_seleniumlibrary_translation_list"
file_path = Path(__file__).parent.parent / lang_plugin / "translate2.json"
received_path = sl._get_translation("swe")
assert received_path == file_path, received_path.relative_to(file_path)
assert sl._get_translation("wrong") is None
received_path = sl._get_translation("Eng")
file_path = Path(__file__).parent.parent / lang_plugin / "translate1.json"
assert received_path == file_path, received_path.relative_to(file_path)

0 comments on commit b5986f4

Please sign in to comment.