Skip to content

Commit

Permalink
translate: Show plural form examples more prominently
Browse files Browse the repository at this point in the history
Instead of the tooltip, the text is rendered in the page now.

Fixes WeblateOrg#9675
  • Loading branch information
nijel committed Oct 10, 2023
1 parent 5adcb5f commit 3b583fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Not yet released.
* Enage page better shows stats.
* Strings which can not be saved to a file no longer block other strings to be written.
* Fixed some API URLs for categorized components.
* Show plural form examples more prominently.

**Bug fixes**

Expand Down
13 changes: 6 additions & 7 deletions weblate/lang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
from weblate.trans.defines import LANGUAGE_CODE_LENGTH, LANGUAGE_NAME_LENGTH
from weblate.trans.mixins import CacheKeyMixin
from weblate.trans.util import sort_objects, sort_unicode
from weblate.utils.templatetags.icons import icon
from weblate.utils.validators import validate_plural_formula

PLURAL_RE = re.compile(
r"\s*nplurals\s*=\s*([0-9]+)\s*;\s*plural\s*=\s*([()n0-9!=|&<>+*/%\s?:-]+)"
)
PLURAL_TITLE = """
{name} <span title="{examples}">{icon}</span>
{name} <span class="text-muted" title="{title}">({examples})</span>
"""
COPY_RE = re.compile(r"\([0-9]+\)")
KNOWN_SUFFIXES = {"hant", "hans", "latn", "cyrl", "shaw"}
Expand Down Expand Up @@ -830,6 +829,9 @@ def examples(self):
if len(result[ret]) >= 10:
continue
result[ret].append(str(i))
for example in result.values():
if len(example) >= 10:
example.append("…")
return result

@staticmethod
Expand Down Expand Up @@ -873,11 +875,8 @@ def get_plural_label(self, idx):
return format_html(
PLURAL_TITLE,
name=self.get_plural_name(idx),
icon=icon("info.svg"),
# Translators: Label for plurals with example counts
examples=gettext("For example: {0}").format(
", ".join(self.examples.get(idx, []))
),
examples=", ".join(self.examples.get(idx, [])),
title=gettext("Example counts for this plural form."),
)

def get_plural_name(self, idx):
Expand Down
2 changes: 1 addition & 1 deletion weblate/lang/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def test_examples(self):
plural = Plural(number=2, formula="n!=1")
self.assertEqual(
plural.examples,
{0: ["1"], 1: ["0", "2", "3", "4", "5", "6", "7", "8", "9", "10"]},
{0: ["1"], 1: ["0", "2", "3", "4", "5", "6", "7", "8", "9", "10", "…"]},
)

def test_plurals(self):
Expand Down
4 changes: 4 additions & 0 deletions weblate/static/style-bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ form + .login-label {
.history-data .text-muted {
font-size: 14px;
}

.history-data {
padding-bottom: 4px;
}
Expand Down Expand Up @@ -1936,3 +1937,6 @@ h5.list-group-item-heading {
#show-linked-repo-toggle:not(:checked) ~ .repo-linked {
display: none;
}
label .text-muted {
font-weight: normal;
}

0 comments on commit 3b583fa

Please sign in to comment.