diff options
author | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:53:20 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:53:20 +0200 |
commit | 94db751716dd2851f99b5c4c2981da1d1f4780f8 (patch) | |
tree | e4ffc9f5ae2b2873f267a6e5d3d2092c8aad49a7 /zen/i18n.h | |
parent | 6.10 (diff) | |
download | FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.gz FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.bz2 FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.zip |
6.11
Diffstat (limited to 'zen/i18n.h')
-rw-r--r-- | zen/i18n.h | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -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<TranslationHandler>&& 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<TranslationHandler>& globalHandler() } inline -void setTranslator(TranslationHandler* newHandler) { implementation::globalHandler().reset(newHandler); } //takes ownership +void setTranslator(std::unique_ptr<TranslationHandler>&& newHandler) { implementation::globalHandler() = std::move(newHandler); } inline TranslationHandler* getTranslator() { return implementation::globalHandler().get(); } |