summaryrefslogtreecommitdiff
path: root/zen/i18n.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:16 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:16 +0200
commitbd6336c629841c6db3a6ca53a936d629d34db53b (patch)
tree3721ef997864108df175ce677a8a7d4342a6f1d2 /zen/i18n.h
parent4.0 (diff)
downloadFreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.tar.gz
FreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.tar.bz2
FreeFileSync-bd6336c629841c6db3a6ca53a936d629d34db53b.zip
4.1
Diffstat (limited to 'zen/i18n.h')
-rw-r--r--zen/i18n.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/zen/i18n.h b/zen/i18n.h
new file mode 100644
index 00000000..de615cdb
--- /dev/null
+++ b/zen/i18n.h
@@ -0,0 +1,96 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+
+#ifndef I18_N_HEADER_3843489325045
+#define I18_N_HEADER_3843489325045
+
+#include <string>
+#include <memory>
+
+//thin layer to enable localization - without platform/library dependencies!
+#ifndef WXINTL_NO_GETTEXT_MACRO
+#error WXINTL_NO_GETTEXT_MACRO must be defined to deactivate wxWidgets underscore macro
+#endif
+
+#define ZEN_CONCAT_SUB(X, Y) X ## Y
+#define _(s) zen::implementation::translate(ZEN_CONCAT_SUB(L, s))
+#define _P(s, p, n) zen::implementation::translate(ZEN_CONCAT_SUB(L, s), ZEN_CONCAT_SUB(L, p), n)
+
+
+namespace zen
+{
+//implement handler to enable program wide localizations
+struct TranslationHandler
+{
+ virtual ~TranslationHandler() {}
+
+ virtual std::wstring thousandsSeparator() = 0;
+ virtual std::wstring translate(const std::wstring& text) = 0; //simple translation
+ virtual std::wstring translate(const std::wstring& singular, const std::wstring& plural, int n) = 0;
+};
+
+void setTranslator(TranslationHandler* newHandler = NULL); //takes ownership
+TranslationHandler* getTranslator();
+
+inline
+std::wstring getThousandsSeparator() { return getTranslator() ? getTranslator()->thousandsSeparator() : L","; };
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+//######################## implementation ##############################
+namespace implementation
+{
+inline
+std::wstring translate(const std::wstring& text)
+{
+ return getTranslator() ? getTranslator()->translate(text) : text;
+}
+
+//translate plural forms: "%x day" "%x days"
+//returns "%x day" if n == 1; "%x days" else for english language
+inline
+std::wstring translate(const std::wstring& singular, const std::wstring& plural, int n)
+{
+ return getTranslator() ? getTranslator()->translate(singular, plural, n) : n == 1 ? singular : plural;
+}
+
+template <class T> inline
+std::wstring translate(const std::wstring& singular, const std::wstring& plural, T n)
+{
+ return translate(singular, plural, static_cast<int>(n % 1000000));
+}
+
+inline
+std::unique_ptr<TranslationHandler>& globalHandler()
+{
+ static std::unique_ptr<TranslationHandler> inst; //external linkage even in header!
+ return inst;
+}
+}
+
+inline
+void setTranslator(TranslationHandler* newHandler) { implementation::globalHandler().reset(newHandler); } //takes ownership
+
+inline
+TranslationHandler* getTranslator() { return implementation::globalHandler().get(); }
+}
+
+#endif //I18_N_HEADER_3843489325045
bgstack15