From 861e5de25e2e09826ffd4e28bbd05a3030b5a732 Mon Sep 17 00:00:00 2001 From: Andre Rummler Date: Fri, 11 Sep 2026 00:10:55 +0200 Subject: [PATCH] Use qt own enumeration translation function. Fix plural forms. --- sources/qet.cpp | 104 +++++++++++---------- sources/qetapp.cpp | 2 + sources/undocommand/rotatetextscommand.cpp | 4 +- 3 files changed, 58 insertions(+), 52 deletions(-) diff --git a/sources/qet.cpp b/sources/qet.cpp index f253fc114..51a6256ab 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -271,84 +271,88 @@ QString QET::ElementsAndConductorsSentence( int tables_count, int terminal_strip_count) { - QString text; + QStringList parts; if (elements_count) { - text += QObject::tr( - "%n élément(s)", - "part of a sentence listing the content of a diagram", - elements_count + parts.append( + QObject::tr( + "%n élément(s)", + "part of a enumerative partial sentence listing the content of a diagram", + elements_count + ) ); } if (conductors_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n conducteur(s)", - "part of a sentence listing the content of a diagram", - conductors_count + parts.append( + QObject::tr( + "%n conducteur(s)", + "part of a enumerative partial sentence listing the content of a diagram", + conductors_count + ) ); } if (texts_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n champ(s) de texte", - "part of a sentence listing the content of a diagram", - texts_count + parts.append( + QObject::tr( + "%n champ(s) de texte", + "part of a enumerative partial sentence listing the content of a diagram", + texts_count + ) ); } if (images_count) { - if (!text.isEmpty()) text += ", "; - // Qt's %n only selects a grammatical singular/plural form (the - // "(s)" convention used by every other count here) -- it never - // spells the number out as a word, so getting "une image" - // instead of the literal "1 image" for the single-item case - // means handling that count outside %n entirely, with its own - // fixed string. - text += images_count == 1 - ? QObject::tr("une image", "part of a sentence listing the content of a diagram") - : QObject::tr( - "%n images", - "part of a sentence listing the content of a diagram", - images_count - ); + parts.append( + QObject::tr( + "%n images", + "part of a enumerative partial sentence listing the content of a diagram", + images_count + ) + ); } if (shapes_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n forme(s)", - "part of a sentence listing the content of a diagram", - shapes_count + parts.append( + QObject::tr( + "%n forme(s)", + "part of a enumerative partial sentence listing the content of a diagram", + shapes_count + ) ); } if (element_text_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n texte(s) d'élément", - "part of a sentence listing the content of a diagram", - element_text_count); + parts.append( + QObject::tr( + "%n texte(s) d'élément", + "part of a enumerative partial sentence listing the content of a diagram", + element_text_count + ) + ); } if (tables_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n tableau(s)", - "part of a sentence listing the content of diagram", - tables_count); + parts.append( + QObject::tr( + "%n tableau(s)", + "part of a enumerative partial sentence listing the content of diagram", + tables_count + ) + ); } if (terminal_strip_count) { - if (!text.isEmpty()) text += ", "; - text += QObject::tr( - "%n plan de bornes", - "part of a sentence listing the content of a diagram", - terminal_strip_count); + parts.append( + QObject::tr( + "%n plan(s) de bornes", + "part of a enumerative partial sentence listing the content of a diagram", + terminal_strip_count + ) + ); } - return(text); + return QLocale().createSeparatedList(parts); } /** diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index ed31bf0a4..2500b8e0f 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -233,6 +233,8 @@ QString QETApp::loadedQtTranslationFile() */ void QETApp::setLanguage(const QString &desired_language) { QString languages_path = languagesPath(); + + QLocale::setDefault(QLocale(desired_language)); // load Qt library translations QString qt_l10n_path = QLibraryInfo::path(QLibraryInfo::TranslationsPath); diff --git a/sources/undocommand/rotatetextscommand.cpp b/sources/undocommand/rotatetextscommand.cpp index 7239d1b98..fdbe67c65 100644 --- a/sources/undocommand/rotatetextscommand.cpp +++ b/sources/undocommand/rotatetextscommand.cpp @@ -57,7 +57,7 @@ m_diagram(diagram) QString text; if(texts_list.count()) - text.append(QObject::tr("Pivoter %1 textes").arg(texts_list.count())); + text.append(QObject::tr("Pivoter %n texte(s)").arg(texts_list.count())); if(groups_list.count()) { if(text.isEmpty()) @@ -65,7 +65,7 @@ m_diagram(diagram) else text.append(QObject::tr(" et")); - text.append(QObject::tr(" %1 groupes de textes").arg(groups_list.count())); + text.append(QObject::tr(" %n groupe(s) de textes").arg(groups_list.count())); } if(!text.isNull()) setText(text);