Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
#52 Working on translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDuquesnoy committed Jul 29, 2017
1 parent 155bcec commit dec52e3
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 46 deletions.
12 changes: 6 additions & 6 deletions lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ QString DateTimeConverter::dateToCategory(const QDateTime& dateTime) const
QDate lastYear = today.addYears(-1);

if (date == today)
return tr("Today");
return "Today";
else if (date == yesterday)
return tr("Yesterday");
return "Yesterday";
else if (date >= lastWeek)
return tr("Last week");
return "Last week";
else if (date >= lastMonth)
return tr("Last month");
return "Last month";
else if (date >= lastYear)
return tr("Last year");
return "Last year";
else
return tr("Years ago");
return "Years ago";
}

QString DateTimeConverter::dateToString(const QDateTime& dateTime) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace MellowPlayer::Presentation {

class DateTimeConverter: public QObject {
Q_OBJECT
public:
Q_INVOKABLE QString dateToCategory(const QDateTime &dateTime) const;
Q_INVOKABLE QString dateToString(const QDateTime &dateTime) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ApplicationViewModel::ApplicationViewModel(int& argc, char** argv, const QString

void ApplicationViewModel::initialize()
{
if (!translator.load(QLocale(), "MellowPlayer", "_", ":/MellowPlayer/Translations")) {
if (!translator.load(QLocale("fr"), "MellowPlayer", "_", ":/MellowPlayer/Translations")) {
qWarning() << "failed to load translation: " << QLocale::system().name();
qInfo() << "available translations: ";
QDirIterator it(":/MellowPlayer/Translations", QStringList() << "*.qm", QDir::Files, QDirIterator::Subdirectories);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function translate(dateCategory) {
switch (dateCategory) {
case "Today":
return qsTr("Today");
case "Yesterday":
return qsTr("Yesterday");
case "Last week":
return qsTr("Last week");
case "Last month":
return qsTr("Last month");
case "Last year":
return qsTr("Last year");
case "Years ago":
return qsTr("Years ago");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import QtQuick.Controls.Material 2.2

import MellowPlayer 3.0
import ".."
import "../DateCategoryTranslator.js" as DateCategoryTranslator

Frame {
id: root
Expand Down Expand Up @@ -81,14 +82,14 @@ Frame {
}

Label {
text: qsTr("by ") + model.artist
text: qsTr("by") + " " + model.artist
font.italic: true
elide: "ElideMiddle"
width: 250
}

Label {
text: qsTr("on ") + model.service
text: qsTr("on") + " " + model.service
font.italic: true
elide: "ElideMiddle"
width: 250
Expand All @@ -101,8 +102,8 @@ Frame {

Label {
text: {
if (model.dateCategory === qsTr("Today") || model.dateCategory === qsTr("Yesterday"))
return model.dateCategory + "\n" + model.time
if (model.dateCategory === "Today" || model.dateCategory === "Yesterday")
return DateCategoryTranslator.translate(model.dateCategory) + "\n" + model.time
else
return model.date + "\n" + model.time
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import QtQuick.Controls.Material 2.2

import MellowPlayer 3.0
import ".."
import "../DateCategoryTranslator.js" as DateCategoryTranslator

Pane {
id: root
Expand Down Expand Up @@ -48,7 +49,7 @@ Pane {
}

Label {
text: section
text: DateCategoryTranslator.translate(section)
font.weight: Font.Bold
verticalAlignment: "AlignVCenter"

Expand Down
1 change: 1 addition & 0 deletions lib/MellowPlayer/Presentation/presentation.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
<file>Views/MellowPlayer/Controls/SettingsDrawer.qml</file>
<file>Views/MellowPlayer/Controls/WebViewContextMenu.qml</file>
<file>Views/MellowPlayer/Controls/IconToolButton.qml</file>
<file>Views/MellowPlayer/DateCategoryTranslator.js</file>
</qresource>
</RCC>
12 changes: 6 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ endif()
file(GLOB_RECURSE TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/languages/*.ts)
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/languages)
if (UPDATE_TRANSLATIONS)
# update source only, pushing to transifex will update all other languages
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR}/lib languages/MellowPlayer_en_US.ts OPTIONS -noobsolete)
file(GLOB_RECURSE QM_FILES ${CMAKE_CURRENT_SOURCE_DIR}/languages/*.qm)
else()
qt5_add_translation(QM_FILES ${TS_FILES})
endif()
Expand All @@ -24,12 +26,10 @@ message(STATUS ${QM_FILES})
file(WRITE languages/languages.qrc "<!DOCTYPE RCC>\n")
file(APPEND languages/languages.qrc "<RCC version=\"1.0\">\n")
file(APPEND languages/languages.qrc " <qresource prefix=\"/MellowPlayer/Translations\">\n")
if (NOT UPDATE_TRANSLATIONS)
foreach(FILE ${QM_FILES})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/languages/" "" RELATIVE_PATH ${FILE})
file(APPEND languages/languages.qrc " <file>${RELATIVE_PATH}</file>\n")
endforeach()
endif()
foreach(FILE ${QM_FILES})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/languages/" "" RELATIVE_PATH ${FILE})
file(APPEND languages/languages.qrc " <file>${RELATIVE_PATH}</file>\n")
endforeach()
file(APPEND languages/languages.qrc " </qresource>\n")
file(APPEND languages/languages.qrc "</RCC>\n")

Expand Down
38 changes: 14 additions & 24 deletions src/languages/MellowPlayer_en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,34 @@
</message>
</context>
<context>
<name>DateTimeConverter</name>
<name>DateCategoryTranslator</name>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="15"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="4"/>
<source>Today</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="17"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="6"/>
<source>Yesterday</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="19"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="8"/>
<source>Last week</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="21"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="10"/>
<source>Last month</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="23"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="12"/>
<source>Last year</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Converters/DateTimeConverter.cpp" line="25"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/DateCategoryTranslator.js" line="14"/>
<source>Years ago</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -269,32 +269,22 @@ listened to will appear here...</source>
<context>
<name>ListeningHistoryEntryDelegate</name>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="84"/>
<source>by </source>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="85"/>
<source>by</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="91"/>
<source>on </source>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="92"/>
<source>on</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="104"/>
<source>Today</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="104"/>
<source>Yesterday</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="135"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="136"/>
<source>Are you sure you want to remove that song from the history?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="136"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="137"/>
<source>Confirm remove</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -325,7 +315,7 @@ listened to will appear here...</source>
<context>
<name>ListeningHistorySectionDelegate</name>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistorySectionDelegate.qml" line="73"/>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistorySectionDelegate.qml" line="74"/>
<source>Confirm remove</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Binary file modified src/languages/MellowPlayer_fr_FR.qm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/languages/MellowPlayer_fr_FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ listened to will appear here...</source>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="84"/>
<source>by </source>
<translation>par</translation>
<translation>par </translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="91"/>
<source>on </source>
<translation>sur</translation>
<translation>sur </translation>
</message>
<message>
<location filename="../../lib/MellowPlayer/Presentation/Views/MellowPlayer/Delegates/ListeningHistoryEntryDelegate.qml" line="104"/>
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ int main(int argc, char** argv)
LOG_INFO(LoggingManager::instance().getLogger("main"),
QString("MellowPlayer %1 - %2").arg(QString(MELLOWPLAYER_VERSION)).arg(qtApp.getBuildInfo()));

qtApp.initialize();

auto injector = di::make_injector(di::bind<IQtApplication>().to(qtApp), di::bind<ICommandLineParser>().to(commandLineParser),
defaultInjector(scope), platformInjector(scope), notificationPresenterInjector(scope));

qtApp.initialize();

#ifdef QT_DEBUG
IApplication& app = injector.create<IApplication&>();
app.initialize();
Expand Down

0 comments on commit dec52e3

Please sign in to comment.