From af319573a3fd4cdfdccbf318bf7a65edc89faeb5 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 24 Sep 2018 23:26:07 +0200 Subject: [PATCH] [DEV] integrate the new interface of URI and file --- etranslate/etranslate.cpp | 40 ++++++++++++++++++++------------------- etranslate/etranslate.hpp | 9 +++++---- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/etranslate/etranslate.cpp b/etranslate/etranslate.cpp index 450fdf6..ace0a42 100644 --- a/etranslate/etranslate.cpp +++ b/etranslate/etranslate.cpp @@ -7,14 +7,13 @@ #include #include #include -#include #include #include class LocalInstanceTranslation { private: - etk::Map m_listPath; + etk::Map m_listPath; etk::String m_major; etk::String m_languageDefault; etk::String m_language; @@ -29,8 +28,8 @@ class LocalInstanceTranslation { // nothing to do ... } public: - void addPath(const etk::String& _lib, const etk::String& _path, bool _major) { - m_listPath.set(_lib, _path); + void addPath(const etk::String& _lib, const etk::Uri& _uri, bool _major) { + m_listPath.set(_lib, _uri); if (_major == true) { m_major = _lib; ETRANSLATE_INFO("Change major translation : '" << m_major << "'"); @@ -39,10 +38,10 @@ class LocalInstanceTranslation { m_translate.clear(); }; - const etk::String& getPaths(const etk::String& _lib) { + const etk::Uri& getPaths(const etk::String& _lib) { auto it = m_listPath.find(_lib); if (it == m_listPath.end()) { - static const etk::String g_error(""); + static const etk::Uri g_error(""); return g_error; } return it->second; @@ -146,15 +145,16 @@ class LocalInstanceTranslation { // start parse language for Major: auto itMajor = m_listPath.find(m_major); if (itMajor != m_listPath.end()) { - etk::String filename(itMajor->second + "/" + m_language + ".json"); + etk::Uri uri = itMajor->second; + uri.setPath(itMajor->second.getPath() / m_language + ".json"); ejson::Document doc; - doc.load(filename); + doc.load(uri); for (auto element : doc.getKeys()) { etk::String val = doc[element].toString().get(); m_translate.set(element, val); } - filename = itMajor->second + "/" + m_languageDefault + ".json"; - doc.load(filename); + uri.setPath(itMajor->second.getPath() / m_languageDefault + ".json"); + doc.load(uri); for (auto element : doc.getKeys()) { etk::String val = doc[element].toString().get(); m_translate.set(element, val); @@ -165,12 +165,13 @@ class LocalInstanceTranslation { if (it.first == m_major) { continue; } - etk::String filename(it.second + "/" + m_languageDefault + ".json"); - if (etk::FSNodeExist(filename) == false) { + etk::Uri uri = itMajor->second; + uri.setPath(itMajor->second.getPath() / m_languageDefault + ".json"); + if (etk::uri::exist(uri) == false) { continue; } ejson::Document doc; - doc.load(filename); + doc.load(uri); for (auto element : doc.getKeys()) { etk::String val = doc[element].toString().get(); m_translate.set(element, val); @@ -181,12 +182,13 @@ class LocalInstanceTranslation { if (it.first == m_major) { continue; } - etk::String filename(it.second + "/" + m_languageDefault + ".json"); - if (etk::FSNodeExist(filename) == false) { + etk::Uri uri = itMajor->second; + uri.setPath(itMajor->second.getPath() / m_languageDefault + ".json"); + if (etk::uri::exist(uri) == false) { continue; } ejson::Document doc; - doc.load(filename); + doc.load(uri); for (auto element : doc.getKeys()) { etk::String val = doc[element].toString().get(); m_translate.set(element, val); @@ -234,14 +236,14 @@ void etranslate::unInit() { ETRANSLATE_ERROR("E-translate system un-init (already done before)"); } -void etranslate::addPath(const etk::String& _lib, const etk::String& _path, bool _major) { +void etranslate::addPath(const etk::String& _lib, const etk::Uri& _uri, bool _major) { if (g_isInit <= 0) { ETRANSLATE_ERROR("E-translate system has not been init"); } - getInstanceTranslation().addPath(_lib, _path, _major); + getInstanceTranslation().addPath(_lib, _uri, _major); } -const etk::String& etranslate::getPaths(const etk::String& _lib) { +const etk::Uri& etranslate::getPaths(const etk::String& _lib) { if (g_isInit <= 0) { ETRANSLATE_ERROR("E-translate system has not been init"); } diff --git a/etranslate/etranslate.hpp b/etranslate/etranslate.hpp index 2313ff0..ec6b195 100644 --- a/etranslate/etranslate.hpp +++ b/etranslate/etranslate.hpp @@ -6,6 +6,7 @@ #pragma once #include +#include /** * @brief This is a simple interface to converte application display string in a generic current system language @@ -36,16 +37,16 @@ namespace etranslate { /** * @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] _uri ETK generic uri (DATA:... or /xxx) * @param[in] _major This path is the major path (The last loaded, the one which overload all) */ - void addPath(const etk::String& _lib, const etk::String& _path, bool _major = false); + void addPath(const etk::String& _lib, const etk::Uri& _uri, bool _major = false); /** * @brief Get the current paths of the library * @param[in] _lib Library name that the path depend - * @return Path name. + * @return Uri value. */ - const etk::String& getPaths(const etk::String& _lib); + const etk::Uri& getPaths(const etk::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 ...)