Make about dialog in frontend translatable
authorWuzzy <Wuzzy2@mail.ru>
Thu, 13 Dec 2018 20:24:50 +0100
changeset 14433 fbe5e49462aa
parent 14432 9b53b46ede3e
child 14434 e64b9ea24cd8
Make about dialog in frontend translatable
.hgignore
QTfrontend/CMakeLists.txt
QTfrontend/res/credits.csv
QTfrontend/ui/widget/about.cpp
--- a/.hgignore	Thu Dec 13 18:55:25 2018 +0100
+++ b/.hgignore	Thu Dec 13 20:24:50 2018 +0100
@@ -20,6 +20,7 @@
 cmake_install.cmake
 QTfrontend/hwconsts.cpp
 QTfrontend/servermessages.h
+QTfrontend/creditsmessages.h
 CPackConfig.cmake
 CPackSourceConfig.cmake
 tools/cmake_uninstall.cmake
--- a/QTfrontend/CMakeLists.txt	Thu Dec 13 18:55:25 2018 +0100
+++ b/QTfrontend/CMakeLists.txt	Thu Dec 13 20:24:50 2018 +0100
@@ -45,6 +45,29 @@
 list(APPEND locsout ${firstline} "\n}\\;\n")
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/servermessages.h ${locsout})
 
+
+# Credits localization
+file(GLOB CreditsCSV ${CMAKE_SOURCE_DIR}/QTfrontend/res/credits.csv)
+foreach(csvfile ${CreditsCSV})
+    file(READ ${csvfile} csv)
+    string(REGEX MATCHALL "\n(\"[^\n\"]+\")" locs ${csv})
+    foreach(str ${locs})
+        string(REGEX REPLACE "\"([^\n\"]+)\"" "QT_TRANSLATE_NOOP(\"credits\", \"\\1\")" s ${str})
+        list(APPEND csvlocs ${s})
+    endforeach(str)
+endforeach(csvfile)
+
+list(REMOVE_DUPLICATES csvlocs)
+list(GET csvlocs 0 firstline)
+list(REMOVE_AT csvlocs 0)
+set(locsout "const char * creditsMessages[] = {")
+foreach(l ${csvlocs})
+    list(APPEND locsout ${l} ",")
+endforeach(l)
+list(APPEND locsout ${firstline} "\n}\\;\n")
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/creditsmessages.h ${locsout})
+
+
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/model)
--- a/QTfrontend/res/credits.csv	Thu Dec 13 18:55:25 2018 +0100
+++ b/QTfrontend/res/credits.csv	Thu Dec 13 20:24:50 2018 +0100
@@ -89,7 +89,7 @@
 "Rock","HSR <http://elhombresinremedio.com>",
 "olympics_sd","yd <http://opengameart.org/users/yd>",
 "oriental","Jonatan Nilsson",
-"sdmusic (""Hitman [sheepluva edit]"")","Kevin MacLeod",
+"sdmusic (Hitman [sheepluva edit])","Kevin MacLeod",
 "snow","Jonatan Nilsson",
 !__MISC,,
 !__SECTION,"Translations",
@@ -138,4 +138,4 @@
 ,"Aleksey Andreev","blaknayabr@gmail.com",
 ,"Aleksander Rudalev","alexv@pomorsu.ru",
 ,"Natasha Korotaeva","layout@pisem.net",
-,"Adam ""ahigerd"" Higerd",
+,"Adam Higerd (alias ahigerd)",
--- a/QTfrontend/ui/widget/about.cpp	Thu Dec 13 18:55:25 2018 +0100
+++ b/QTfrontend/ui/widget/about.cpp	Thu Dec 13 20:24:50 2018 +0100
@@ -32,6 +32,8 @@
 #include "SDL.h"
 #include "SDL_version.h"
 #include "physfs.h"
+#include "creditsmessages.h"
+#include "HWApplication.h"
 
 #ifdef VIDEOREC
 extern "C"
@@ -160,19 +162,33 @@
                 QString mailLink = QString("<a href=\"mailto:%1\">%1</a>").arg(mail);
                 if(task.isEmpty() && mail.isEmpty())
                 {
+                    // Name only
                     out = out + "<li>" + name + "</li>\n";
                 }
                 else if(task.isEmpty())
                 {
+                    // Name and e-mail
+                    //: Part of credits. %1: Contribution name. %2: E-mail address
                     out = out + "<li>" + tr("%1 &lt;%2&gt;").arg(name).arg(mailLink) + "</li>\n";
                 }
                 else if(mail.isEmpty())
                 {
-                    out = out + "<li>" + tr("%1: %2").arg(task).arg(name) + "</li>\n";
+                    // Contribution and name
+                    //: Part of credits. %1: Description of contribution. %2: Contributor name
+                    out = out + "<li>" + tr("%1: %2")
+                        .arg(HWApplication::translate("credits", task.toLatin1().constData()))
+                        .arg(name)
+                        + "</li>\n";
                 }
                 else
                 {
-                    out = out + "<li>" + tr("%1: %2 &lt;%3&gt;").arg(task).arg(name).arg(mailLink) + "</li>\n";
+                    // Contribution, name and e-mail
+                    //: Part of credits. %1: Description of contribution. %2: Contributor name. %3: E-mail address
+                    out = out + "<li>" + tr("%1: %2 &lt;%3&gt;")
+                        .arg(HWApplication::translate("credits", task.toLatin1().constData()))
+                        .arg(name)
+                        .arg(mailLink)
+                        + "</li>\n";
                 }
             }
             lineComplete = false;