Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-07-28 16:36:11 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:58:14 +0300
commitd30f6611f798e48e4516e524f3ef71c6ea929d5b (patch)
tree44c01e8f426c190c1d19e8f354ccec181e44db49 /platform
parenta040abf0ce37b7b874ed577dc559be116b76644d (diff)
Corrections after colleagues comments.
Diffstat (limited to 'platform')
-rw-r--r--platform/get_text_by_id.cpp36
-rw-r--r--platform/get_text_by_id.hpp8
-rw-r--r--platform/platform_tests/get_text_by_id_tests.cpp36
3 files changed, 60 insertions, 20 deletions
diff --git a/platform/get_text_by_id.cpp b/platform/get_text_by_id.cpp
index 5667ee22a4..91d5e5342b 100644
--- a/platform/get_text_by_id.cpp
+++ b/platform/get_text_by_id.cpp
@@ -1,21 +1,47 @@
#include "platform/get_text_by_id.hpp"
#include "platform/platform.hpp"
+#include "coding/file_name_utils.hpp"
+
#include "base/logging.hpp"
#include "3party/jansson/myjansson.hpp"
+#include "std/target_os.hpp"
+
+
+namespace
+{
+string GetTextSourceString(platform::TextSource textSouce)
+{
+#if defined(OMIM_OS_ANDROID) || defined(OMIM_OS_IPHONE)
+ switch(textSouce)
+ {
+ case platform::TextSource::TtsSound:
+ return "sound-strings";
+ }
+#else
+ switch(textSouce)
+ {
+ case platform::TextSource::TtsSound:
+ return "../data/sound-strings";
+ }
+#endif
+ ASSERT(false, ());
+}
+} // namespace
namespace platform
{
-GetTextById::GetTextById(string const & textsDir, string const & localeName)
+GetTextById::GetTextById(TextSource textSouce, string const & localeName)
{
- string const pathToJson = textsDir + "/" + localeName + ".json/localize.json";
+ string const pathToJson = my::JoinFoldersToPath({GetTextSourceString(textSouce),
+ localeName + ".json"}, "localize.json");
string jsonBuffer;
ReaderPtr<Reader>(GetPlatform().GetReader(pathToJson)).ReadAsString(jsonBuffer);
- if (jsonBuffer == "")
+ if (jsonBuffer.empty())
{
ASSERT(false, ("No json files found at the path", pathToJson));
return;
@@ -28,13 +54,13 @@ GetTextById::GetTextById(string const & textsDir, string const & localeName)
return;
}
- const char * key = nullptr;
+ char const * key = nullptr;
json_t * value = nullptr;
json_object_foreach(root.get(), key, value)
{
ASSERT(key, ());
ASSERT(value, ());
- const char * valueStr = json_string_value(value);
+ char const * const valueStr = json_string_value(value);
ASSERT(valueStr, ());
m_localeTexts[key] = valueStr;
}
diff --git a/platform/get_text_by_id.hpp b/platform/get_text_by_id.hpp
index d5dba5bc53..807025644e 100644
--- a/platform/get_text_by_id.hpp
+++ b/platform/get_text_by_id.hpp
@@ -6,13 +6,19 @@
namespace platform
{
+// class GetTextById is ready to work with different sources of text strings.
+// For the time being it's only strings for TTS.
+enum class TextSource
+{
+ TtsSound = 0
+};
/// GetTextById represents text messages which are saved in textsDir
/// in a specified locale.
class GetTextById
{
public:
- GetTextById(string const & textsDir, string const & localeName);
+ GetTextById(TextSource textSouce, string const & localeName);
bool IsValid() const { return !m_localeTexts.empty(); }
string operator()(string const & textId) const;
diff --git a/platform/platform_tests/get_text_by_id_tests.cpp b/platform/platform_tests/get_text_by_id_tests.cpp
index ab217f25f5..0d6113f825 100644
--- a/platform/platform_tests/get_text_by_id_tests.cpp
+++ b/platform/platform_tests/get_text_by_id_tests.cpp
@@ -2,47 +2,55 @@
#include "platform/get_text_by_id.hpp"
+
+using namespace platform;
+
UNIT_TEST(GetTextByIdEnglishTest)
{
- platform::GetTextById getEng("../data/sound-strings", "en");
- TEST_EQUAL(getEng("make_a_slight_right_turn"), "Make a slight right turn.", ());
- TEST_EQUAL(getEng("in_900_meters"), "In 900 meters.", ());
- TEST_EQUAL(getEng("then"), "Then.", ());
- TEST_EQUAL(getEng("in_one_mile"), "In one mile.", ());
+ platform::GetTextById getEnglish(TextSource::TtsSound, "en");
+ TEST_EQUAL(getEnglish("make_a_slight_right_turn"), "Make a slight right turn.", ());
+ TEST_EQUAL(getEnglish("in_900_meters"), "In 900 meters.", ());
+ TEST_EQUAL(getEnglish("then"), "Then.", ());
+ TEST_EQUAL(getEnglish("in_1_mile"), "In one mile.", ());
+ TEST_EQUAL(getEnglish("some_nonexistent_key"), "some_nonexistent_key", ());
}
UNIT_TEST(GetTextByIdRussianTest)
{
- platform::GetTextById getRussian("../data/sound-strings", "ru");
+ platform::GetTextById getRussian(TextSource::TtsSound, "ru");
TEST_EQUAL(getRussian("in_800_meters"), "Через 800 метров.", ());
TEST_EQUAL(getRussian("make_a_slight_right_turn"), "Плавный поворот направо.", ());
TEST_EQUAL(getRussian("take_the_6th_exit"), "6-й поворот с кольца.", ());
- TEST_EQUAL(getRussian("in_one_mile"), "Через одну милю.", ());
+ TEST_EQUAL(getRussian("in_1_mile"), "Через одну милю.", ());
+ TEST_EQUAL(getRussian("some_nonexistent_key"), "some_nonexistent_key", ());
}
UNIT_TEST(GetTextByIdKoreanTest)
{
- platform::GetTextById getKorean("../data/sound-strings", "ko");
+ platform::GetTextById getKorean(TextSource::TtsSound, "ko");
TEST_EQUAL(getKorean("in_700_meters"), "700 미터 앞", ());
TEST_EQUAL(getKorean("make_a_right_turn"), "우회전입니다.", ());
TEST_EQUAL(getKorean("take_the_5th_exit"), "다섯 번째 출구입니다.", ());
TEST_EQUAL(getKorean("in_5000_feet"), "5000피트 앞", ());
+ TEST_EQUAL(getKorean("some_nonexistent_key"), "some_nonexistent_key", ());
}
UNIT_TEST(GetTextByIdArabicTest)
{
- platform::GetTextById getArabic("../data/sound-strings", "ar");
- TEST_EQUAL(getArabic("in_one_kilometer"), "بعد كيلو متر واحدٍ", ());
+ platform::GetTextById getArabic(TextSource::TtsSound, "ar");
+ TEST_EQUAL(getArabic("in_1_kilometer"), "بعد كيلو متر واحدٍ", ());
TEST_EQUAL(getArabic("leave_the_roundabout"), "اخرج من الطريق الدوار", ());
- TEST_EQUAL(getArabic("take_the_third_exit"), "اسلك المخرج الثالث", ());
+ TEST_EQUAL(getArabic("take_the_3rd_exit"), "اسلك المخرج الثالث", ());
TEST_EQUAL(getArabic("in_4000_feet"), "بعد 4000 قدم", ());
+ TEST_EQUAL(getArabic("some_nonexistent_key"), "some_nonexistent_key", ());
}
UNIT_TEST(GetTextByIdFrenchTest)
{
- platform::GetTextById getFrench("../data/sound-strings", "fr");
- TEST_EQUAL(getFrench("in_one_and_a_half_kilometer"), "Dans un virgule cinq kilomètre.", ());
+ platform::GetTextById getFrench(TextSource::TtsSound, "fr");
+ TEST_EQUAL(getFrench("in_1_5_kilometers"), "Dans un virgule cinq kilomètre.", ());
TEST_EQUAL(getFrench("enter_the_roundabout"), "Prenez le rond-point.", ());
- TEST_EQUAL(getFrench("take_the_second_exit"), "Prenez la deuxième sortie.", ());
+ TEST_EQUAL(getFrench("take_the_2nd_exit"), "Prenez la deuxième sortie.", ());
TEST_EQUAL(getFrench("in_3500_feet"), "Dans 3500 feet.", ());
+ TEST_EQUAL(getFrench("some_nonexistent_key"), "some_nonexistent_key", ());
}