diff --git a/es-core/src/utils/LocalizationUtil.cpp b/es-core/src/utils/LocalizationUtil.cpp index 6ade92aeb..980dbbf62 100644 --- a/es-core/src/utils/LocalizationUtil.cpp +++ b/es-core/src/utils/LocalizationUtil.cpp @@ -43,6 +43,35 @@ namespace Utils // clang-format on float sMenuTitleScaleFactor {1.0f}; + const char* pgettextBuiltin(const char* msgctxt, const char* msgid) + { + // This is an unbelievable hack but it's actually done pretty much the same way in + // the gettext.h header where a macro is used to wrap around the libintl functionality. + // Why this function is simply not part of libintl itself is anyone's guess, as that + // would be the logical thing to do. + std::string lookup; + lookup.append(msgctxt).append("\004").append(msgid); + const char* translation = gettext(lookup.c_str()); + if (translation == lookup.c_str()) + return msgid; + else + return translation; + } + + const char* npgettextBuiltin(const char* msgctxt, + const char* msgid1, + const char* msgid2, + unsigned long int n) + { + std::string lookup; + lookup.append(msgctxt).append("\004").append(msgid1); + const char* translation = ngettext(lookup.c_str(), msgid2, n); + if (translation == lookup.c_str()) + return msgid1; + else + return translation; + } + std::pair getLocale() { #if defined(_WIN64) diff --git a/es-core/src/utils/LocalizationUtil.h b/es-core/src/utils/LocalizationUtil.h index 39bd03452..05a131410 100644 --- a/es-core/src/utils/LocalizationUtil.h +++ b/es-core/src/utils/LocalizationUtil.h @@ -16,6 +16,8 @@ #define _(STR) std::string(gettext(STR)) #define _n(STR1, STR2, NUM) std::string(ngettext(STR1, STR2, NUM)) +#define _p(STR1, STR2) Utils::Localization::pgettextBuiltin(STR1, STR2) +#define _np(STR1, STR2, STR3, NUM) Utils::Localization::npgettextBuiltin(STR1, STR2, STR3, NUM) namespace Utils { @@ -24,6 +26,11 @@ namespace Utils extern const std::vector> sSupportedLocales; extern float sMenuTitleScaleFactor; + const char* pgettextBuiltin(const char* msgctxt, const char* msgid); + const char* npgettextBuiltin(const char* msgctxt, + const char* msgid1, + const char* msgid2, + unsigned long int n); std::pair getLocale(); void setLocale(); diff --git a/tools/update_translation_strings.sh b/tools/update_translation_strings.sh index ae5504920..a62ec11d2 100755 --- a/tools/update_translation_strings.sh +++ b/tools/update_translation_strings.sh @@ -23,7 +23,7 @@ if [ ! $(which xgettext 2>/dev/null) ]; then exit fi -find ../es-app/src/ ../es-core/src -name '*.cpp' -o -name '*.h' | xgettext -f - -o ../locale/es-de.pot -k_ -k_n:1,2 --no-location \ +find ../es-app/src/ ../es-core/src -name '*.cpp' -o -name '*.h' | xgettext -f - -o ../locale/es-de.pot -k_ -k_n:1,2 -k_p:1c,2 -k_np:1c,2,3 --no-location \ --copyright-holder="Northwestern Software AB" --package-name="ES-DE Frontend" --msgid-bugs-address "info@es-de.org" sed -i "1s/.*/# ES-DE Frontend translation strings./" ../locale/es-de.pot