diff options
| author | Joel Bodenmann <joel@seriouslyembedded.com> | 2016-02-27 14:35:57 +0100 |
|---|---|---|
| committer | Joel Bodenmann <joel@seriouslyembedded.com> | 2016-02-27 14:35:57 +0100 |
| commit | 6d2492aa93d8dc2a5fe701102d59d4e96d1b568c (patch) | |
| tree | 5d1d1c0aff467fd4155a8dff0fb6659d8514cf78 /src/gtrans/gtrans.c | |
| parent | b422bc99dd00947d4da668b8be12d8ecd191ccf9 (diff) | |
| parent | 87412e87d641e1d4e63eebbffc6434608a2149cb (diff) | |
| download | uGFX-6d2492aa93d8dc2a5fe701102d59d4e96d1b568c.tar.gz uGFX-6d2492aa93d8dc2a5fe701102d59d4e96d1b568c.tar.bz2 uGFX-6d2492aa93d8dc2a5fe701102d59d4e96d1b568c.zip | |
Merge branch 'translation'
Diffstat (limited to 'src/gtrans/gtrans.c')
| -rw-r--r-- | src/gtrans/gtrans.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/gtrans/gtrans.c b/src/gtrans/gtrans.c new file mode 100644 index 00000000..07409838 --- /dev/null +++ b/src/gtrans/gtrans.c @@ -0,0 +1,77 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * 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) +{ + // Find the index of the specified string in the base language table + size_t i = 0; + while (1) { + // Prevent overflow + if (i >= _languageBase->numEntries) { + return string; + } + + // Check if we found the string + if (strcmp(string, _languageBase->strings[i]) == 0) { + break; + } + + // Otherwise keep going + i++; + } + + // Make sure that the index exists in the current language table + if (i >= _languageCurrent->numEntries) { + return string; + } + + // Return the translated string + 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 */ |
