From d563eee35a6f2f72644049ade2c020bc8103a99c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Sj=C3=B6lund?= <martin.sjolund@liu.se>
Date: Wed, 26 Jun 2019 12:42:47 +0200
Subject: [PATCH] Add linguist lab

---
 translations/.gitignore   |  5 ++++-
 translations/Linguist.pro |  6 ++++++
 translations/Makefile     | 12 ++++++++++--
 translations/base.c       | 20 +++++++++++++++-----
 translations/gettext.c    |  3 ---
 5 files changed, 35 insertions(+), 11 deletions(-)
 create mode 100644 translations/Linguist.pro

diff --git a/translations/.gitignore b/translations/.gitignore
index cf75c4f..fa63547 100644
--- a/translations/.gitignore
+++ b/translations/.gitignore
@@ -1,3 +1,6 @@
-*-main.c
+*-main.c*
 *.mo
 gettext
+*.qm
+qt-linguist
+Makefile.linguist
diff --git a/translations/Linguist.pro b/translations/Linguist.pro
new file mode 100644
index 0000000..3c20502
--- /dev/null
+++ b/translations/Linguist.pro
@@ -0,0 +1,6 @@
+QT += core
+
+TARGET = qt-linguist
+
+SOURCES += linguist-main.cpp setuplocale.c linguist.cpp
+TRANSLATIONS = example_sv.ts
diff --git a/translations/Makefile b/translations/Makefile
index 85000ea..e68e6aa 100644
--- a/translations/Makefile
+++ b/translations/Makefile
@@ -1,8 +1,16 @@
-all: gettext-main.c linguist-main.c
+.PHONY: qt-linguist
+
+all: gettext-main.c linguist-main.cpp gettext qt-linguist
 
 gettext: gettext-main.c setuplocale.c gettext.c
 
 gettext-main.c: base.c
 	cp $< $@
-linguist-main.c: base.c
+linguist-main.cpp: base.c
 	cp $< $@
+
+qt-linguist: Makefile.linguist
+	$(MAKE) -f Makefile.linguist
+
+Makefile.linguist: Linguist.pro
+	qmake -o $@ $<
diff --git a/translations/base.c b/translations/base.c
index 03eace7..02fdf80 100644
--- a/translations/base.c
+++ b/translations/base.c
@@ -1,19 +1,29 @@
 #include <stdio.h>
 
+#if __cplusplus
+extern "C" void setuplocale();
+#else
 void setup();
 void setuplocale();
+#endif
 
 int main(int argc, char** argv)
 {
   setuplocale();
+#if __cplusplus
+  /* For Qt: Your code here as it is more convenient than a separate function in C++.
+   * Setup a QCoreApplication (an application without GUI) and install a translator.
+   */
+#else
   setup();
-  /* TODO: You need to update this code to output translated strings
+#endif
+  /* You need to update this code to output translated strings
    * Note that you should make gettext-main.c linguist-main.c and modify
    * those files rather than base.c
    */
-  printf("The current language is the default (C/POSIX)\n");
-  printf("The horse can run.\n");
-  printf("How fast can the horse run?\n");
-  printf("It typically runs at speed of less than 50 km/h.\n");
+  puts("The current language is the default (C/POSIX)\n");
+  puts("The horse can run.\n");
+  puts("How fast can the horse run?\n");
+  puts("It typically runs at speed of less than 50 km/h.\n");
   return 0;
 }
diff --git a/translations/gettext.c b/translations/gettext.c
index 657b2ba..e3ee684 100644
--- a/translations/gettext.c
+++ b/translations/gettext.c
@@ -1,7 +1,4 @@
-#include <locale.h>
 #include <libintl.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 void setup()
 {
-- 
GitLab