Skip to content

Commit

Permalink
Reworded some documentation on selib tool
Browse files Browse the repository at this point in the history
I reworded some of the documentation from the perspective of one who had not yet used the
tool. Also made some minor changes to spelling.
  • Loading branch information
emanlove committed Jun 9, 2024
1 parent ee5a7de commit 489f103
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
21 changes: 11 additions & 10 deletions src/SeleniumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,16 @@ class SeleniumLibrary(DynamicCore):
= Language =
SeleniumLibrary offers possibility to translte keyword names and documentation to new language. If language
SeleniumLibrary offers the possibility to translate keyword names and documentation to new language. If language
is defined, SeleniumLibrary will search from
[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#module-search-path | module search path]
Python packages starting with `robotframework_seleniumlibrary_translation` by using
[https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/ | Python pluging API]. Library
for Python packages starting with `robotframework-seleniumlibrary-translation` by using the
[https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/ | Python pluging API]. The Library
is using naming convention to find Python plugins.
The package must implement single API call, ``get_language`` without any arguments. Method must return a
The package must implement a single API call, ``get_language`` without any arguments. The method must return a
dictionary containing two keys: ``language`` and ``path``. The language key value defines which language
the package contains. Also value should match (case insentive) the library ``language`` import parameter.
the package contains. Also the value should match (case insensitive) the library ``language`` import parameter.
The path parameter value should be full path to the translation file.
== Translation file ==
Expand All @@ -568,8 +568,8 @@ class SeleniumLibrary(DynamicCore):
format. The keys of json are the methods names, not the keyword names, which implements keywords. Value of
key is json object which contains two keys: ``name`` and ``doc``. The ``name`` key contains the keyword
translated name and `doc` contains translated documentation. Providing doc and name are optional, example
translation json file can only provide translations to keyword names or only to documentatin. But it is
always recomended to provide translation to both name and doc. Special key ``__intro__`` is for class level
translation json file can only provide translations to keyword names or only to documentation. But it is
always recommended to provide translation to both name and doc. Special key ``__intro__`` is for class level
documentation and ``__init__`` is for init level documentation. These special values ``name`` can not be
translated, instead ``name`` should be kept the same.
Expand All @@ -580,9 +580,10 @@ class SeleniumLibrary(DynamicCore):
languages, it only provides easy way to create full list keywords and their documentation in correct
format. It is also possible to add keywords from library plugins by providing `--plugings` arguments
to command. Example: `rfselib translation --plugings myplugin.SomePlugin /path/to/translation.json` The
genered json file contains `sha256` key, which constains the sha256 sum of the library documentation,
the sha256 sum is used by `rfselib translation --compare /path/to/translation.json` command, which compares
transation to to library and prints outs a table which tell if there are changes needed for translation file.
generated json file contains `sha256` key, which contains the sha256 sum of the library documentation.
The sha256 sum is used by `rfselib translation --compare /path/to/translation.json` command, which compares
the translation to the library and prints outs a table which tells if there are changes needed for
translation file.
Example project for translation can be found from
[https://github.com/MarketSquare/robotframework-seleniumlibrary-translation-fi | robotframework-seleniumlibrary-translation-fi]
Expand Down
32 changes: 16 additions & 16 deletions src/SeleniumLibrary/entry/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from pathlib import Path
from typing import Optional
import click

from .get_versions import get_version
from .translation import compare_translatoin, get_library_translaton
from .translation import compare_translation, get_library_translation


CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
Expand All @@ -32,10 +33,9 @@ def cli():
"""Robot Framework SeleniumLibrary command line tool.
Possible commands are:
translation
translation will generate detaul tranlsation json file from library keywords.
translation
will generate template translation json file from library keywords.
See each command argument help for more details what (optional) arguments that command supports.
"""
Expand All @@ -49,7 +49,7 @@ def cli():
required=True,
)
@click.option(
"--plugings",
"--plugin",
help="Same as plugins argument in the library import.",
default=None,
type=str,
Expand All @@ -63,31 +63,31 @@ def cli():
)
def translation(
filename: Path,
plugings: Optional[str] = None,
plugins: Optional[str] = None,
compare: bool = False,
):
"""Default translation file from library keywords.
This will help users to create their own translation as Python plugins. Command
will populate json file with english language. To create proper translation
will populate json file with English language. To create proper translation
file, users needs to translate the keyword name and doc arguments values in
json file.
The filename argument will tell where the default json file is saved.
The --pluging argument is same as plugins argument in the library import.
If you use plugins, it is also get default translation json file also witht
the plugin keyword included in the library.
The --plugin argument will add plugin keywords in addition to the library keywords
into the default translation json file. It is used the same as plugins argument in
the library import.
If the --compare flag is set, then command does not generate template
translation file. Then it compares sha256 sums from the filenane
to ones read from the library documenentation. It will print out a list
of keywords which documentation sha256 does not match. This will ease
translation projects to identify keywords which documentation needs updating.
translation file. Instead it compares sha256 sums from the filename
to the one read from the library documentation. It will print out a list
of keywords for which the documentation sha256 does not match. This will ease
translating projects to identify keywords which needs updating.
"""
translation = get_library_translaton(plugings)
lib_translation = get_library_translation(plugins)
if compare:
if table := compare_translatoin(filename, translation):
if table := compare_translation(filename, lib_translation):
print(
"Found differences between translation and library, see below for details."
)
Expand Down
28 changes: 14 additions & 14 deletions src/SeleniumLibrary/entry/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
DOC_CHANGED = "Documentation update needed"
NO_LIB_KEYWORD = "Keyword not found from library"
MISSING_TRANSLATION = "Keyword is missing translation"
MISSING_CHECKSUM = "Keyword tranlsaton is missing checksum"
MISSING_CHECKSUM = "Keyword translation is missing checksum"
MAX_REASON_LEN = max(
len(DOC_CHANGED),
len(NO_LIB_KEYWORD),
Expand All @@ -33,10 +33,10 @@
)


def get_library_translaton(plugings: Optional[str] = None) -> dict:
def get_library_translation(plugins: Optional[str] = None) -> dict:
from SeleniumLibrary import SeleniumLibrary

selib = SeleniumLibrary(plugins=plugings)
selib = SeleniumLibrary(plugins=plugins)
translation = {}
for function in selib.attributes.values():
translation[function.__name__] = {
Expand All @@ -57,18 +57,18 @@ def get_library_translaton(plugings: Optional[str] = None) -> dict:
return translation


def _max_kw_name_lenght(project_tanslation: dict) -> int:
def _max_kw_name_length(project_translation: dict) -> int:
max_lenght = 0
for keyword_data in project_tanslation.values():
for keyword_data in project_translation.values():
if (current_kw_length := len(keyword_data["name"])) > max_lenght:
max_lenght = current_kw_length
return max_lenght


def _get_heading(max_kw_lenght: int) -> List[str]:
def _get_heading(max_kw_length: int) -> List[str]:
heading = f"| {KEYWORD_NAME} "
next_line = f"| {'-' * len(KEYWORD_NAME)}"
if (padding := max_kw_lenght - len(KEYWORD_NAME)) > 0:
if (padding := max_kw_length - len(KEYWORD_NAME)) > 0:
heading = f"{heading}{' ' * padding}"
next_line = f"{next_line}{'-' * padding}"
reason = "Reason"
Expand All @@ -89,34 +89,34 @@ def _table_doc_updated(lib_kw: str, max_name_lenght: int, reason: str) -> str:
return f"{line}|"


def compare_translatoin(filename: Path, library_translation: dict):
def compare_translation(filename: Path, library_translation: dict):
with filename.open("r") as file:
project_translation = json.load(file)
max_kw_lenght = _max_kw_name_lenght(library_translation)
max_kw_length = _max_kw_name_length(library_translation)
table_body = []
for lib_kw, lib_kw_data in library_translation.items():
project_kw_data = project_translation.get(lib_kw)
if not project_kw_data:
table_body.append(
_table_doc_updated(lib_kw, max_kw_lenght, MISSING_TRANSLATION)
_table_doc_updated(lib_kw, max_kw_length, MISSING_TRANSLATION)
)
continue
sha256_value = project_kw_data.get("sha256")
if not sha256_value:
table_body.append(
_table_doc_updated(lib_kw, max_kw_lenght, MISSING_CHECKSUM)
_table_doc_updated(lib_kw, max_kw_length, MISSING_CHECKSUM)
)
continue
if project_kw_data["sha256"] != lib_kw_data["sha256"]:
table_body.append(_table_doc_updated(lib_kw, max_kw_lenght, DOC_CHANGED))
table_body.append(_table_doc_updated(lib_kw, max_kw_length, DOC_CHANGED))
for project_kw in project_translation:
if project_kw not in library_translation:
table_body.append(
_table_doc_updated(project_kw, max_kw_lenght, NO_LIB_KEYWORD)
_table_doc_updated(project_kw, max_kw_length, NO_LIB_KEYWORD)
)
if not table_body:
return []

table = _get_heading(max_kw_lenght)
table = _get_heading(max_kw_length)
table.extend(table_body)
return table
14 changes: 7 additions & 7 deletions utest/test/entry/test_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from SeleniumLibrary.entry.get_versions import get_version
from SeleniumLibrary.entry.translation import (
compare_translatoin,
get_library_translaton,
compare_translation,
get_library_translation,
)


Expand All @@ -25,7 +25,7 @@ def test_version():


def test_get_translation():
data = get_library_translaton()
data = get_library_translation()
for item in data.values():
assert item["name"], item["name"]
assert item["doc"], item["doc"]
Expand All @@ -34,19 +34,19 @@ def test_get_translation():

def test_compare_translation(tmp_path: Path):
translation = tmp_path / "translation.json"
data = get_library_translaton()
data = get_library_translation()
with translation.open("w") as file:
json.dump(data, file, indent=4)
table = compare_translatoin(translation, data)
table = compare_translation(translation, data)
verify_all("No changes", table)


def test_compare_translation_changes(tmp_path: Path):
translation = tmp_path / "translation.json"
data = get_library_translaton()
data = get_library_translation()
data.pop("handle_alert", None)
data["alert_should_be_present"]["sha256"] = "foo"
with translation.open("w") as file:
json.dump(data, file, indent=4)
table = compare_translatoin(translation, get_library_translaton())
table = compare_translation(translation, get_library_translation())
verify_all("Changes", table)

0 comments on commit 489f103

Please sign in to comment.