Skip to content

Commit 85b6f0d

Browse files
committed
Update getting language identifier from filename
The resources generated by embed_translations include the .qm from the filename in the resource name, so it is necessary to remove it. Also, the prefix generated by qmake is /i18n, not /translations.
1 parent 1b40e4f commit 85b6f0d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,11 @@ QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country e
16021602
QMap<QString, QString> CLocale::GetAvailableTranslations()
16031603
{
16041604
QMap<QString, QString> TranslMap;
1605-
QDirIterator DirIter ( ":/translations" );
1605+
1606+
// Since we use "embed_translations" in Jamulus.pro, this resource prefix must
1607+
// match the default prefix used by qmake when generating the resource file.
1608+
// That prefix is "i18n" (standard abbreviation for internationalisation).
1609+
QDirIterator DirIter ( ":/i18n" );
16061610

16071611
// add english language (default which is in the actual source code)
16081612
TranslMap["en"] = ""; // empty file name means that the translation load fails and we get the default english language
@@ -1612,8 +1616,9 @@ QMap<QString, QString> CLocale::GetAvailableTranslations()
16121616
// get alias of translation file
16131617
const QString strCurFileName = DirIter.next();
16141618

1615-
// extract only language code (must be at the end, separated with a "_")
1616-
const QString strLoc = strCurFileName.right ( strCurFileName.length() - strCurFileName.indexOf ( "_" ) - 1 );
1619+
// extract only language code "xx_XX" from "translation_xx_XX.qm"
1620+
const int lang = strCurFileName.indexOf ( "_" ) + 1;
1621+
const QString strLoc = strCurFileName.mid ( lang, strCurFileName.indexOf ( "." ) - lang );
16171622

16181623
TranslMap[strLoc] = strCurFileName;
16191624
}

0 commit comments

Comments
 (0)