Skip to content
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
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Weblate 5.16

.. rubric:: New features

* :ref:`check-multiple-capital` quality check.

.. rubric:: Improvements

* Delete announcements permission can be assigned to teams, see :ref:`privileges`.
Expand Down
19 changes: 19 additions & 0 deletions docs/user/checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
.. seealso::

* :ref:`check-formats`
* `Laravel translation formatting <https://laravel.com/docs/localization#replacing-parameters-in-translation-strings>`_

Check warning on line 745 in docs/user/checks.rst

View workflow job for this annotation

GitHub Actions / Linkcheck

https://laravel.com/docs/localization#replacing-parameters-in-translation-strings to https://laravel.com/docs/12.x/localization

.. _check-lua-format:

Expand Down Expand Up @@ -1476,6 +1476,25 @@
Failing to fill in plural forms will in some cases lead to displaying nothing when
the plural form is in use.

.. _check-multiple-capital:

Multiple capitals
~~~~~~~~~~~~~~~~~

.. versionadded:: 5.16

:Summary: Translation contains words with multiple misplaced capital letters.
:Scope: translated strings
:Check class: ``weblate.checks.chars.MultipleCapitalCheck``
:Check identifier: ``multiple_capital``
:Trigger: This check is always enabled but can be ignored using a flag.
:Flag to ignore: ``ignore-multiple-capital``

Checks for misplaced capitalization by detecting words that contain consecutive
uppercase letters in otherwise lowercase or normally capitalized text (for
example, ``HEllo`` or ``CAmelCase``). Strings that contain capitalization in the
source string are allowed to contain capitalization in the translation.

.. _check-kabyle-characters:

Non‑standard characters in Kabyle
Expand Down
21 changes: 21 additions & 0 deletions weblate/checks/chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import unicodedata
from typing import TYPE_CHECKING, ClassVar

import regex
from django.utils.translation import gettext_lazy

from weblate.checks.base import CountingCheck, TargetCheck, TargetCheckParametrized
Expand Down Expand Up @@ -579,3 +580,23 @@ def get_fixup(self, unit: Unit) -> Iterable[FixupType] | None:
"gu",
),
]


class MultipleCapitalCheck(TargetCheck):
"""Multiple capitals check."""

check_id = "multiple_capital"
name = gettext_lazy("Multiple capitals")
description = gettext_lazy(
"Translation contains words with multiple misplaced capital letters."
)

# matches sequences of 2+ uppercase letters in *any language*
UPPERCASE_SEQ = regex.compile(r"\p{Lu}{2,}")

def check_single(self, source: str, target: str, unit: Unit) -> bool:
# Flag if any uppercase sequence is present in target and not present in the source
return (
self.UPPERCASE_SEQ.search(target) is not None
and not self.UPPERCASE_SEQ.search(source) is not None
)
1 change: 1 addition & 0 deletions weblate/checks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class WeblateChecksConf(AppConf):
"weblate.checks.chars.EndEllipsisCheck",
"weblate.checks.chars.EndSemicolonCheck",
"weblate.checks.chars.MaxLengthCheck",
"weblate.checks.chars.MultipleCapitalCheck",
"weblate.checks.chars.KashidaCheck",
"weblate.checks.chars.PunctuationSpacingCheck",
"weblate.checks.chars.KabyleCharactersCheck",
Expand Down
32 changes: 32 additions & 0 deletions weblate/checks/tests/test_chars_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
KabyleCharactersCheck,
KashidaCheck,
MaxLengthCheck,
MultipleCapitalCheck,
NewLineCountCheck,
PunctuationSpacingCheck,
ZeroWidthSpaceCheck,
Expand Down Expand Up @@ -300,7 +301,7 @@

def setUp(self) -> None:
super().setUp()
self.test_single_good_matching = ("string\n\nstring", "string\n\nstring", "")

Check failure on line 304 in weblate/checks/tests/test_chars_checks.py

View workflow job for this annotation

GitHub Actions / mypy

Incompatible types in assignment (expression has type "tuple[str, str, str]", variable has type "Callable[[], None]")

Check failure on line 304 in weblate/checks/tests/test_chars_checks.py

View workflow job for this annotation

GitHub Actions / mypy

Cannot assign to a method
self.test_failure_1 = ("string\nstring", "string\n\n\nstring", "")
self.test_failure_2 = ("string\nstring\n\nstring", "string\nstring\nstring", "")

Expand Down Expand Up @@ -512,3 +513,34 @@
),
"el",
)


class MultipleCapitalCheckTest(CheckTestCase):
check = MultipleCapitalCheck()

def setUp(self) -> None:
super().setUp()
self.test_good_matching = ("Hello", "Hello", "")
self.test_failure_1 = ("Hello", "HEllo", "")
self.test_failure_2 = ("camel case", "CAmelCase", "")
self.test_failure_3 = ("sigma", "ΣIGMA", "")

def test_acronyms(self) -> None:
self.do_test(
False,
(
"Welcome NATO",
"Bonjour OTAN",
"",
),
"fr",
)
self.do_test(
False,
(
"Welcome NATO",
"Vítej NATO",
"",
),
"cs",
)
1 change: 1 addition & 0 deletions weblate/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@
"weblate.checks.chars.EndEllipsisCheck",
"weblate.checks.chars.EndSemicolonCheck",
"weblate.checks.chars.MaxLengthCheck",
"weblate.checks.chars.MultipleCapitalCheck",
"weblate.checks.chars.KashidaCheck",
"weblate.checks.chars.PunctuationSpacingCheck",
"weblate.checks.chars.KabyleCharactersCheck",
Expand Down
1 change: 1 addition & 0 deletions weblate/settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@
# "weblate.checks.chars.EndEllipsisCheck",
# "weblate.checks.chars.EndSemicolonCheck",
# "weblate.checks.chars.MaxLengthCheck",
# "weblate.checks.chars.MultipleCapitalCheck",
# "weblate.checks.chars.KashidaCheck",
# "weblate.checks.chars.PunctuationSpacingCheck",
# "weblate.checks.chars.KabyleCharactersCheck",
Expand Down
Loading