Skip to content

Commit

Permalink
feat(i18n): Handle English plural forms in translations
Browse files Browse the repository at this point in the history
Special case that only needs plurals translated.
  • Loading branch information
anthonybilinski committed Feb 24, 2022
1 parent b05c069 commit 0cb222c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 19 deletions.
32 changes: 15 additions & 17 deletions src/widget/translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,23 @@ void Translator::translate(const QString& localeName)
// Load translations
QString locale = localeName.isEmpty() ? QLocale::system().name().section('_', 0, 0) : localeName;

if (locale != "en") {
if (core_translator->load(locale, ":translations/")) {
qDebug() << "Loaded translation" << locale;

// System menu translation
QString s_locale = "qt_" + locale;
QString location = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (app_translator->load(s_locale, location)) {
QApplication::installTranslator(app_translator);
qDebug() << "System translation loaded" << locale;
} else {
qDebug() << "System translation not loaded" << locale;
}

// Application translation
QCoreApplication::installTranslator(core_translator);
if (core_translator->load(locale, ":translations/")) {
qDebug() << "Loaded translation" << locale;

// System menu translation
QString s_locale = "qt_" + locale;
QString location = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (app_translator->load(s_locale, location)) {
QApplication::installTranslator(app_translator);
qDebug() << "System translation loaded" << locale;
} else {
qDebug() << "Error loading translation" << locale;
qDebug() << "System translation not loaded" << locale;
}

// Application translation
QCoreApplication::installTranslator(core_translator);
} else {
qDebug() << "Error loading translation" << locale;
}

// After the language is changed from RTL to LTR, the layout direction isn't
Expand Down
5 changes: 3 additions & 2 deletions tools/update-translation-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

set -eu -o pipefail

readonly LUPDATE_CMD="lupdate src -no-obsolete -locations none -ts"
readonly LUPDATE_CMD="lupdate src -no-obsolete -locations none"

if [[ "$@" = "ALL" ]]
then
for translation in translations/*.ts
do
$LUPDATE_CMD "$translation"
$LUPDATE_CMD -ts "$translation"
done
$LUPDATE_CMD -pluralonly -ts translations/en.ts
else
$LUPDATE_CMD "$@"
fi
1 change: 1 addition & 0 deletions translations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ qt5_add_translation(translations_FILES
da.ts
de.ts
el.ts
en.ts
eo.ts
es.ts
et.ts
Expand Down
1 change: 1 addition & 0 deletions translations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Language | Status
[Deutsch](https://hosted.weblate.org/engage/tox/de/) | [![Translation status](https://hosted.weblate.org/widgets/tox/de/svg-badge.svg)](https://hosted.weblate.org/engage/tox/de/?utm_source=widget)
[Eesti](https://hosted.weblate.org/engage/tox/et/) | [![Translation status](https://hosted.weblate.org/widgets/tox/et/svg-badge.svg)](https://hosted.weblate.org/engage/tox/et/?utm_source=widget)
[Ελληνικά](https://hosted.weblate.org/engage/tox/el/) | [![Translation status](https://hosted.weblate.org/widgets/tox/el/svg-badge.svg)](https://hosted.weblate.org/engage/tox/el/?utm_source=widget)
[English](https://hosted.weblate.org/engage/tox/en/) | [![Translation status](https://hosted.weblate.org/widgets/tox/en/svg-badge.svg)](https://hosted.weblate.org/engage/tox/en/?utm_source=widget)
[Español](https://hosted.weblate.org/engage/tox/es/) | [![Translation status](https://hosted.weblate.org/widgets/tox/es/svg-badge.svg)](https://hosted.weblate.org/engage/tox/es/?utm_source=widget)
[Esperanto](https://hosted.weblate.org/engage/tox/eo/) | [![Translation status](https://hosted.weblate.org/widgets/tox/eo/svg-badge.svg)](https://hosted.weblate.org/engage/tox/eo/?utm_source=widget)
[فارسی](https://hosted.weblate.org/engage/tox/fa/) | [![Translation status](https://hosted.weblate.org/widgets/tox/fa/svg-badge.svg)](https://hosted.weblate.org/engage/tox/fa/?utm_source=widget)
Expand Down
57 changes: 57 additions & 0 deletions translations/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>AddFriendForm</name>
<message numerus="yes">
<source>Ready to import %n contact(s), click send to confirm</source>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>GroupChatForm</name>
<message numerus="yes">
<source>%n user(s) in chat</source>
<comment>Number of users in chat</comment>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>GroupWidget</name>
<message numerus="yes">
<source>%n user(s) in chat</source>
<comment>Number of users in chat</comment>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>NotificationEdgeWidget</name>
<message numerus="yes">
<source>Unread message(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>Widget</name>
<message numerus="yes">
<source>%n new friend request(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%n new group invite(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
</translation>
</message>
</context>
</TS>
1 change: 1 addition & 0 deletions translations/i18n.pri
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TRANSLATIONS = \
translations/da.ts \
translations/de.ts \
translations/el.ts \
translations/en.ts \
translations/eo.ts \
translations/es.ts \
translations/et.ts \
Expand Down
1 change: 1 addition & 0 deletions translations/translations.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>da.qm</file>
<file>de.qm</file>
<file>el.qm</file>
<file>en.qm</file>
<file>eo.qm</file>
<file>es.qm</file>
<file>et.qm</file>
Expand Down

0 comments on commit 0cb222c

Please sign in to comment.