diff options
Diffstat (limited to 'src/gtrans')
-rw-r--r-- | src/gtrans/gtrans.c | 51 | ||||
-rw-r--r-- | src/gtrans/gtrans.h | 10 |
2 files changed, 60 insertions, 1 deletions
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 } |