diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/pbd/convert.cc | 15 | ||||
-rw-r--r-- | libs/pbd/pbd/convert.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/libs/pbd/convert.cc b/libs/pbd/convert.cc index bda0683910..02d7f3c0a4 100644 --- a/libs/pbd/convert.cc +++ b/libs/pbd/convert.cc @@ -22,6 +22,7 @@ #include <stdlib.h> #include <cstdio> #include <ctype.h> +#include <cstring> #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif @@ -325,5 +326,19 @@ strings_equal_ignore_case (const string& a, const string& b) return false; } +/** A wrapper for dgettext that takes a msgid of the form Context|Text. + * If Context|Text is translated, the translation is returned, otherwise + * just Text is returned. Useful for getting translations of words or phrases + * that have different meanings in different contexts. + */ +const char * +sgettext (const char* domain_name, const char* msgid) +{ + const char * msgval = dgettext (domain_name, msgid); + if (msgval == msgid) { + msgval = strrchr (msgid, '|') + 1; + } + return msgval; +} } // namespace PBD diff --git a/libs/pbd/pbd/convert.h b/libs/pbd/pbd/convert.h index cbc898011d..7bf922e94f 100644 --- a/libs/pbd/pbd/convert.h +++ b/libs/pbd/pbd/convert.h @@ -54,6 +54,9 @@ to_string (T t, std::ios_base & (*f)(std::ios_base&)) return oss.str(); } +const char * +sgettext (const char *, const char *); + } //namespace PBD #endif /* __pbd_convert_h__ */ |