2929#include < libintl.h>
3030
3131#define GETTEXT_CONTEXT_SEPARATOR " \004 "
32- #define _ (String ) dgettext( ::Nickvision::Localization::Gettext::getDomainName().c_str(), String)
33- #define _n (String, StringPlural, N ) dngettext( ::Nickvision::Localization::Gettext::getDomainName().c_str(), String, StringPlural, static_cast <unsigned long >(N))
32+ #define _ (String ) ::Nickvision::Localization::Gettext::dgettext( String)
33+ #define _n (String, StringPlural, N ) ::Nickvision::Localization::Gettext::dngettext( String, StringPlural, static_cast <unsigned long >(N))
3434#define _f (String, ...) ::Nickvision::Localization::Gettext::fgettext(String, __VA_ARGS__)
3535#define _fn (String, StringPlural, N, ...) ::Nickvision::Localization::Gettext::fngettext(String, StringPlural, static_cast <unsigned long >(N), __VA_ARGS__)
3636#define _p (Context, String ) ::Nickvision::Localization::Gettext::pgettext(Context GETTEXT_CONTEXT_SEPARATOR String, String)
@@ -57,31 +57,47 @@ namespace Nickvision::Localization::Gettext
5757 const std::vector<std::string>& getAvailableLanguages ();
5858 /* *
5959 * @brief Changes the current language for gettext translations.
60- * @param language The language code to change translations to (use "C" to turn off translations and use the default language)
60+ * @param language The language code to change translations to (use "C" to turn off translations; use "" to use the system default language)
6161 * @return True if the language was changed successfully, else false
6262 */
6363 bool changeLanguage (const std::string& language);
64+ /* *
65+ * @brief Translates a message.
66+ * @param msgid The message to translate
67+ * @return The translated message
68+ */
69+ const char * dgettext (const char * msgid);
70+ /* *
71+ * @brief Translates a plural message.
72+ * @param msg The message to translate
73+ * @param msgPlural The plural version of the message to translate
74+ * @param n The number of objects (used to determine whether or not to use the plural version of the message)
75+ * @return The translated message for the given number of objects
76+ */
77+ const char * dngettext (const char * msg, const char * msgPlural, unsigned long n);
6478 /* *
6579 * @brief Translates a message and formats it with the given arguments.
6680 * @param msg The message to translate
6781 * @param args The arguments to format the translated message with
82+ * @return The formatted translated message
6883 */
6984 template <typename ... Args>
7085 std::string fgettext (const char * msg, Args&&... args)
7186 {
72- return std::vformat (_ (msg), std::make_format_args (args...));
87+ return std::vformat (Nickvision::Localization::Gettext::dgettext (msg), std::make_format_args (args...));
7388 }
7489 /* *
7590 * @brief Translates a plural message and formats it with the given arguments.
7691 * @param msg The message to translate
7792 * @param msgPlural The plural version of the message to translate
7893 * @param n The number of objects (used to determine whether or not to use the plural version of the message)
7994 * @param args The arguments to format the translated message with
95+ * @return The formatted translated message for the given number of objects
8096 */
8197 template <typename ... Args>
8298 std::string fngettext (const char * msg, const char * msgPlural, unsigned long n, Args&&... args)
8399 {
84- return std::vformat (_n (msg, msgPlural, n), std::make_format_args (args...));
100+ return std::vformat (Nickvision::Localization::Gettext::dngettext (msg, msgPlural, n), std::make_format_args (args...));
85101 }
86102 /* *
87103 * @brief Translates a message for a given context.
0 commit comments