initial check in based on SVN revision 575
This commit is contained in:
204
source/Fonts/translate.c
Normal file
204
source/Fonts/translate.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* translate.c
|
||||
*
|
||||
* Created on: Feb 12, 2022
|
||||
* Author: Brian.Bailey
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "System/system.h"
|
||||
#include "languages.h"
|
||||
#include "translate.h"
|
||||
|
||||
|
||||
|
||||
//Language names (in the language)
|
||||
const char *languageNames[] =
|
||||
{
|
||||
"English", //English
|
||||
"Español", //Spanish
|
||||
"Français", //French
|
||||
"Deutsch", //German
|
||||
"Italiano", //Italian
|
||||
"Polski", //Polish
|
||||
"Nederlands", //Dutch
|
||||
"Português", //Portuguese
|
||||
"Русский", //Russian
|
||||
"Svenska", //Swedish
|
||||
"Dansk", //Danish
|
||||
"Eesti", //Estonian
|
||||
"Latviski", //Latvian
|
||||
"Lietuvių kalba", //Lithuanian
|
||||
"Čeština", //Czech
|
||||
"Suomi", //Finnish
|
||||
"Ελληνικά", //Greek
|
||||
"Norsk", //Norwegian
|
||||
"Magyar", //Hungarian
|
||||
"Română", //Romanian
|
||||
"简体中文", //Chinese
|
||||
"한국어", //Korean
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const char* Translate(const char *input)
|
||||
{
|
||||
//find the index of the input string in textEnglish[]
|
||||
int16_t low = 0;
|
||||
int16_t high = NUM_TRANSLATION_STRINGS - 1;
|
||||
int16_t mid;
|
||||
int16_t compare; //result of strcmp()
|
||||
int16_t index; //index of the input string in textEnglish[]
|
||||
bool done = false;
|
||||
const char *translatedString;
|
||||
|
||||
//bisection algorithm
|
||||
|
||||
while ((low <= high) && !done)
|
||||
{
|
||||
mid = (low + high) / 2;
|
||||
compare = strcmp(input, textEnglish[mid]);
|
||||
|
||||
if (compare == 0) //strings match
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
else if (compare < 0) //correct string is "lower" than result
|
||||
{
|
||||
high = mid - 1;
|
||||
}
|
||||
else //correct string is "higher" than result
|
||||
{
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
index = mid;
|
||||
|
||||
if (done == false) //string not found in array
|
||||
{
|
||||
translatedString = input; //return the input string (no translation)
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (SYS_GetLanguage()) //language currently used
|
||||
{
|
||||
case LANG_SPANISH:
|
||||
translatedString = textSpanish[index];
|
||||
break;
|
||||
case LANG_FRENCH:
|
||||
translatedString = textFrench[index];
|
||||
break;
|
||||
case LANG_GERMAN:
|
||||
translatedString = textGerman[index];
|
||||
break;
|
||||
case LANG_ITALIAN:
|
||||
translatedString = textItalian[index];
|
||||
break;
|
||||
case LANG_POLISH:
|
||||
translatedString = textPolish[index];
|
||||
break;
|
||||
case LANG_DUTCH:
|
||||
translatedString = textDutch[index];
|
||||
break;
|
||||
case LANG_PORTUGUESE:
|
||||
translatedString = textPortuguese[index];
|
||||
break;
|
||||
case LANG_RUSSIAN:
|
||||
translatedString = textRussian[index];
|
||||
break;
|
||||
case LANG_SWEDISH:
|
||||
translatedString = textSwedish[index];
|
||||
break;
|
||||
case LANG_DANISH:
|
||||
translatedString = textDanish[index];
|
||||
break;
|
||||
case LANG_ESTONIAN:
|
||||
translatedString = textEstonian[index];
|
||||
break;
|
||||
case LANG_LATVIAN:
|
||||
translatedString = textLatvian[index];
|
||||
break;
|
||||
case LANG_LITHUANIAN:
|
||||
translatedString = textLithuanian[index];
|
||||
break;
|
||||
case LANG_CZECH:
|
||||
translatedString = textCzech[index];
|
||||
break;
|
||||
case LANG_FINNISH:
|
||||
translatedString = textFinnish[index];
|
||||
break;
|
||||
case LANG_GREEK:
|
||||
translatedString = textGreek[index];
|
||||
break;
|
||||
case LANG_NORWEGIAN:
|
||||
translatedString = textNorwegian[index];
|
||||
break;
|
||||
case LANG_HUNGARIAN:
|
||||
translatedString = textHungarian[index];
|
||||
break;
|
||||
case LANG_ROMANIAN:
|
||||
translatedString = textRomanian[index];
|
||||
break;
|
||||
case LANG_CHINESE:
|
||||
translatedString = textChinese[index];
|
||||
break;
|
||||
case LANG_KOREAN:
|
||||
translatedString = textKorean[index];
|
||||
break;
|
||||
default:
|
||||
translatedString = textEnglish[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return translatedString;
|
||||
}
|
||||
|
||||
#if 0
|
||||
//returns the index of the input string in textEnglish[]
|
||||
//returns -1 if input string not found
|
||||
uint16_t GetTranslationIndex(const char *input)
|
||||
{
|
||||
int16_t low = 0;
|
||||
int16_t high = NUM_TRANSLATION_STRINGS - 1;
|
||||
int16_t mid;
|
||||
int16_t compare;
|
||||
|
||||
bool done = false;
|
||||
|
||||
//bisection algorithm
|
||||
|
||||
while ((low <= high) && !done)
|
||||
{
|
||||
mid = (low + high) / 2;
|
||||
compare = strcmp(input, textEnglish[mid]);
|
||||
|
||||
if (compare == 0) //strings match
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
else if (compare < 0) //correct string is "lower" than result
|
||||
{
|
||||
high = mid - 1;
|
||||
}
|
||||
else //correct string is "higher" than result
|
||||
{
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int16_t retval = mid;
|
||||
if (done == false) //string not found in array
|
||||
{
|
||||
retval = -1;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user