diff options
-rw-r--r-- | map/framework.hpp | 4 | ||||
-rw-r--r-- | platform/get_text_by_id.cpp | 29 | ||||
-rw-r--r-- | platform/get_text_by_id.hpp | 19 | ||||
-rw-r--r-- | platform/platform_tests/get_text_by_id_tests.cpp | 10 | ||||
-rw-r--r-- | routing/turns_tts_text.cpp | 2 | ||||
-rw-r--r-- | routing/turns_tts_text.hpp | 7 |
6 files changed, 39 insertions, 32 deletions
diff --git a/map/framework.hpp b/map/framework.hpp index c6799e26a7..fa96242462 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -605,10 +605,12 @@ public: inline bool AreTurnNotificationsEnabled() const { return m_routingSession.AreTurnNotificationsEnabled(); } /// \brief Sets a locale for TTS. /// \param locale is a string with locale code. For example "en", "ru", "zh-Hant" and so on. - /// See sound/tts/languages.txt for the full list. + /// \note ee sound/tts/languages.txt for the full list of available locales. inline void SetTurnNotificationsLocale(string const & locale) { m_routingSession.SetTurnNotificationsLocale(locale); } /// @return current TTS locale. For example "en", "ru", "zh-Hant" and so on. /// In case of error returns an empty string. + /// \note The method returns correct locale after SetTurnNotificationsLocale has been called. + /// If not, it returns an empty string. inline string GetTurnNotificationsLocale() const { return m_routingSession.GetTurnNotificationsLocale(); } /// \brief When an end user is going to a turn he gets sound turn instructions. /// If C++ part wants the client to pronounce an instruction GenerateTurnSound (in turnNotifications) returns diff --git a/platform/get_text_by_id.cpp b/platform/get_text_by_id.cpp index a14da57200..c9b715c375 100644 --- a/platform/get_text_by_id.cpp +++ b/platform/get_text_by_id.cpp @@ -13,16 +13,16 @@ namespace { string const kDefaultLanguage = "en"; -string GetTextSourceString(platform::TextSource textSouce) +string GetTextSourceString(platform::TextSource textSource) { #if defined(OMIM_OS_ANDROID) || defined(OMIM_OS_IPHONE) - switch (textSouce) + switch (textSource) { case platform::TextSource::TtsSound: return "sound-strings"; } #else - switch (textSouce) + switch (textSource) { case platform::TextSource::TtsSound: return "../data/sound-strings"; @@ -31,10 +31,10 @@ string GetTextSourceString(platform::TextSource textSouce) ASSERT(false, ()); } -bool GetJsonBuffer(platform::TextSource textSouce, string const & localeName, string & jsonBuffer) +bool GetJsonBuffer(platform::TextSource textSource, string const & localeName, string & jsonBuffer) { string const pathToJson = my::JoinFoldersToPath( - {GetTextSourceString(textSouce), localeName + ".json"}, "localize.json"); + {GetTextSourceString(textSource), localeName + ".json"}, "localize.json"); try { @@ -53,10 +53,10 @@ bool GetJsonBuffer(platform::TextSource textSouce, string const & localeName, st namespace platform { -unique_ptr<GetTextById> MakeGetTextById(string const & jsonBuffer, string const & localeName) +TGetTextByIdPtr MakeGetTextById(string const & jsonBuffer, string const & localeName) { - unique_ptr<GetTextById> result(new GetTextById(jsonBuffer, localeName)); - if (!result || !result->IsValid()) + TGetTextByIdPtr result(new GetTextById(jsonBuffer, localeName)); + if (!result->IsValid()) { ASSERT(false, ()); return nullptr; @@ -64,20 +64,20 @@ unique_ptr<GetTextById> MakeGetTextById(string const & jsonBuffer, string const return result; } -unique_ptr<GetTextById> GetTextByIdFactory(TextSource textSouce, string const & localeName) +TGetTextByIdPtr GetTextByIdFactory(TextSource textSource, string const & localeName) { string jsonBuffer; - if (GetJsonBuffer(textSouce, localeName, jsonBuffer)) + if (GetJsonBuffer(textSource, localeName, jsonBuffer)) return MakeGetTextById(jsonBuffer, localeName); - if (GetJsonBuffer(textSouce, kDefaultLanguage, jsonBuffer)) + if (GetJsonBuffer(textSource, kDefaultLanguage, jsonBuffer)) return MakeGetTextById(jsonBuffer, kDefaultLanguage); ASSERT(false, ("sound.txt does not contain default language.")); return nullptr; } -unique_ptr<GetTextById> ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName) +TGetTextByIdPtr ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName) { return MakeGetTextById(jsonBuffer, localeName); } @@ -117,12 +117,9 @@ void GetTextById::InitFromJson(string const & jsonBuffer) string GetTextById::operator()(string const & textId) const { - if (!IsValid()) - return string(); - auto const textIt = m_localeTexts.find(textId); if (textIt == m_localeTexts.end()) - return ""; + return string(); return textIt->second; } } // namespace platform diff --git a/platform/get_text_by_id.hpp b/platform/get_text_by_id.hpp index 50c5184a46..ff644e37d3 100644 --- a/platform/get_text_by_id.hpp +++ b/platform/get_text_by_id.hpp @@ -14,6 +14,9 @@ enum class TextSource TtsSound = 0 }; +class GetTextById; +typedef unique_ptr<GetTextById> TGetTextByIdPtr; + /// GetTextById represents text messages which are saved in textsDir /// in a specified locale. class GetTextById @@ -25,9 +28,9 @@ public: string operator()(string const & textId) const; string GetLocale() const { return m_locale; } private: - friend unique_ptr<GetTextById> GetTextByIdFactory(TextSource textSouce, string const & localeName); - friend unique_ptr<GetTextById> ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); - friend unique_ptr<GetTextById> MakeGetTextById(string const & jsonBuffer, string const & localeName); + friend TGetTextByIdPtr GetTextByIdFactory(TextSource textSource, string const & localeName); + friend TGetTextByIdPtr ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); + friend TGetTextByIdPtr MakeGetTextById(string const & jsonBuffer, string const & localeName); GetTextById(string const & jsonBuffer, string const & localeName); void InitFromJson(string const & jsonBuffer); @@ -38,11 +41,11 @@ private: unordered_map<string, string> m_localeTexts; }; -/// Factoris to create intances of GetTextById. -/// If unique_ptr<GetTextById> is created by GetTextByIdFactory or ForTestingGetTextByIdFactory -/// threre are only two possibities. +/// Factories to create GetTextById instances. +/// If TGetTextByIdPtr is created by GetTextByIdFactory or ForTestingGetTextByIdFactory +/// threre are only two possibities: /// * a factory returns a valid instance /// * a factory returns nullptr -unique_ptr<GetTextById> GetTextByIdFactory(TextSource textSouce, string const & localeName); -unique_ptr<GetTextById> ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); +TGetTextByIdPtr GetTextByIdFactory(TextSource textSource, string const & localeName); +TGetTextByIdPtr ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); } // namespace platform diff --git a/platform/platform_tests/get_text_by_id_tests.cpp b/platform/platform_tests/get_text_by_id_tests.cpp index b1eff8f3a9..395199908c 100644 --- a/platform/platform_tests/get_text_by_id_tests.cpp +++ b/platform/platform_tests/get_text_by_id_tests.cpp @@ -15,7 +15,7 @@ UNIT_TEST(GetTextByIdEnglishTest) \"in_1_mile\":\"In one mile.\"\ }"; - unique_ptr<platform::GetTextById> getEnglish = platform::ForTestingGetTextByIdFactory(shortJson, "en"); + auto getEnglish = platform::ForTestingGetTextByIdFactory(shortJson, "en"); TEST_EQUAL((*getEnglish)("make_a_slight_right_turn"), "Make a slight right turn.", ()); TEST_EQUAL((*getEnglish)("in_900_meters"), "In nine hundred meters.", ()); TEST_EQUAL((*getEnglish)("then"), "Then.", ()); @@ -38,7 +38,7 @@ UNIT_TEST(GetTextByIdRussianTest) \"in_1_mile\":\"Через одну милю.\"\ }"; - unique_ptr<platform::GetTextById> getRussian = platform::ForTestingGetTextByIdFactory(shortJson, "ru"); + auto getRussian = platform::ForTestingGetTextByIdFactory(shortJson, "ru"); TEST_EQUAL((*getRussian)("in_800_meters"), "Через восемьсот метров.", ()); TEST_EQUAL((*getRussian)("make_a_slight_right_turn"), "Плавный поворот направо.", ()); TEST_EQUAL((*getRussian)("take_the_6th_exit"), "Шестой поворот с кольца.", ()); @@ -61,7 +61,7 @@ UNIT_TEST(GetTextByIdKoreanTest) \"in_5000_feet\":\"5000피트 앞\"\ }"; - unique_ptr<platform::GetTextById> getKorean = platform::ForTestingGetTextByIdFactory(shortJson, "ko"); + auto getKorean = platform::ForTestingGetTextByIdFactory(shortJson, "ko"); TEST_EQUAL((*getKorean)("in_700_meters"), "700 미터 앞", ()); TEST_EQUAL((*getKorean)("make_a_right_turn"), "우회전입니다.", ()); TEST_EQUAL((*getKorean)("take_the_5th_exit"), "다섯 번째 출구입니다.", ()); @@ -84,7 +84,7 @@ UNIT_TEST(GetTextByIdArabicTest) \"in_4000_feet\":\"بعد 4000 قدم\"\ }"; - unique_ptr<platform::GetTextById> getArabic = platform::ForTestingGetTextByIdFactory(shortJson, "ar"); + auto getArabic = platform::ForTestingGetTextByIdFactory(shortJson, "ar"); TEST_EQUAL((*getArabic)("in_1_kilometer"), "بعد كيلو متر واحدٍ", ()); TEST_EQUAL((*getArabic)("leave_the_roundabout"), "اخرج من الطريق الدوار", ()); TEST_EQUAL((*getArabic)("take_the_3rd_exit"), "اسلك المخرج الثالث", ()); @@ -107,7 +107,7 @@ UNIT_TEST(GetTextByIdFrenchTest) \"in_3500_feet\":\"Dans trois mille cinq cents pieds.\"\ }"; - unique_ptr<platform::GetTextById> getFrench = platform::ForTestingGetTextByIdFactory(shortJson, "fr"); + auto getFrench = platform::ForTestingGetTextByIdFactory(shortJson, "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_2nd_exit"), "Prenez la deuxième sortie.", ()); diff --git a/routing/turns_tts_text.cpp b/routing/turns_tts_text.cpp index cb2e302d32..6932c710d0 100644 --- a/routing/turns_tts_text.cpp +++ b/routing/turns_tts_text.cpp @@ -37,13 +37,11 @@ namespace sound void GetTtsText::SetLocale(string const & locale) { m_getCurLang = platform::GetTextByIdFactory(platform::TextSource::TtsSound, locale); - ASSERT(m_getCurLang, ()); } void GetTtsText::ForTestingSetLocaleWithJson(string const & jsonBuffer, string const & locale) { m_getCurLang = platform::ForTestingGetTextByIdFactory(jsonBuffer, locale); - ASSERT(m_getCurLang, ()); } string GetTtsText::operator()(Notification const & notification) const diff --git a/routing/turns_tts_text.hpp b/routing/turns_tts_text.hpp index 880da596c7..89154d0335 100644 --- a/routing/turns_tts_text.hpp +++ b/routing/turns_tts_text.hpp @@ -22,8 +22,15 @@ class GetTtsText { public: string operator()(Notification const & notification) const; + /// \brief Sets a locale. + /// @param locale is a string representation of locale. For example "en", "ru", "zh-Hant" and so on. + /// \note ee sound/tts/languages.txt for the full list of available locales. void SetLocale(string const & locale); + /// @return current TTS locale. For example "en", "ru", "zh-Hant" and so on. + /// \note The method returns correct locale after SetLocale has been called. + /// If not, it returns an empty string. string GetLocale() const; + void ForTestingSetLocaleWithJson(string const & jsonBuffer, string const & locale); private: |