[DEV] Add basic translation interface
This commit is contained in:
parent
e3f6831dfa
commit
bc29612e37
2
external/enet
vendored
2
external/enet
vendored
@ -1 +1 @@
|
||||
Subproject commit 77dd712c56d11f1a6e1b98180f2f717dec52ab96
|
||||
Subproject commit 488658aecf730231e265d7d6b6887d00b74f9dec
|
@ -28,6 +28,7 @@
|
||||
#include <ewol/openGL/openGL.h>
|
||||
|
||||
#include <ewol/widget/Manager.h>
|
||||
#include <ewol/translate.h>
|
||||
|
||||
|
||||
|
||||
@ -302,6 +303,9 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) :
|
||||
m_initTotalStep(1) {
|
||||
m_commandLine.parse(_argc, _argv);
|
||||
EWOL_INFO(" == > Ewol system init (BEGIN)");
|
||||
// Add basic ewol translation:
|
||||
ewol::translate::addPath("ewol", "DATA:translate/ewol/");
|
||||
ewol::translate::autoDetectLanguage();
|
||||
// Reset the random system to be sure have real random values...
|
||||
etk::tool::resetRandom();
|
||||
// set the curent interface :
|
||||
|
202
sources/ewol/translate.cpp
Normal file
202
sources/ewol/translate.cpp
Normal file
@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/translate.h>
|
||||
#include <map>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ejson/ejson.h>
|
||||
|
||||
class LocalInstanceTranslation {
|
||||
private:
|
||||
std::map<std::string,std::string> m_listPath;
|
||||
std::string m_major;
|
||||
std::string m_languageDefault;
|
||||
std::string m_language;
|
||||
bool m_translateLoadad;
|
||||
std::map<std::string,std::string> m_translate;
|
||||
public:
|
||||
LocalInstanceTranslation(void) :
|
||||
m_major("ewol"),
|
||||
m_languageDefault("EN"),
|
||||
m_language(""),
|
||||
m_translateLoadad(false) {
|
||||
// nothing to do ...
|
||||
}
|
||||
public:
|
||||
void addPath(const std::string& _lib, const std::string& _path, bool _major) {
|
||||
auto it = m_listPath.find(_lib);
|
||||
if (it == m_listPath.end()) {
|
||||
m_listPath.insert(make_pair(_lib, _path));
|
||||
} else {
|
||||
it->second = _path;
|
||||
}
|
||||
if (_major == true) {
|
||||
m_major = _lib;
|
||||
EWOL_INFO("Change major translation : '" << m_major << "'");
|
||||
}
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
};
|
||||
|
||||
const std::string& getPaths(const std::string& _lib) {
|
||||
auto it = m_listPath.find(_lib);
|
||||
if (it == m_listPath.end()) {
|
||||
static const std::string g_error("");
|
||||
return g_error;
|
||||
}
|
||||
return it->second;
|
||||
};
|
||||
|
||||
void setLanguageDefault(const std::string& _lang) {
|
||||
if (m_languageDefault == _lang) {
|
||||
return;
|
||||
}
|
||||
EWOL_INFO("Change default language translation : '" << _lang << "'");
|
||||
m_languageDefault = _lang;
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
};
|
||||
|
||||
const std::string& getLanguageDefault(void) {
|
||||
return m_languageDefault;
|
||||
};
|
||||
|
||||
void setLanguage(const std::string& _lang) {
|
||||
if (m_language == _lang) {
|
||||
return;
|
||||
}
|
||||
m_language = _lang;
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
if (_lang == "EN") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=English");
|
||||
} else if (_lang == "FR") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=French");
|
||||
} else if (_lang == "DE") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=German");
|
||||
} else if (_lang == "SP") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Spanish");
|
||||
} else if (_lang == "JA") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Japanese");
|
||||
} else if (_lang == "IT") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Italian");
|
||||
} else if (_lang == "KO") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Korean");
|
||||
} else if (_lang == "RU") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Russian");
|
||||
} else if (_lang == "PT") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Portuguese, Brazilian");
|
||||
} else if (_lang == "ZH") {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Chinese");
|
||||
} else {
|
||||
EWOL_INFO("Change language translation: '" << _lang << "'=Unknow");
|
||||
}
|
||||
};
|
||||
|
||||
const std::string& getLanguage(void) {
|
||||
return m_language;
|
||||
};
|
||||
|
||||
const std::string& get(const std::string& _instance) {
|
||||
loadTranslation();
|
||||
auto it = m_translate.find(_instance);
|
||||
if (it == m_translate.end()) {
|
||||
EWOL_DEBUG("Can not find tranlation : '" << _instance << "'");
|
||||
return _instance;
|
||||
}
|
||||
return it->second;
|
||||
};
|
||||
private:
|
||||
void loadTranslation(void) {
|
||||
if (m_translateLoadad == true) {
|
||||
return;
|
||||
}
|
||||
// start parse default language:
|
||||
for (auto &it : m_listPath) {
|
||||
if (it.first == m_major) {
|
||||
continue;
|
||||
}
|
||||
std::string filename(it.second + "/" + m_languageDefault + ".json");
|
||||
if (etk::FSNodeExist(filename) == false) {
|
||||
continue;
|
||||
}
|
||||
ejson::Document doc;
|
||||
doc.load(filename);
|
||||
}
|
||||
// start parse default language for Major:
|
||||
auto itMajor = m_listPath.find(m_major);
|
||||
if (itMajor != m_listPath.end()) {
|
||||
|
||||
}
|
||||
// start parse language:
|
||||
for (auto &it : m_listPath) {
|
||||
if (it.first == m_major) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// start parse language for Major:
|
||||
if (itMajor != m_listPath.end()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static LocalInstanceTranslation& getInstanceTranslation(void) {
|
||||
static LocalInstanceTranslation g_val;
|
||||
return g_val;
|
||||
}
|
||||
|
||||
void ewol::translate::addPath(const std::string& _lib, const std::string& _path, bool _major) {
|
||||
getInstanceTranslation().addPath(_lib, _path, _major);
|
||||
}
|
||||
|
||||
const std::string& ewol::translate::getPaths(const std::string& _lib) {
|
||||
return getInstanceTranslation().getPaths(_lib);
|
||||
}
|
||||
|
||||
void ewol::translate::setLanguageDefault(const std::string& _lang) {
|
||||
getInstanceTranslation().setLanguageDefault(_lang);
|
||||
}
|
||||
|
||||
const std::string& ewol::translate::getLanguageDefault(void) {
|
||||
return getInstanceTranslation().getLanguageDefault();
|
||||
}
|
||||
|
||||
void ewol::translate::setLanguage(const std::string& _lang) {
|
||||
getInstanceTranslation().setLanguage(_lang);
|
||||
}
|
||||
|
||||
const std::string& ewol::translate::getLanguage(void) {
|
||||
return getInstanceTranslation().getLanguage();
|
||||
}
|
||||
|
||||
void ewol::translate::autoDetectLanguage(void) {
|
||||
EWOL_INFO("Auto-detect language of system");
|
||||
#if defined(__TARGET_OS__Linux)
|
||||
char *s = getenv("LANG");
|
||||
if (s == NULL || strlen(s) < 2) {
|
||||
EWOL_INFO("Try to determine system language FAIL ...");
|
||||
} else {
|
||||
std::string lang;
|
||||
lang += s[0];
|
||||
lang += s[1];
|
||||
lang = toupper(lang);
|
||||
getInstanceTranslation().setLanguage(lang);
|
||||
}
|
||||
#else
|
||||
EWOL_INFO("Can not auto-detect language ...");
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::string& ewol::translate::get(const std::string& _instance) {
|
||||
return getInstanceTranslation().get(_instance);
|
||||
}
|
||||
|
||||
|
80
sources/ewol/translate.h
Normal file
80
sources/ewol/translate.h
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_TRANSLATE_H__
|
||||
#define __EWOL_TRANSLATE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
|
||||
namespace ewol {
|
||||
/**
|
||||
* @brief This is a simple interface to converte application display string in a generic current system language
|
||||
* @note: The current name of language reprenent the file name, then if you want to get the machine language in an other than generic passed, juste add it.
|
||||
* Generic langage char: (all translation might be done in UTF-8 this simplify interface)
|
||||
* English : "EN"
|
||||
* French : "FR"
|
||||
* German : "DE"
|
||||
* Spanish : "SP"
|
||||
* Japanese : "JA"
|
||||
* Italian : "IT"
|
||||
* Korean : "KO"
|
||||
* Russian : "RU"
|
||||
* Portuguese, Brazilian : "PT"
|
||||
* Chinese : "ZH"
|
||||
*/
|
||||
namespace translate {
|
||||
/**
|
||||
* @brief Set the path folder of the translation files
|
||||
* @param[in] _lib Library name that the path depend
|
||||
* @param[in] _path ETK generic path (DATA:... or /xxx)
|
||||
* @param[in] _major This path is the major path (The last loaded, the one wichi overload all)
|
||||
*/
|
||||
void addPath(const std::string& _lib, const std::string& _path, bool _major = false);
|
||||
/**
|
||||
* @brief Get the current paths of the library
|
||||
* @param[in] _lib Library name that the path depend
|
||||
* @return Path name.
|
||||
*/
|
||||
const std::string& getPaths(const std::string& _lib);
|
||||
/**
|
||||
* @brief Set the default language to load data (the default language might contain all internal data for the basic application)
|
||||
* @param[in] _lang Language to load : ("EN" for english, "FR" for french, "DE" for German, "SP" for spanish ...)
|
||||
*/
|
||||
void setLanguageDefault(const std::string& _lang);
|
||||
/**
|
||||
* @brief Get the current language selected
|
||||
* @return The 2/3 char defining the language
|
||||
*/
|
||||
const std::string& getLanguageDefault(void);
|
||||
/**
|
||||
* @brief Set the language to load data. when no data availlable, we get the default language.
|
||||
* @param[in] _lang Language to load : ("EN" for english, "FR" for french, "DE" for German, "SP" for spanish ...)
|
||||
*/
|
||||
void setLanguage(const std::string& _lang);
|
||||
/**
|
||||
* @brief Get the current language loaded
|
||||
* @return The 2/3 char defining the language
|
||||
*/
|
||||
const std::string& getLanguage(void);
|
||||
/**
|
||||
* @brief Automatic detection of the system language
|
||||
*/
|
||||
void autoDetectLanguage(void);
|
||||
/**
|
||||
* @brief Translate a specific text (if not find, it will be retured the same text).
|
||||
* @param[in] _instance Text to translate.
|
||||
* @return The tranlated text.
|
||||
*/
|
||||
const std::string& get(const std::string& _instance);
|
||||
};
|
||||
};
|
||||
// Here we define a simple macro to Translate all string simply:
|
||||
#define TRANSLATE(a) ewol::translate::get(a)
|
||||
|
||||
#endif
|
||||
|
@ -29,6 +29,7 @@ namespace ewol {
|
||||
#include <ewol/event/Input.h>
|
||||
#include <ewol/event/Entry.h>
|
||||
#include <ewol/event/Time.h>
|
||||
#include <ewol/translate.h>
|
||||
|
||||
#define ULTIMATE_MAX_SIZE (99999999)
|
||||
|
||||
|
@ -56,19 +56,19 @@ ewol::widget::FileChooser::FileChooser(void) {
|
||||
+ " <sizer mode='vert' lock='true' fill='true' expand='true'>\n"
|
||||
+ " <sizer mode='hori'>\n"
|
||||
+ " <checkbox name='[" + std::to_string(getId()) + "]file-shooser:show-hiden-file'>\n"
|
||||
+ " <label>Show hiden files</label>\n"
|
||||
+ " <label>" + TRANSLATE("ShowHiddenFiles") + "</label>\n"
|
||||
+ " </checkbox>\n"
|
||||
+ " <spacer expand='true,false'/>\n"
|
||||
+ " <button name='[" + std::to_string(getId()) + "]file-shooser:button-validate'>\n"
|
||||
+ " <sizer mode='hori'>\n"
|
||||
+ " <image src='THEME:GUI:Load.edf' fill='true' size='7,7mm' distance-field='true'/>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:validate-label'>Validate</label>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:validate-label'>" + TRANSLATE("Validate") + "</label>\n"
|
||||
+ " </sizer>\n"
|
||||
+ " </button>\n"
|
||||
+ " <button name='[" + std::to_string(getId()) + "]file-shooser:button-cancel'>\n"
|
||||
+ " <sizer mode='hori'>\n"
|
||||
+ " <image src='THEME:GUI:Remove.edf' fill='true' size='7,7mm' distance-field='true'/>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:cancel-label'>Cancel</label>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:cancel-label'>" + TRANSLATE("Cancel") + "</label>\n"
|
||||
+ " </sizer>\n"
|
||||
+ " </button>\n"
|
||||
+ " </sizer>\n"
|
||||
@ -99,7 +99,7 @@ ewol::widget::FileChooser::FileChooser(void) {
|
||||
+ " <entry name='[" + std::to_string(getId()) + "]file-shooser:entry-folder' expand='true,false' fill='true,false'/>\n"
|
||||
+ " <image name='[" + std::to_string(getId()) + "]file-shooser:img-home' src='THEME:GUI:Home.edf' expand='false' size='8,8mm' distance-field='true'/>\n"
|
||||
+ " </sizer>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:title-label'>File chooser ...</label>\n"
|
||||
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:title-label'>" + TRANSLATE("Cancel") + "</label>\n"
|
||||
+ " </sizer>\n"
|
||||
+ "</popup>";
|
||||
loadFromString(myDescription);
|
||||
|
@ -23,7 +23,8 @@ def create(target):
|
||||
'ewol/ewol.cpp',
|
||||
'ewol/debug.cpp',
|
||||
'ewol/Padding.cpp',
|
||||
'ewol/Dimension.cpp'
|
||||
'ewol/Dimension.cpp',
|
||||
'ewol/translate.cpp'
|
||||
])
|
||||
|
||||
# compositing :
|
||||
@ -170,6 +171,7 @@ def create(target):
|
||||
myModule.copy_folder('../data/textured3D.*','')
|
||||
myModule.copy_folder('../data/texturedDF.*','')
|
||||
myModule.copy_folder('../data/fontDistanceField/*','fontDistanceField')
|
||||
myModule.copy_folder('../data/translate/*','translate/ewol/')
|
||||
|
||||
# name of the dependency
|
||||
myModule.add_module_depend(['etk', 'freetype', 'exml', 'ejson', 'egami', 'edtaa3', 'date'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user