Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance transtion to discover multiple translation from same Python plugin #1918

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)