aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/modules/gtrans/basic/gfxconf.h2
-rw-r--r--demos/modules/gtrans/basic/main.c39
-rw-r--r--gfx.h10
-rw-r--r--src/gtrans/gtrans.c51
-rw-r--r--src/gtrans/gtrans.h10
5 files changed, 109 insertions, 3 deletions
diff --git a/demos/modules/gtrans/basic/gfxconf.h b/demos/modules/gtrans/basic/gfxconf.h
index a5a0fbef..09e6bbea 100644
--- a/demos/modules/gtrans/basic/gfxconf.h
+++ b/demos/modules/gtrans/basic/gfxconf.h
@@ -42,7 +42,7 @@
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_TEXT TRUE
-#define GDISP_NEED_ANTIALIAS TRUE
+#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_INCLUDE_USER_FONTS FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
diff --git a/demos/modules/gtrans/basic/main.c b/demos/modules/gtrans/basic/main.c
index 38d163cd..63310be7 100644
--- a/demos/modules/gtrans/basic/main.c
+++ b/demos/modules/gtrans/basic/main.c
@@ -28,10 +28,47 @@
*/
#include "gfx.h"
-
+
+static const char* EnglishStrings[] = {
+ "Welcome",
+ "The number %s has the value %d",
+ "Goodbye"
+};
+static const transTable EnglishTranslation = { sizeof(EnglishStrings)/sizeof(EnglishStrings[0]), EnglishStrings };
+
+static const char* GermanStrings[] = {
+ "Herzlich Willkommen",
+ "Die Zahl %s hat den Wert %d",
+ "Auf Wiedersehen"
+};
+static const transTable GermanTranslation = { sizeof(GermanStrings)/sizeof(GermanStrings[0]), GermanStrings };
+
int main(void)
{
+ size_t i, j;
+ font_t font;
+
gfxInit();
+ gdispClear(Silver);
+
+ font = gdispOpenFont("*");
+
+ gtransSetBaseLanguage(&EnglishTranslation);
+ gtransSetLanguage(&GermanTranslation);
+
+ gtransSetLanguage(&EnglishTranslation);
+ i = 0;
+ for (j = 0; j < EnglishTranslation.numEntries; j++) {
+ gdispFillStringBox(20+300*i, 35*j, 300, 35, gtransIndex(j), font, Black, Silver, justifyLeft);
+ }
+
+ gtransSetLanguage(&GermanTranslation);
+ i = 1;
+ for (j = 0; j < EnglishTranslation.numEntries; j++) {
+ gdispFillStringBox(20+300*i, 35*j, 300, 35, gtransIndex(j), font, Black, Silver, justifyLeft);
+ }
+
+ gdispFillStringBox(20, 300, 300, 25, gtransString("Welcome"), font, Black, Silver, justifyLeft);
while (TRUE) {
gfxSleepMilliseconds(500);
diff --git a/gfx.h b/gfx.h
index 1c217b32..afaf7b87 100644
--- a/gfx.h
+++ b/gfx.h
@@ -145,6 +145,13 @@
#ifndef GFX_USE_GFILE
#define GFX_USE_GFILE FALSE
#endif
+ /**
+ * @brief GFX Translation Support API
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_GTRANS
+ #define GFX_USE_GTRANS FALSE
+ #endif
/** @} */
/**
@@ -155,6 +162,7 @@
#include "src/gdriver/gdriver_options.h"
#include "src/gfile/gfile_options.h"
#include "src/gmisc/gmisc_options.h"
+#include "src/gtrans/gtrans_options.h"
#include "src/gqueue/gqueue_options.h"
#include "src/gevent/gevent_options.h"
#include "src/gtimer/gtimer_options.h"
@@ -181,6 +189,7 @@
#include "src/gtimer/gtimer_rules.h"
#include "src/gqueue/gqueue_rules.h"
#include "src/gmisc/gmisc_rules.h"
+#include "src/gtrans/gtrans_rules.h"
#include "src/gfile/gfile_rules.h"
#include "src/gdriver/gdriver_rules.h"
#include "src/gos/gos_rules.h"
@@ -192,6 +201,7 @@
//#include "src/gdriver/gdriver.h" // This module is only included by source that needs it.
#include "src/gfile/gfile.h"
#include "src/gmisc/gmisc.h"
+#include "src/gtrans/gtrans.h"
#include "src/gqueue/gqueue.h"
#include "src/gevent/gevent.h"
#include "src/gtimer/gtimer.h"
diff --git a/src/gtrans/gtrans.c b/src/gtrans/gtrans.c
index 7e1105d6..4961cdcb 100644
--- a/src/gtrans/gtrans.c
+++ b/src/gtrans/gtrans.c
@@ -5,16 +5,67 @@
* http://ugfx.org/license.html
*/
+#include <string.h>
#include "../../gfx.h"
#if GFX_USE_GTRANS
+static const transTable* _languageBase;
+static const transTable* _languageCurrent;
+
void _gtransInit(void)
{
+ _languageBase = 0;
+ _languageCurrent = 0;
}
void _gtransDeinit(void)
{
}
+const char* gtransString(const char* string)
+{
+ size_t i = 0;
+ while (1) {
+ if (i >= _languageBase->numEntries-1) {
+ return 0;
+ }
+
+ if (strcmp(string, _languageBase->strings[i]) == 0) {
+ break;
+ }
+
+ i++;
+ }
+
+ if (i >= _languageCurrent->numEntries-1) {
+ return 0;
+ }
+
+ return _languageCurrent->strings[i];
+}
+
+const char* gtransIndex(unsigned index)
+{
+ if (!_languageCurrent) {
+ return 0;
+ }
+
+ if (index >= _languageCurrent->numEntries) {
+ return 0;
+ }
+
+ return _languageCurrent->strings[index];
+}
+
+void gtransSetBaseLanguage(const transTable* const translation)
+{
+ _languageBase = translation;
+}
+
+void gtransSetLanguage(const transTable* const translation)
+{
+ _languageCurrent = translation;
+}
+
#endif /* GFX_USE_GTRANS */
diff --git a/src/gtrans/gtrans.h b/src/gtrans/gtrans.h
index c46b5b28..f09d90e1 100644
--- a/src/gtrans/gtrans.h
+++ b/src/gtrans/gtrans.h
@@ -22,11 +22,19 @@
#if GFX_USE_GTRANS || defined(__DOXYGEN__)
+typedef struct transTable {
+ unsigned numEntries;
+ const char** strings;
+} transTable;
+
#ifdef __cplusplus
extern "C" {
#endif
-
+const char* gtransString(const char* string);
+const char* gtransIndex(unsigned index);
+void gtransSetBaseLanguage(const transTable* const translation);
+void gtransSetLanguage(const transTable* const translation);
#ifdef __cplusplus
}