From 94db751716dd2851f99b5c4c2981da1d1f4780f8 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:53:20 +0200 Subject: 6.11 --- zen/i18n.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'zen/i18n.h') diff --git a/zen/i18n.h b/zen/i18n.h index 3790e528..bf284c7f 100644 --- a/zen/i18n.h +++ b/zen/i18n.h @@ -37,7 +37,7 @@ struct TranslationHandler virtual std::wstring translate(const std::wstring& singular, const std::wstring& plural, std::int64_t n) = 0; }; -void setTranslator(TranslationHandler* newHandler = nullptr); //takes ownership +void setTranslator(std::unique_ptr&& newHandler = nullptr); //take ownership TranslationHandler* getTranslator(); @@ -58,7 +58,10 @@ namespace implementation inline std::wstring translate(const std::wstring& text) { - return getTranslator() ? getTranslator()->translate(text) : text; + if (TranslationHandler* t = getTranslator()) + return t->translate(text); + + return text; } //translate plural forms: "%x day" "%x days" @@ -68,13 +71,13 @@ std::wstring translate(const std::wstring& singular, const std::wstring& plural, { assert(contains(plural, L"%x")); - if (getTranslator()) + if (TranslationHandler* t = getTranslator()) { - std::wstring translation = getTranslator()->translate(singular, plural, n); + std::wstring translation = t->translate(singular, plural, n); assert(!contains(translation, L"%x")); return translation; } - else + return replaceCpy(std::abs(n) == 1 ? singular : plural, L"%x", toGuiString(n)); } @@ -94,7 +97,7 @@ std::unique_ptr& globalHandler() } inline -void setTranslator(TranslationHandler* newHandler) { implementation::globalHandler().reset(newHandler); } //takes ownership +void setTranslator(std::unique_ptr&& newHandler) { implementation::globalHandler() = std::move(newHandler); } inline TranslationHandler* getTranslator() { return implementation::globalHandler().get(); } -- cgit