Skip to content

Commit 342c88a

Browse files
committed
Rework translation file naming
For most cases translation files just need the language and not the country/territory as well. This better aligns to Qt and other Qt-based applications.
1 parent e5d21c4 commit 342c88a

File tree

10 files changed

+21
-15
lines changed

10 files changed

+21
-15
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="cs_CZ">
3+
<TS version="2.1" language="cs">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="es_NI">
3+
<TS version="2.1" language="es">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="pl_PL">
3+
<TS version="2.1" language="pl">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="ru_RU">
3+
<TS version="2.1" language="ru">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="sv_SE">
3+
<TS version="2.1" language="sv">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="tr_TR">
3+
<TS version="2.1" language="tr">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE TS>
3-
<TS version="2.1" language="uk_UA">
3+
<TS version="2.1" language="uk">
44
<context>
55
<name>AuthenticateDialog</name>
66
<message>

src/NotepadNext/TranslationManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ QString TranslationManager::FormatLocaleTerritoryAndLanguage(QLocale &locale)
6262
const QString territory = QLocale::territoryToString(locale.territory());
6363
#endif
6464
const QString language = QLocale::languageToString(locale.language());
65-
return QStringLiteral("%1 / %2").arg(language, territory);
65+
return QStringLiteral("%1 (%2)").arg(language, territory);
6666
}
6767

6868
void TranslationManager::loadSystemDefaultTranslation()

src/NotepadNext/dialogs/PreferencesDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ void PreferencesDialog::populateTranslationComboBox()
136136
NotepadNextApplication *app = qobject_cast<NotepadNextApplication *>(qApp);
137137

138138
// Add the system default at the top
139-
ui->comboBoxTranslation->addItem(QStringLiteral("%1 (%2)").arg(tr("<System Default>"), QLocale::system().name()), QStringLiteral(""));
139+
ui->comboBoxTranslation->addItem(tr("<System Default>"), QStringLiteral(""));
140140

141141
// TODO: sort this list and keep the system default at the top
142142
for (const auto &localeName : app->getTranslationManager()->availableTranslations())
143143
{
144144
QLocale locale(localeName);
145145
const QString localeDisplay = TranslationManager::FormatLocaleTerritoryAndLanguage(locale);
146-
ui->comboBoxTranslation->addItem(QStringLiteral("%1 (%2)").arg(localeDisplay, localeName), localeName);
146+
ui->comboBoxTranslation->addItem(localeDisplay, localeName);
147147
}
148148

149149
// Select the current one

src/i18n.pri

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ for(TS_FILE, TS_FILES) {
2323
# Add the application translation file
2424
TRANSLATIONS += $$TS_FILE
2525

26+
FILE_NAME = $$basename(TS_FILE)
27+
2628
# Extract the locale from the file name (e.g. NotepadNext_pl_PL.ts to pl_PL)
27-
LOCALE = $$str_member($$TS_FILE, -8, -4)
29+
LOCALE = $$replace(FILE_NAME, "NotepadNext_(..)(\\_..)?\\.ts", "\\1\\2")
2830

29-
# Extra translation files that include both the language and translation
31+
# Extra Qt translation files
3032
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qt_$${LOCALE}.qm)
3133
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qtbase_$${LOCALE}.qm)
3234

3335
# Check for files without the territory specified (e.g. pl)
34-
LANGUAGE = $$replace(LOCALE, "(..).*", "\\1")
35-
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qt_$${LANGUAGE}.qm)
36-
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qtbase_$${LANGUAGE}.qm)
36+
greaterThan($$str_size(LOCALE), 2) {
37+
LANGUAGE = $$replace(LOCALE, "(..).*", "\\1")
38+
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qt_$${LANGUAGE}.qm)
39+
EXTRA_TRANSLATIONS += $$files($$[QT_INSTALL_TRANSLATIONS]/qtbase_$${LANGUAGE}.qm)
40+
}
3741
}
42+
43+
message("EXTRA_TRANSLATIONS: $$EXTRA_TRANSLATIONS")

0 commit comments

Comments
 (0)