Skip to content

Commit

Permalink
Improved translation loading; translations are now loaded first from …
Browse files Browse the repository at this point in the history
…the configuration, then from the system locale, and from either the application directory or an embedded resource. Added an english translation as a resource.
  • Loading branch information
special committed Apr 3, 2010
1 parent e8dea9b commit b75c5cf
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 27 deletions.
26 changes: 3 additions & 23 deletions TorIM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,6 @@ HEADERS += src/ui/MainWindow.h \
src/tor/GetConfCommand.h \
src/ui/HomeContactWidget.h \
src/utils/DateUtil.h
OTHER_FILES += res/user--plus.png \
res/info-inactive.png \
res/info-hover.png \
res/info-active.png \
res/chat-inactive.png \
res/chat-hover.png \
res/chat-active.png \
res/status-online.png \
res/status-offline.png \
res/avatar-placeholder.png \
res/wall--pencil.png \
res/user--plus.png \
res/image--pencil.png \
res/globe-green.png \
res/gear.png \
res/folder-open-image.png \
res/tick-circle.png \
res/exclamation-red.png \
res/exclamation.png \
res/logotext.png \
res/information.png
RESOURCES += res/resources.qrc
TRANSLATIONS = torim.ts
RESOURCES += res/resources.qrc \
translation/embedded.qrc
TRANSLATIONS = translation/torim.ts
37 changes: 33 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ QSettings *config = 0;
static IncomingSocket *incomingSocket = 0;

static void initSettings();
static void initTranslation();
static void initIncomingSocket();
static bool connectTorControl();

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTranslator translator;
translator.load(QString("torim_") + QLocale::system().name(), a.applicationDirPath());
a.installTranslator(&translator);

QDir::setCurrent(a.applicationDirPath());

initSettings();
initTranslation();

/* Seed RNG */
{
Expand Down Expand Up @@ -69,6 +67,37 @@ static void initSettings()
config = new QSettings;
}

static void initTranslation()
{
QTranslator *translator = new QTranslator;

bool ok = false;
QString appPath = qApp->applicationDirPath();

/* First, try to load the user's configured language */
QString configLang = config->value("core/language").toString();
if (!configLang.isEmpty())
{
/* Look in the application directory */
ok = translator->load(QString("torim.") + configLang, appPath, QString("_"));
/* Look in the resources */
if (!ok)
ok = translator->load(QString("torim.") + configLang, QString(":/lang/"), QString("_"));
}

/* Next, try to load the system locale language, and allow it to fall back to the english default */
if (!ok)
{
QString locale = QLocale::system().name();
ok = translator->load(QString("torim.") + configLang, appPath);
if (!ok)
ok = translator->load(QString("torim.") + configLang, QString(":/lang/"));
}

if (ok)
qApp->installTranslator(translator);
}

static void initIncomingSocket()
{
QHostAddress address(config->value("core/listenIp", QString("127.0.0.1")).toString());
Expand Down
5 changes: 5 additions & 0 deletions translation/embedded.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/lang">
<file>torim.qm</file>
</qresource>
</RCC>
Binary file added translation/torim.qm
Binary file not shown.
66 changes: 66 additions & 0 deletions translation/torim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en_US">
<context>
<name>ContactUser</name>
<message numerus="yes">
<location filename="../src/core/ContactUser.cpp" line="+52"/>
<source>%n new message(s)</source>
<translation>
<numerusform>New message</numerusform>
<numerusform>%n new messages</numerusform>
</translation>
</message>
</context>
<context>
<name>timeDifferenceString</name>
<message numerus="yes">
<location filename="../src/utils/DateUtil.cpp" line="+17"/>
<source>%n minute(s) ago</source>
<translation>
<numerusform>%n minute ago</numerusform>
<numerusform>%n minutes ago</numerusform>
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n hour(s) ago</source>
<translation>
<numerusform>An hour ago</numerusform>
<numerusform>%n hours ago</numerusform>
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n day(s) ago</source>
<translation>
<numerusform>Yesterday</numerusform>
<numerusform>%n days ago</numerusform>
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n week(s) ago</source>
<translation>
<numerusform>Last week</numerusform>
<numerusform>%n weeks ago</numerusform>
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n month(s) ago</source>
<translation>
<numerusform>Last month</numerusform>
<numerusform>%n months ago</numerusform>
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n year(s) ago</source>
<translation>
<numerusform>Last year</numerusform>
<numerusform>%n years ago</numerusform>
</translation>
</message>
</context>
</TS>

0 comments on commit b75c5cf

Please sign in to comment.