Philipp Hörist pushed to branch master at gajim / gajim
Commits:
555da2d8 by Philipp Hörist at 2024-10-01T19:43:38+02:00
fix: Translations: Use standard ngettext method
Our custom wrapper creates problems with languages which allow to
remove the formating chars (e.g. %s)
Fixes #11997
- - - - -
4 changed files:
- gajim/common/i18n.py
- gajim/common/util/user_strings.py
- gajim/gtk/roster_item_exchange.py
- test/common/test_get_uf_relative_time.py
Changes:
=====================================
gajim/common/i18n.py
=====================================
@@ -58,25 +58,8 @@ def is_rtl_text(text: str) -> bool:
return False
-def ngettext(s_sing: str,
- s_plural: str,
- n: int,
- replace_sing: str | None = None,
- replace_plural: str | None = None) -> str:
- '''
- Use as:
- i18n.ngettext(
- 'leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c')
-
- In other words this is a hack to ngettext() to support %s %d etc..
- '''
- text = _trans.translation.ngettext(s_sing, s_plural, n)
- if n == 1 and replace_sing is not None:
- return text % replace_sing
-
- if n > 1 and replace_plural is not None:
- return text % replace_plural
- return text
+def ngettext(s_sing: str, s_plural: str, n: int) -> str:
+ return _trans.translation.ngettext(s_sing, s_plural, n)
class Translation:
=====================================
gajim/common/util/user_strings.py
=====================================
@@ -135,9 +135,8 @@ def get_uf_relative_time(date_time: dt.datetime, now:
dt.datetime | None = None)
return _('Just now')
if timespan < dt.timedelta(minutes=15):
minutes = int(timespan.seconds / 60)
- return ngettext(
- '%s min ago', '%s mins ago', minutes, str(minutes), str(minutes)
- )
+ return ngettext('%s min ago', '%s mins ago', minutes)
+
today = now.date()
if date_time.date() == today:
format_string = app.settings.get('time_format')
=====================================
gajim/gtk/roster_item_exchange.py
=====================================
@@ -217,9 +217,7 @@ def _on_accept_button_clicked(self, _button: Gtk.Button) ->
None:
iter_ = model.iter_next(iter_)
InformationDialog(i18n.ngettext('Added %s contact',
'Added %s contacts',
- count,
- str(count),
- str(count)))
+ count))
elif self._action == 'modify':
count = 0
while iter_:
@@ -247,9 +245,7 @@ def _on_accept_button_clicked(self, _button: Gtk.Button) ->
None:
iter_ = model.iter_next(iter_)
InformationDialog(i18n.ngettext('Removed %s contact',
'Removed %s contacts',
- count,
- str(count),
- str(count)))
+ count))
self.destroy()
def _on_cancel_button_clicked(self, _button: Gtk.Button) -> None:
=====================================
test/common/test_get_uf_relative_time.py
=====================================
@@ -32,9 +32,7 @@ def test_sub_15_minutes(self):
ngettext(
'%s min ago',
'%s mins ago',
- 3,
- str(3),
- str(3)))
+ 3))
def test_sub_15_minutes_next_day(self):
'''Test timedelta less than 15 minutes and it is the next day'''
@@ -45,9 +43,7 @@ def test_sub_15_minutes_next_day(self):
ngettext(
'%s min ago',
'%s mins ago',
- 10,
- str(10),
- str(10)))
+ 10))
def test_today(self):
'''Test today: same day and more than 15 minutes ago'''
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/555da2d88cb76cd12822cc11312e32def82d7226
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/555da2d88cb76cd12822cc11312e32def82d7226
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]