summaryrefslogtreecommitdiff
path: root/zen/i18n.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2015-10-02 14:53:20 +0200
committerDaniel Wilhelm <daniel@wili.li>2015-10-02 14:53:20 +0200
commit94db751716dd2851f99b5c4c2981da1d1f4780f8 (patch)
treee4ffc9f5ae2b2873f267a6e5d3d2092c8aad49a7 /zen/i18n.h
parent6.10 (diff)
downloadFreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.gz
FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.tar.bz2
FreeFileSync-94db751716dd2851f99b5c4c2981da1d1f4780f8.zip
6.11
Diffstat (limited to 'zen/i18n.h')
-rw-r--r--zen/i18n.h15
1 files changed, 9 insertions, 6 deletions
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<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(); }
bgstack15