Skip to content

Commit 877f34b

Browse files
committed
Make transltaiton more flaxible
robotframework#139
1 parent 081bc84 commit 877f34b

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

atest/SmallLibrary.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,44 @@ def __init__(self, translation: Optional[Path] = None):
1414
translation = Path(translation)
1515
logger.warn(translation.absolute())
1616
logger.warn(type(translation))
17-
17+
1818
DynamicCore.__init__(self, [], translation.absolute())
1919

2020
@keyword(tags=["tag1", "tag2"])
2121
def normal_keyword(self, arg: int, other: str) -> str:
2222
"""I have doc
23-
23+
2424
Multiple lines.
2525
Other line.
2626
"""
2727
data = f"{arg} {other}"
2828
print(data)
2929
return data
30-
30+
3131
def not_keyword(self, data: str) -> str:
3232
print(data)
3333
return data
34-
34+
3535
@keyword(name="This Is New Name", tags=["tag1", "tag2"])
3636
def name_changed(self, some: int, other: int) -> int:
3737
"""This one too"""
3838
print(f"{some} {type(some)}, {other} {type(other)}")
3939
return some + other
40+
41+
@keyword
42+
def not_translated(seld, a: int) -> int:
43+
"""This is not replaced."""
44+
print(f"{a} {type(a)}")
45+
return a + 1
46+
47+
@keyword
48+
def doc_not_translated(seld, a: int) -> int:
49+
"""This is not replaced also."""
50+
print(f"{a} {type(a)}")
51+
return a + 1
52+
53+
@keyword
54+
def kw_not_translated(seld, a: int) -> int:
55+
"""This is replaced too but name is not."""
56+
print(f"{a} {type(a)}")
57+
return a + 1

atest/translation.json

+7
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
"__intro__": {
1515
"name": "__intro__",
1616
"doc": "New __intro__ documentation is here."
17+
},
18+
"doc_not_translated": {
19+
"name": "this_is_replaced"
20+
}
21+
,
22+
"kw_not_translated": {
23+
"doc": "Here is new doc"
1724
}
1825
}

src/robotlibcore.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def add_library_components(self, library_components: List, translation: Optional
8484

8585
def __get_keyword_name(self, func: Callable, name: str, translation: dict):
8686
if name in translation:
87-
return translation[name]["name"]
87+
if new_name := translation[name].get("name"):
88+
return new_name
8889
return func.robot_name or name
8990

9091
def __replace_intro_doc(self, translation: dict):
@@ -236,7 +237,8 @@ def build(cls, function, translation: Optional[dict] = None):
236237
@classmethod
237238
def get_doc(cls, function, translation: dict):
238239
if kw := cls._get_kw_transtation(function, translation):
239-
return kw["doc"]
240+
if "doc" in kw:
241+
return kw["doc"]
240242
return inspect.getdoc(function) or ""
241243

242244
@classmethod

utest/test_translations.py

+22
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,25 @@ def test_init_and_lib_docs(lib: SmallLibrary):
3434
assert init.documentation == "Replaces init docs with this one."
3535
doc = lib.get_keyword_documentation("__intro__")
3636
assert doc == "New __intro__ documentation is here."
37+
38+
39+
def test_not_translated(lib: SmallLibrary):
40+
keywords = lib.keywords_spec
41+
assert "not_translated" in keywords
42+
doc = lib.get_keyword_documentation("not_translated")
43+
assert doc == "This is not replaced."
44+
45+
46+
def test_doc_not_translated(lib: SmallLibrary):
47+
keywords = lib.keywords_spec
48+
assert "doc_not_translated" not in keywords
49+
assert "this_is_replaced" in keywords
50+
doc = lib.get_keyword_documentation("this_is_replaced")
51+
assert doc == "This is not replaced also."
52+
53+
54+
def test_kw_not_translated_but_doc_is(lib: SmallLibrary):
55+
keywords = lib.keywords_spec
56+
assert "kw_not_translated" in keywords
57+
doc = lib.get_keyword_documentation("kw_not_translated")
58+
assert doc == "Here is new doc"

0 commit comments

Comments
 (0)