• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dfint / df-gettext-toolkit / 5978636356

25 Aug 2023 05:17PM UTC coverage: 42.967% (-0.1%) from 43.088%
5978636356

push

github

insolor
Add a rule for SINGULAR and PLURAL

170 of 450 branches covered (0.0%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

444 of 979 relevant lines covered (45.35%)

1.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.5
/df_gettext_toolkit/validation/validate_objects.py
1
from df_gettext_toolkit.parse.parse_raws import all_caps, split_tag
3✔
2

3

4
def validate_brackets(tag: str):
3✔
5
    return tag.startswith("[") and tag.endswith("]") and tag.count("[") == 1 and tag.count("]") == 1
×
6

7

8
def validate_tag(original_tag: str, translation_tag: str):
3✔
9
    assert len(translation_tag) > 2, "Too short or empty translation"
×
10
    assert translation_tag.strip() == translation_tag, "Extra spaces at the beginning or at the end of the translation"
×
11
    assert validate_brackets(translation_tag), "Wrong tag translation format"
×
12

13
    original_parts = split_tag(original_tag)
×
14
    translation_parts = split_tag(translation_tag)
×
15
    assert len(original_parts) == len(translation_parts), "Tag parts count mismatch"
×
16
    validate_tag_parts(original_parts, translation_parts)
×
17

18

19
def validate_tag_parts(original_parts: list[str], translation_parts: list[str]):
3✔
20
    for original, translation in zip(original_parts, translation_parts):
×
21
        if all_caps(original) or original.isdecimal():
×
22
            valid = original == translation or original in ("STP", "NP", "SINGULAR", "PLURAL")
×
23
            assert valid, f"Part {original!r} should not be translated"
×
24

25
            if original in {"SINGULAR", "PLURAL"}:
×
26
                assert translation in {"SINGULAR", "PLURAL"}, (
×
27
                    "SINGULAR can be changed only to PLURAL, and PLURAL can be changed only to SINGULAR",
28
                )
29

30
            if original == "STP":
×
31
                # TODO: this should be a warning, not error
32
                # assert translation != "STP", (
33
                #     "Replace STP with a translation of the previous word in the tag in a plural form, "
34
                #     "otherwise, the game will create a plural form with adding -s at the end. "
35
                #     "If the translation with adding -s at the end is valid for your language, "
36
                #     "just ignore this message."
37
                # )
38
                pass
×
39
        elif original:
×
40
            assert translation, "Translation should not be empty"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc