Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
a9752aaf
Commit
a9752aaf
authored
Jun 22, 2012
by
Claudio Valerio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added -lang parameter to application to be able to choose the language. Available on linux
parent
0ba0dcc7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
27 deletions
+77
-27
UBApplication.cpp
src/core/UBApplication.cpp
+47
-18
UBApplication.h
src/core/UBApplication.h
+1
-0
UBPlatformUtils.h
src/frameworks/UBPlatformUtils.h
+3
-2
UBPlatformUtils_linux.cpp
src/frameworks/UBPlatformUtils_linux.cpp
+14
-3
UBPlatformUtils_win.cpp
src/frameworks/UBPlatformUtils_win.cpp
+12
-4
No files found.
src/core/UBApplication.cpp
View file @
a9752aaf
...
...
@@ -135,27 +135,13 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing
UBResources
::
resources
();
if
(
!
undoStack
)
{
undoStack
=
new
QUndoStack
(
staticMemoryCleaner
);
}
mApplicationTranslator
=
new
QTranslator
(
this
);
mApplicationTranslator
->
load
(
UBPlatformUtils
::
preferredTranslation
(
QString
(
"sankore_"
)));
installTranslator
(
mApplicationTranslator
);
QString
localString
;
if
(
!
mApplicationTranslator
->
isEmpty
())
localString
=
UBPlatformUtils
::
preferredLanguage
();
else
localString
=
"en_US"
;
mQtGuiTranslator
=
new
QTranslator
(
this
);
mQtGuiTranslator
->
load
(
UBPlatformUtils
::
preferredTranslation
(
QString
(
"qt_"
)));
installTranslator
(
mQtGuiTranslator
);
QString
forcedLanguage
(
""
);
if
(
args
.
contains
(
"-lang"
))
forcedLanguage
=
args
.
at
(
args
.
indexOf
(
"-lang"
)
+
1
);
QLocale
::
setDefault
(
QLocale
(
localString
));
qDebug
()
<<
"Running application in:"
<<
localString
;
setupTranslator
(
forcedLanguage
);
UBSettings
*
settings
=
UBSettings
::
settings
();
...
...
@@ -217,6 +203,49 @@ UBApplication::~UBApplication()
staticMemoryCleaner
=
0
;
}
void
UBApplication
::
setupTranslator
(
QString
forcedLanguage
)
{
QStringList
availablesTranslations
=
UBPlatformUtils
::
availableTranslations
();
QString
language
(
""
);
if
(
!
forcedLanguage
.
isEmpty
()){
if
(
availablesTranslations
.
contains
(
forcedLanguage
,
Qt
::
CaseInsensitive
))
language
=
forcedLanguage
;
else
qDebug
()
<<
"forced language "
<<
forcedLanguage
<<
" not available"
;
}
else
{
QString
systemLanguage
=
UBPlatformUtils
::
systemLanguage
();
if
(
availablesTranslations
.
contains
(
systemLanguage
,
Qt
::
CaseInsensitive
))
language
=
systemLanguage
;
else
qDebug
()
<<
"translation for system language "
<<
systemLanguage
<<
" not found"
;
}
if
(
language
.
isEmpty
()){
language
=
"en_US"
;
//fallback if no translation are available
}
else
{
mApplicationTranslator
=
new
QTranslator
(
this
);
mQtGuiTranslator
=
new
QTranslator
(
this
);
mApplicationTranslator
->
load
(
UBPlatformUtils
::
translationPath
(
QString
(
"sankore_"
),
language
));
installTranslator
(
mApplicationTranslator
);
mQtGuiTranslator
->
load
(
UBPlatformUtils
::
translationPath
(
QString
(
"qt_"
),
language
));
if
(
mQtGuiTranslator
){
// checked because this translation could be not available
installTranslator
(
mQtGuiTranslator
);
}
}
QLocale
::
setDefault
(
QLocale
(
language
));
qDebug
()
<<
"Running application in:"
<<
language
;
}
int
UBApplication
::
exec
(
const
QString
&
pFileToImport
)
{
QPixmapCache
::
setCacheLimit
(
1024
*
100
);
...
...
src/core/UBApplication.h
View file @
a9752aaf
...
...
@@ -121,6 +121,7 @@ class UBApplication : public QtSingleApplication
private
:
void
updateProtoActionsState
();
void
setupTranslator
(
QString
forcedLanguage
);
QList
<
QMenu
*>
mProtoMenus
;
bool
mIsVerbose
;
...
...
src/frameworks/UBPlatformUtils.h
View file @
a9752aaf
...
...
@@ -103,8 +103,8 @@ class UBPlatformUtils
static
void
setFileType
(
const
QString
&
filePath
,
unsigned
long
fileType
);
static
void
fadeDisplayOut
();
static
void
fadeDisplayIn
();
static
QString
preferredTranslation
(
QString
pFilePrefix
);
static
QString
preferred
Language
();
static
QString
translationPath
(
QString
pFilePrefix
,
QString
pLanguage
);
static
QString
system
Language
();
static
bool
hasVirtualKeyboard
();
//static void showVirtualKeyboard();
static
void
runInstaller
(
const
QString
&
installerFilePath
);
...
...
@@ -115,6 +115,7 @@ class UBPlatformUtils
static
QString
computerName
();
static
UBKeyboardLocale
**
getKeyboardLayouts
(
int
&
nCount
);
static
QString
urlFromClipboard
();
static
QStringList
availableTranslations
();
};
...
...
src/frameworks/UBPlatformUtils_linux.cpp
View file @
a9752aaf
...
...
@@ -20,6 +20,8 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "frameworks/UBFileSystemUtils.h"
void
UBPlatformUtils
::
init
()
{
...
...
@@ -55,13 +57,22 @@ void UBPlatformUtils::fadeDisplayIn()
// NOOP
}
QString
UBPlatformUtils
::
preferredTranslation
(
QString
pFilePrefix
)
QStringList
UBPlatformUtils
::
availableTranslations
()
{
QString
translationsPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
;
QStringList
translationsList
=
UBFileSystemUtils
::
allFiles
(
translationsPath
);
QRegExp
sankoreTranslationFiles
(
".*sankore_.*.qm"
);
translationsList
=
translationsList
.
filter
(
sankoreTranslationFiles
);
return
translationsList
.
replaceInStrings
(
QRegExp
(
"(.*)sankore_(.*).qm"
),
"
\\
2"
);
}
QString
UBPlatformUtils
::
translationPath
(
QString
pFilePrefix
,
QString
pLanguage
)
{
QString
qmPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
+
pFilePrefix
+
p
referredLanguage
()
+
".qm"
;
QString
qmPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
+
pFilePrefix
+
p
Language
+
".qm"
;
return
qmPath
;
}
QString
UBPlatformUtils
::
preferred
Language
()
QString
UBPlatformUtils
::
system
Language
()
{
return
QLocale
::
system
().
name
();
}
...
...
src/frameworks/UBPlatformUtils_win.cpp
View file @
a9752aaf
...
...
@@ -59,14 +59,22 @@ void UBPlatformUtils::fadeDisplayIn()
// NOOP
}
QString
UBPlatformUtils
::
preferredTranslation
(
QString
pFilePrefix
)
QString
List
UBPlatformUtils
::
availableTranslations
(
)
{
QString
localPreferredLanguage
=
preferredLanguage
();
QString
qmPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
+
pFilePrefix
+
localPreferredLanguage
+
".qm"
;
QString
translationsPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
;
QStringList
translationsList
=
UBFileSystemUtils
::
allFiles
(
translationsPath
);
QRegExp
sankoreTranslationFiles
(
".*sankore_.*.qm"
);
translationsList
=
translationsList
.
filter
(
sankoreTranslationFiles
);
return
translationsList
.
replaceInStrings
(
QRegExp
(
"(.*)sankore_(.*).qm"
),
"
\\
2"
);
}
QString
UBPlatformUtils
::
translationPath
(
QString
pFilePrefix
,
QString
pLanguage
)
{
QString
qmPath
=
applicationResourcesDirectory
()
+
"/"
+
"i18n"
+
"/"
+
pFilePrefix
+
pLanguage
+
".qm"
;
return
qmPath
;
}
QString
UBPlatformUtils
::
preferred
Language
()
QString
UBPlatformUtils
::
system
Language
()
{
return
QLocale
::
system
().
name
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment