Skip to content

Commit

Permalink
Require new translations to have "New in" note.
Browse files Browse the repository at this point in the history
Also add it to Vietnamese added in RF 6.1 (#4792).
  • Loading branch information
pekkaklarck committed Jun 11, 2023
1 parent 2ca377f commit a11ff03
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/userguide/src/Appendices/Translations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,8 @@ Boolean strings
Vietnamese (vi)
---------------

New in Robot Framework 6.1.

Section headers
~~~~~~~~~~~~~~~

Expand Down
10 changes: 8 additions & 2 deletions doc/userguide/translations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import re
import sys
from pathlib import Path


CURDIR = Path(__file__).absolute().parent
Expand All @@ -21,6 +22,11 @@ def __getattr__(self, name):
value = getattr(self.lang, name)
return value if value is not None else ''

@property
def new_in(self):
new_in = re.search(r'(New in Robot Framework [\d.]+\.)', self.lang.__doc__)
return ('\n' + new_in.group(1) + '\n') if new_in else ''

@property
def underline(self):
width = len(self.lang.name + self.lang.code) + 3
Expand Down Expand Up @@ -58,7 +64,7 @@ def false_strings(self):
TEMPLATE = '''
{lang.name} ({lang.code})
{lang.underline}
{lang.new_in}
Section headers
~~~~~~~~~~~~~~~
Expand Down
7 changes: 5 additions & 2 deletions src/robot/conf/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,12 @@ class Hi(Language):
true_strings = ['यथार्थ', 'निश्चित', 'हां', 'पर']
false_strings = ['गलत', 'नहीं', 'हालाँकि', 'यद्यपि', 'नहीं', 'हैं']


class Vi(Language):
"""Vietnamese"""
"""Vietnamese
New in Robot Framework 6.1.
"""
settings_header = 'Cài Đặt'
variables_header = 'Các biến số'
test_cases_header = 'Các kịch bản kiểm thử'
Expand Down
29 changes: 26 additions & 3 deletions utest/api/test_languages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import unittest

import re
from pathlib import Path

from robot.api import Language, Languages
Expand All @@ -9,6 +10,9 @@
assert_raises_with_msg)


STANDARD_LANGUAGES = Language.__subclasses__()


class TestLanguage(unittest.TestCase):

def test_one_part_code(self):
Expand Down Expand Up @@ -41,13 +45,32 @@ class X(Language):
assert_equal(X().name, '')
assert_equal(X.name, '')

def test_all_standard_languages_have_code_and_name(self):
for cls in Language.__subclasses__():
def test_standard_languages_have_code_and_name(self):
for cls in STANDARD_LANGUAGES:
assert cls().code
assert cls.code
assert cls().name
assert cls.name

def test_standard_language_doc_formatting(self):
added_in_rf60 = {'bg', 'bs', 'cs', 'de', 'en', 'es', 'fi', 'fr', 'hi',
'it', 'nl', 'pl', 'pt', 'pt-BR', 'ro', 'ru', 'sv',
'th', 'tr', 'uk', 'zh-CN', 'zh-TW'}
for cls in STANDARD_LANGUAGES:
doc = inspect.getdoc(cls)
if cls.code in added_in_rf60:
if doc != cls.name:
raise AssertionError(
f'Invalid docstring for {cls.name}. '
f'Expected only language name, got:\n{doc}'
)
else:
if not re.match(rf'{cls.name}\n\nNew in Robot Framework [\d.]+\.', doc):
raise AssertionError(
f'Invalid docstring for {cls.name}. '
f'Expected language name and "New in" note, got:\n{doc}'
)

def test_code_and_name_of_Language_base_class_are_propertys(self):
assert isinstance(Language.code, property)
assert isinstance(Language.name, property)
Expand Down

0 comments on commit a11ff03

Please sign in to comment.