|
31 | 31 | #include <QStyle>
|
32 | 32 | #include <QStyleFactory>
|
33 | 33 | #include <QDesktopWidget>
|
34 |
| -#include <QTranslator> |
35 | 34 | #include <QImageReader>
|
36 | 35 | #include <QMessageBox>
|
37 | 36 |
|
@@ -538,7 +537,7 @@ int main( int argc, char *argv[] )
|
538 | 537 |
|
539 | 538 | // This behavior will allow you to force the use of a translation file
|
540 | 539 | // which is useful for testing
|
541 |
| - QString myTranslationCode; |
| 540 | + QString translationCode; |
542 | 541 |
|
543 | 542 | // The user can specify a path which will override the default path of custom
|
544 | 543 | // user settings (~/.qgis) and it will be used for QgsSettings INI file
|
@@ -622,7 +621,7 @@ int main( int argc, char *argv[] )
|
622 | 621 | }
|
623 | 622 | else if ( i + 1 < argc && ( arg == QLatin1String( "--lang" ) || arg == QLatin1String( "-l" ) ) )
|
624 | 623 | {
|
625 |
| - myTranslationCode = args[++i]; |
| 624 | + translationCode = args[++i]; |
626 | 625 | }
|
627 | 626 | else if ( i + 1 < argc && ( arg == QLatin1String( "--project" ) || arg == QLatin1String( "-p" ) ) )
|
628 | 627 | {
|
@@ -815,6 +814,71 @@ int main( int argc, char *argv[] )
|
815 | 814 | QCoreApplication::setAttribute( Qt::AA_DisableWindowContextHelpButton, true );
|
816 | 815 | #endif
|
817 | 816 |
|
| 817 | + /* Translation file for QGIS. |
| 818 | + */ |
| 819 | + QString i18nPath = QgsApplication::i18nPath(); |
| 820 | + QgsSettings mySettings; |
| 821 | + QString myUserTranslation = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString(); |
| 822 | + QString myGlobalLocale = mySettings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString(); |
| 823 | + bool myShowGroupSeparatorFlag = false; // Default to false |
| 824 | + bool myLocaleOverrideFlag = mySettings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); |
| 825 | + |
| 826 | + // Override Show Group Separator if the global override flag is set |
| 827 | + if ( myLocaleOverrideFlag ) |
| 828 | + { |
| 829 | + // Default to false again |
| 830 | + myShowGroupSeparatorFlag = mySettings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); |
| 831 | + } |
| 832 | + |
| 833 | + // |
| 834 | + // Priority of translation is: |
| 835 | + // - command line |
| 836 | + // - user specified in options dialog (with group checked on) |
| 837 | + // - system locale |
| 838 | + // |
| 839 | + // When specifying from the command line it will change the user |
| 840 | + // specified user locale |
| 841 | + // |
| 842 | + if ( !translationCode.isNull() && !translationCode.isEmpty() ) |
| 843 | + { |
| 844 | + mySettings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); |
| 845 | + } |
| 846 | + else |
| 847 | + { |
| 848 | + if ( !myLocaleOverrideFlag || myUserTranslation.isEmpty() ) |
| 849 | + { |
| 850 | + translationCode = QLocale().name(); |
| 851 | + //setting the locale/userLocale when the --lang= option is not set will allow third party |
| 852 | + //plugins to always use the same locale as the QGIS, otherwise they can be out of sync |
| 853 | + mySettings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); |
| 854 | + } |
| 855 | + else |
| 856 | + { |
| 857 | + translationCode = myUserTranslation; |
| 858 | + } |
| 859 | + } |
| 860 | + |
| 861 | + // Global locale settings |
| 862 | + if ( myLocaleOverrideFlag && ! myGlobalLocale.isEmpty( ) ) |
| 863 | + { |
| 864 | + QLocale currentLocale( myGlobalLocale ); |
| 865 | + QLocale::setDefault( currentLocale ); |
| 866 | + } |
| 867 | + |
| 868 | + // Number settings |
| 869 | + QLocale currentLocale; |
| 870 | + if ( myShowGroupSeparatorFlag ) |
| 871 | + { |
| 872 | + currentLocale.setNumberOptions( currentLocale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator ); |
| 873 | + } |
| 874 | + else |
| 875 | + { |
| 876 | + currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator ); |
| 877 | + } |
| 878 | + QLocale::setDefault( currentLocale ); |
| 879 | + |
| 880 | + QgsApplication::setTranslation( translationCode ); |
| 881 | + |
818 | 882 | QgsApplication myApp( argc, argv, myUseGuiFlag );
|
819 | 883 |
|
820 | 884 | // SetUp the QgsSettings Global Settings:
|
@@ -1057,9 +1121,6 @@ int main( int argc, char *argv[] )
|
1057 | 1121 | }
|
1058 | 1122 | #endif
|
1059 | 1123 |
|
1060 |
| - |
1061 |
| - QgsSettings mySettings; |
1062 |
| - |
1063 | 1124 | // update any saved setting for older themes to new default 'gis' theme (2013-04-15)
|
1064 | 1125 | if ( mySettings.contains( QStringLiteral( "/Themes" ) ) )
|
1065 | 1126 | {
|
@@ -1157,96 +1218,6 @@ int main( int argc, char *argv[] )
|
1157 | 1218 | QApplication::setStyle( presetStyle );
|
1158 | 1219 | mySettings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() );
|
1159 | 1220 | }
|
1160 |
| - /* Translation file for QGIS. |
1161 |
| - */ |
1162 |
| - QString i18nPath = QgsApplication::i18nPath(); |
1163 |
| - QString myUserTranslation = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString(); |
1164 |
| - QString myGlobalLocale = mySettings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString(); |
1165 |
| - bool myShowGroupSeparatorFlag = false; // Default to false |
1166 |
| - bool myLocaleOverrideFlag = mySettings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); |
1167 |
| - |
1168 |
| - // Override Show Group Separator if the global override flag is set |
1169 |
| - if ( myLocaleOverrideFlag ) |
1170 |
| - { |
1171 |
| - // Default to false again |
1172 |
| - myShowGroupSeparatorFlag = mySettings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); |
1173 |
| - } |
1174 |
| - |
1175 |
| - // |
1176 |
| - // Priority of translation is: |
1177 |
| - // - command line |
1178 |
| - // - user specified in options dialog (with group checked on) |
1179 |
| - // - system locale |
1180 |
| - // |
1181 |
| - // When specifying from the command line it will change the user |
1182 |
| - // specified user locale |
1183 |
| - // |
1184 |
| - if ( !myTranslationCode.isNull() && !myTranslationCode.isEmpty() ) |
1185 |
| - { |
1186 |
| - mySettings.setValue( QStringLiteral( "locale/userLocale" ), myTranslationCode ); |
1187 |
| - } |
1188 |
| - else |
1189 |
| - { |
1190 |
| - if ( !myLocaleOverrideFlag || myUserTranslation.isEmpty() ) |
1191 |
| - { |
1192 |
| - myTranslationCode = QLocale().name(); |
1193 |
| - //setting the locale/userLocale when the --lang= option is not set will allow third party |
1194 |
| - //plugins to always use the same locale as the QGIS, otherwise they can be out of sync |
1195 |
| - mySettings.setValue( QStringLiteral( "locale/userLocale" ), myTranslationCode ); |
1196 |
| - } |
1197 |
| - else |
1198 |
| - { |
1199 |
| - myTranslationCode = myUserTranslation; |
1200 |
| - } |
1201 |
| - } |
1202 |
| - |
1203 |
| - // Global locale settings |
1204 |
| - if ( myLocaleOverrideFlag && ! myGlobalLocale.isEmpty( ) ) |
1205 |
| - { |
1206 |
| - QLocale currentLocale( myGlobalLocale ); |
1207 |
| - QLocale::setDefault( currentLocale ); |
1208 |
| - } |
1209 |
| - |
1210 |
| - // Number settings |
1211 |
| - QLocale currentLocale; |
1212 |
| - if ( myShowGroupSeparatorFlag ) |
1213 |
| - { |
1214 |
| - currentLocale.setNumberOptions( currentLocale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator ); |
1215 |
| - } |
1216 |
| - else |
1217 |
| - { |
1218 |
| - currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator ); |
1219 |
| - } |
1220 |
| - QLocale::setDefault( currentLocale ); |
1221 |
| - |
1222 |
| - |
1223 |
| - QTranslator qgistor( nullptr ); |
1224 |
| - QTranslator qttor( nullptr ); |
1225 |
| - if ( myTranslationCode != QLatin1String( "C" ) ) |
1226 |
| - { |
1227 |
| - if ( qgistor.load( QStringLiteral( "qgis_" ) + myTranslationCode, i18nPath ) ) |
1228 |
| - { |
1229 |
| - myApp.installTranslator( &qgistor ); |
1230 |
| - } |
1231 |
| - else |
1232 |
| - { |
1233 |
| - QgsDebugMsg( QStringLiteral( "loading of qgis translation failed %1/qgis_%2" ).arg( i18nPath, myTranslationCode ) ); |
1234 |
| - } |
1235 |
| - |
1236 |
| - /* Translation file for Qt. |
1237 |
| - * The strings from the QMenuBar context section are used by Qt/Mac to shift |
1238 |
| - * the About, Preferences and Quit items to the Mac Application menu. |
1239 |
| - * These items must be translated identically in both qt_ and qgis_ files. |
1240 |
| - */ |
1241 |
| - if ( qttor.load( QStringLiteral( "qt_" ) + myTranslationCode, QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) ) |
1242 |
| - { |
1243 |
| - myApp.installTranslator( &qttor ); |
1244 |
| - } |
1245 |
| - else |
1246 |
| - { |
1247 |
| - QgsDebugMsg( QStringLiteral( "loading of qt translation failed %1/qt_%2" ).arg( QLibraryInfo::location( QLibraryInfo::TranslationsPath ), myTranslationCode ) ); |
1248 |
| - } |
1249 |
| - } |
1250 | 1221 |
|
1251 | 1222 | // set authentication database directory
|
1252 | 1223 | if ( !authdbdirectory.isEmpty() )
|
|
0 commit comments