Skip to content

Commit 35f3838

Browse files
committed
browser: add i18n
1 parent 2125f6a commit 35f3838

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/browser/main.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main( int argc, char ** argv )
6969
gdalShares << QCoreApplication::applicationDirPath().append( "/share/gdal" )
7070
<< appResources.append( "/share/gdal" )
7171
<< appResources.append( "/gdal" );
72-
Q_FOREACH ( const QString& gdalShare, gdalShares )
72+
Q_FOREACH( const QString& gdalShare, gdalShares )
7373
{
7474
if ( QFile::exists( gdalShare ) )
7575
{
@@ -80,6 +80,39 @@ int main( int argc, char ** argv )
8080
}
8181
#endif
8282

83+
QString i18nPath = QgsApplication::i18nPath();
84+
bool myLocaleOverrideFlag = settings.value( "locale/overrideFlag", false ).toBool();
85+
QString myUserLocale = settings.value( "locale/userLocale", "" ).toString();
86+
QString myTranslationCode = !myLocaleOverrideFlag || myUserLocale.isEmpty() ? QLocale::system().name() : myUserLocale;
87+
88+
QTranslator qgistor( 0 );
89+
QTranslator qttor( 0 );
90+
if ( myTranslationCode != "C" )
91+
{
92+
if ( qgistor.load( QString( "qgis_" ) + myTranslationCode, i18nPath ) )
93+
{
94+
a.installTranslator( &qgistor );
95+
}
96+
else
97+
{
98+
qWarning( "loading of qgis translation failed [%s]", QString( "%1/qgis_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() );
99+
}
100+
101+
/* Translation file for Qt.
102+
* The strings from the QMenuBar context section are used by Qt/Mac to shift
103+
* the About, Preferences and Quit items to the Mac Application menu.
104+
* These items must be translated identically in both qt_ and qgis_ files.
105+
*/
106+
if ( qttor.load( QString( "qt_" ) + myTranslationCode, QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) )
107+
{
108+
a.installTranslator( &qttor );
109+
}
110+
else
111+
{
112+
qWarning( "loading of qt translation failed [%s]", QString( "%1/qt_%2" ).arg( QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ).arg( myTranslationCode ).toLocal8Bit().constData() );
113+
}
114+
}
115+
83116
QgsBrowser w;
84117

85118
a.connect( &a, SIGNAL( aboutToQuit() ), &w, SLOT( saveWindowState() ) );

0 commit comments

Comments
 (0)