-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding translations #144
Adding translations #144
Changes from all commits
98ecc3c
93e20c1
1e9e63a
1d889a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#ifndef TURNINSTRUCTIONSLIST_H_ | ||
#define TURNINSTRUCTIONSLIST_H_ | ||
|
||
#include <list> | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <stdlib.h> | ||
#include <dirent.h> | ||
#include <sys/stat.h> | ||
#include <cctype> | ||
#include <boost/algorithm/string.hpp> | ||
#include "./TurnInstructions.h" | ||
|
||
struct TurnInstructionsListClass { | ||
|
||
// Class to go over directory hierachy | ||
list<TurnInstructionsClass> tilist; | ||
vector<string> languages; | ||
|
||
TurnInstructionsListClass(){}; | ||
|
||
TurnInstructionsListClass(std::string path){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always pass strings as reference. The extra allocation is expensive. |
||
vector<string> archivos; | ||
vector<string>::iterator posArchivo; | ||
posArchivo = archivos.begin(); | ||
FindFile(path.c_str(), archivos); | ||
TurnInstructionsClass ti; | ||
// Vector with the file names to read | ||
for (int i = 0; i < archivos.size(); ++i){ | ||
ti = TurnInstructionsClass(archivos.at(i)); | ||
posArchivo++; | ||
tilist.push_back(ti); | ||
} | ||
}; | ||
|
||
void FindFile (const char dirname[], vector<string> &archivos){ | ||
static DIR *dir; | ||
static struct dirent *mi_dirent; | ||
// Check if the directory have opened correctly | ||
if((dir = opendir(dirname)) == NULL) | ||
cout << "Fault in opendir" << endl;; | ||
// Go over directory content | ||
while ((mi_dirent = readdir(dir)) != NULL){ | ||
// If it's not (.) or (..) | ||
if (strcmp (mi_dirent->d_name, ".") != 0 && strcmp (mi_dirent->d_name, "..") != 0){ | ||
struct stat structura; | ||
// Read the complete path | ||
string dirnameString = dirname; | ||
string nameFile = mi_dirent->d_name; | ||
string pathFile = dirnameString + "/" + nameFile; | ||
if (stat(pathFile.c_str(), &structura) < 0){ | ||
cout << "Fault in stat" << endl; | ||
}else if (structura.st_mode & S_IFREG){ | ||
archivos.reserve(archivos.size() + 2); | ||
archivos.push_back(pathFile); | ||
boost::to_upper(nameFile); | ||
languages.reserve(languages.size() + 2); | ||
languages.push_back(nameFile); | ||
}else if(structura.st_mode & S_IFDIR){ | ||
FindFile(mi_dirent->d_name, archivos); | ||
} | ||
} | ||
} | ||
if(closedir(dir) == -1){ | ||
cout << "Fault in closedir" << endl; | ||
} | ||
} | ||
|
||
TurnInstructionsClass getTurnInstructions(std::string language){ | ||
boost::to_upper(language); | ||
list <TurnInstructionsClass>::iterator pos; | ||
int index = -1; | ||
// In case the language is empty | ||
if(index == -1 && language == ""){ | ||
for(int i=0; i<languages.size(); i++){ | ||
if(languages.at(i).find("EN")==0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has linear runtime and is considered bad. A hash map is much more usable here. |
||
index = i; | ||
break; | ||
} | ||
} | ||
} | ||
// In case the request language is the same name than we have in the directory hierachy | ||
for(int i=0; i<languages.size(); i++){ | ||
if(language.compare(languages.at(i)) == 0){ | ||
index = i; | ||
break; | ||
} | ||
} | ||
// In case the request language is the same language but the name is not exactly the same | ||
// Example: Request parameter: 'lang=ES' and file name is 'ES_ES' | ||
if(index == -1){ | ||
for(int i=0; i<languages.size(); i++){ | ||
if(language != "" && languages.at(i).find(language)==0){ | ||
index = i; | ||
break; | ||
} | ||
} | ||
} | ||
// In case the request language is the same language but the name is not exactly the same | ||
// Example: Request parameter: 'lang=ES_ES' and file name is 'ES' | ||
if(index == -1){ | ||
for(int i=0; i<languages.size(); i++){ | ||
if(language.find(languages.at(i))==0){ | ||
index = i; | ||
break; | ||
} | ||
} | ||
} | ||
// In case the request language was an included language in another language | ||
// Example: Request parameter: 'lang=ES_AR' and file name is 'ES' | ||
if(index == -1){ | ||
for(int i=0; i<languages.size(); i++){ | ||
int pos = language.find("_"); | ||
string lang = language.substr(0, pos); | ||
if(languages.at(i).find(lang)==0){ | ||
index = i; | ||
break; | ||
} | ||
} | ||
} | ||
// In case the request parameter language doesn't exist, the default language is 'EN' | ||
if(index == -1){ | ||
for(int i=0; i<languages.size(); i++){ | ||
if(languages.at(i).find("EN")==0){ | ||
index = i; | ||
break; | ||
} | ||
} | ||
} | ||
pos = tilist.begin(); | ||
for(int i=0; i<index; i++){ | ||
pos++; | ||
} | ||
return *pos; | ||
} | ||
}; | ||
|
||
#endif /* TURNINSTRUCTIONSLIST_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Continue | ||
Turn slight right | ||
Turn right | ||
Turn sharp right | ||
U-Turn | ||
Turn sharp left | ||
Turn left | ||
Turn slight left | ||
Reach via point | ||
Head | ||
Enter round-about | ||
Leave round-about | ||
Stay on round-about | ||
Start | ||
zeroth | ||
first | ||
second | ||
third | ||
fourth | ||
fifth | ||
sixth | ||
seventh | ||
eighth | ||
nineth | ||
tenth |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Continuar | ||
Gire a la derecha | ||
Gire a la derecha | ||
Gire a la derecha aguda | ||
U-Turn | ||
Girar a la izquierda | ||
Gire a la izquierda | ||
Gire a la izquierda | ||
Llegar a un punto intermedio | ||
Cabeza | ||
Introduzca rotonda | ||
Deja rotonda | ||
Permanezca en rotonda | ||
Comenzar | ||
cero | ||
primero | ||
segundo | ||
tercero | ||
cuarto | ||
quinto | ||
sexto | ||
séptimo | ||
octavo | ||
noveno | ||
décimo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Continuer | ||
Tourner à droite | ||
Tourner à droite | ||
Tournez à droite forte | ||
U-Turn | ||
Tourner à gauche | ||
Tourner à gauche | ||
Tourner à gauche | ||
Parvenir à un compromis | ||
Tête | ||
Entrez rond-point | ||
Laissez rond-point | ||
Rester sur rond-point | ||
Commencer | ||
zéro | ||
première | ||
deuxième | ||
troisième | ||
quatrième | ||
cinquième | ||
sixième | ||
septième | ||
huitième | ||
neuvième | ||
dixième |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the Util/BaseConfiguration.h to load this information. Format the language files as simple ini files. This gives a lot more structure to the internationalization and does not introduce any new loading code.