summaryrefslogtreecommitdiff
path: root/zen/i18n.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:01:58 +0200
committerDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:01:58 +0200
commit725e6e3c8e52ede0edec0fa15da3f148bb2f7d74 (patch)
tree739061fe661dc0bd1d200b0378365f3f47ff78be /zen/i18n.h
parent9.3 (diff)
downloadFreeFileSync-725e6e3c8e52ede0edec0fa15da3f148bb2f7d74.tar.gz
FreeFileSync-725e6e3c8e52ede0edec0fa15da3f148bb2f7d74.tar.bz2
FreeFileSync-725e6e3c8e52ede0edec0fa15da3f148bb2f7d74.zip
9.4
Diffstat (limited to 'zen/i18n.h')
-rwxr-xr-xzen/i18n.h68
1 files changed, 31 insertions, 37 deletions
diff --git a/zen/i18n.h b/zen/i18n.h
index c7d1d5dc..ebe22459 100755
--- a/zen/i18n.h
+++ b/zen/i18n.h
@@ -16,8 +16,8 @@
//minimal layer enabling text translation - without platform/library dependencies!
#define ZEN_TRANS_CONCAT_SUB(X, Y) X ## Y
-#define _(s) zen::implementation::translate(ZEN_TRANS_CONCAT_SUB(L, s))
-#define _P(s, p, n) zen::implementation::translate(ZEN_TRANS_CONCAT_SUB(L, s), ZEN_TRANS_CONCAT_SUB(L, p), n)
+#define _(s) zen::translate(ZEN_TRANS_CONCAT_SUB(L, s))
+#define _P(s, p, n) zen::translate(ZEN_TRANS_CONCAT_SUB(L, s), ZEN_TRANS_CONCAT_SUB(L, p), n)
//source and translation are required to use %x as number placeholder
//for plural form, which will be substituted automatically!!!
@@ -58,61 +58,55 @@ std::shared_ptr<const TranslationHandler> getTranslator();
namespace implementation
{
inline
-std::wstring translate(const std::wstring& text)
+Global<const TranslationHandler>& refGlobalTranslationHandler()
{
- if (std::shared_ptr<const TranslationHandler> t = getTranslator()) //std::shared_ptr => temporarily take (shared) ownership while using the interface!
- return t->translate(text);
- return text;
+ //getTranslator() may be called even after static objects of this translation unit are destroyed!
+ static Global<const TranslationHandler> inst; //external linkage even in header!
+ return inst;
+}
}
-
-//translate plural forms: "%x day" "%x days"
-//returns "1 day" if n == 1; "123 days" if n == 123 for english language
inline
-std::wstring translate(const std::wstring& singular, const std::wstring& plural, int64_t n)
+std::shared_ptr<const TranslationHandler> getTranslator()
{
- assert(contains(plural, L"%x"));
-
- if (std::shared_ptr<const TranslationHandler> t = getTranslator())
- {
- std::wstring translation = t->translate(singular, plural, n);
- assert(!contains(translation, L"%x"));
- return translation;
- }
-
- return replaceCpy(std::abs(n) == 1 ? singular : plural, L"%x", toGuiString(n));
+ return implementation::refGlobalTranslationHandler().get();
}
-template <class T> inline
-std::wstring translate(const std::wstring& singular, const std::wstring& plural, T n)
+inline
+void setTranslator(std::unique_ptr<const TranslationHandler>&& newHandler)
{
- static_assert(sizeof(n) <= sizeof(int64_t), "");
- return translate(singular, plural, static_cast<int64_t>(n));
+ implementation::refGlobalTranslationHandler().set(std::move(newHandler));
}
inline
-Global<const TranslationHandler>& refGlobalTranslationHandler()
+std::wstring translate(const std::wstring& text)
{
- //getTranslator() may be called even after static objects of this translation unit are destroyed!
- static Global<const TranslationHandler> inst; //external linkage even in header!
- return inst;
-}
+ if (std::shared_ptr<const TranslationHandler> t = getTranslator()) //std::shared_ptr => temporarily take (shared) ownership while using the interface!
+ return t->translate(text);
+ return text;
}
-inline
-void setTranslator(std::unique_ptr<const TranslationHandler>&& newHandler)
+//translate plural forms: "%x day" "%x days"
+//returns "1 day" if n == 1; "123 days" if n == 123 for english language
+template <class T> inline
+std::wstring translate(const std::wstring& singular, const std::wstring& plural, T n)
{
- implementation::refGlobalTranslationHandler().set(std::move(newHandler));
-}
+ static_assert(sizeof(n) <= sizeof(int64_t), "");
+ const auto n64 = static_cast<int64_t>(n);
+ assert(contains(plural, L"%x"));
-inline
-std::shared_ptr<const TranslationHandler> getTranslator()
-{
- return implementation::refGlobalTranslationHandler().get();
+ if (std::shared_ptr<const TranslationHandler> t = getTranslator())
+ {
+ std::wstring translation = t->translate(singular, plural, n64);
+ assert(!contains(translation, L"%x"));
+ return translation;
+ }
+ //fallback:
+ return replaceCpy(std::abs(n64) == 1 ? singular : plural, L"%x", toGuiString(n));
}
}
bgstack15