added path search system for translations

This commit is contained in:
itsmattkc
2019-02-04 17:31:35 +11:00
parent 46e87f8f2d
commit a9d2b67069
4 changed files with 32 additions and 10 deletions
+17 -10
View File
@@ -384,17 +384,24 @@ void PreferencesDialog::setup_ui() {
language_combobox->addItem(QLocale::languageToString(QLocale("en-US").language()));
// add languages from file
QDir translation_dir(QApplication::applicationDirPath().append("/ts"));
QStringList translation_files = translation_dir.entryList({"*.qm"}, QDir::Files | QDir::NoDotAndDotDot);
for (int i=0;i<translation_files.size();i++) {
QString locale_full_path = translation_dir.filePath(translation_files.at(i));
QFileInfo locale_file(translation_files.at(i));
QString locale_file_basename = locale_file.baseName();
QString locale_str = locale_file_basename.mid(locale_file_basename.lastIndexOf('_')+1);
language_combobox->addItem(QLocale(locale_str).nativeLanguageName(), locale_full_path);
QList<QString> translation_paths = get_language_paths();
if (config.language_file == locale_full_path) {
language_combobox->setCurrentIndex(language_combobox->count() - 1);
// iterate through all language search paths
for (int j=0;j<translation_paths.size();j++) {
QDir translation_dir(translation_paths.at(j));
if (translation_dir.exists()) {
QStringList translation_files = translation_dir.entryList({"*.qm"}, QDir::Files | QDir::NoDotAndDotDot);
for (int i=0;i<translation_files.size();i++) {
QString locale_full_path = translation_dir.filePath(translation_files.at(i));
QFileInfo locale_file(translation_files.at(i));
QString locale_file_basename = locale_file.baseName();
QString locale_str = locale_file_basename.mid(locale_file_basename.lastIndexOf('_')+1);
language_combobox->addItem(QLocale(locale_str).nativeLanguageName(), locale_full_path);
if (config.language_file == locale_full_path) {
language_combobox->setCurrentIndex(language_combobox->count() - 1);
}
}
}
}