static SeedValue seed_gettext_dcngettext (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue args[], SeedException * exception) { gchar * domainname, * msgid, * msgid_plural; guint n; gint category; SeedValue ret; CHECK_ARG_COUNT("gettext.dcngettext", 5); domainname = seed_value_to_string (ctx, args[0], exception); msgid = seed_value_to_string (ctx, args[1], exception); msgid_plural = seed_value_to_string (ctx, args[2], exception); n = seed_value_to_uint (ctx, args[3], exception); category = seed_value_to_int (ctx, args[4], exception); ret = seed_value_from_string (ctx, dcngettext(domainname, msgid, msgid_plural, n, category), exception); g_free(domainname); g_free(msgid); g_free(msgid_plural); return ret; }
static uim_lisp intl_dcngettext(uim_lisp domainname, uim_lisp msgid1, uim_lisp msgid2, uim_lisp n, uim_lisp category) { return MAKE_STR(dcngettext(REFER_C_STR(domainname), REFER_C_STR(msgid1), REFER_C_STR(msgid2), C_INT(n), C_INT(category))); }
const char *npgettext( const char *const context, const char *const msgid, const char *const msgid_plural, const unsigned long int n ) { const std::string context_id = std::string( context ) + '\004' + msgid; const char *const msg_ctxt_id = context_id.c_str(); const char *const translation = dcngettext( nullptr, msg_ctxt_id, msgid_plural, n, LC_MESSAGES ); if( translation == msg_ctxt_id ) { return n == 1 ? msgid : msgid_plural; } else { return translation; } }
Variant HHVM_FUNCTION(dcngettext, const String& domain, const String& msgid1, const String& msgid2, int64_t count, int64_t category) { CHECK_DOMAIN_LENGTH(); CHECK_GETTEXT_LENGTH("msgid1", msgid1.length()); CHECK_GETTEXT_LENGTH("msgid2", msgid2.length()); auto msgstr = dcngettext(domain.data(), msgid1.data(), msgid2.data(), count, category); if (!msgstr) { return false; } return String(msgstr, CopyString); }
static inline object do_ngettext (const char* msgid, const char* msgid_plural, const char* domain, uint32 n, int category) { const char* translated_msg; begin_system_call(); # ifdef CLISP_UNICODE if (domain != NULL) bind_textdomain_codeset(domain,"UTF-8"); # endif translated_msg = dcngettext(domain,msgid,msgid_plural,n,category); end_system_call(); return asciz_to_string(translated_msg,Symbol_value(S(utf_8))); }
static int do_test (void) { const char *strs[2] = { "singular", "plural" }; unsigned long int i; int res = 0; /* We don't want any translation here. */ setenv ("LANGUAGE", "C", 1); unsetenv ("OUTPUT_CHARSET"); for (i = 0; i < 30; ++i) { char *tr; tr = ngettext (strs[0], strs[1], i); #define TEST \ do \ if (tr != strs[i != 1]) \ { \ if (strcmp (tr, strs[i != 1]) == 0) \ printf ("%lu: correct string, wrong pointer (%s)\n", i, tr); \ else \ printf ("%lu: wrong result (%s)\n", i, tr); \ res = 1; \ } \ while (0) TEST; tr = dngettext ("messages", strs[0], strs[1], i); TEST; tr = dcngettext ("messages", strs[0], strs[1], i, LC_MESSAGES); TEST; } return res; }
static int intl_ctl(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen) { void* d = (void*)drv_data; char* aptr = buf; int alen = len; char* str1; char* str2; char* str3; int int1; int int2; unsigned int uint1; switch(command) { case INTL_GETTEXT: /* arguments: string msgid */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(gettext(str1), rbuf, rlen); case INTL_NGETTEXT: /* arguments: string msgid, string msgid_plural, int n */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr, &alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(ngettext(str1,str2,uint1), rbuf, rlen); case INTL_DGETTEXT: /* arguments: string domain, string msgid */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dgettext(str1,str2), rbuf, rlen); case INTL_DNGETTEXT: /* arguments: string domain, string msgid, string msgid_plural, integer n */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str3) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr, &alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dngettext(str1,str2,str3,uint1), rbuf, rlen); case INTL_DCGETTEXT: /* arguments: string domain, string msgid, int category */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dcgettext(str1,str2,int1),rbuf,rlen); case INTL_DCNGETTEXT: /* arguments: string domain, string msgid, strinf msgid_plural, unsigned n, int category */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str3) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr,&alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dcngettext(str1,str2,str3,uint1,int1),rbuf,rlen); case INTL_TEXTDOMAIN: /* arguments: string domainname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(textdomain(str1), rbuf, rlen); case INTL_BINDTEXTDOMAIN: /* arguments: string domainname, string dirname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(bindtextdomain(str1,str2), rbuf, rlen); case INTL_BIND_TEXTDOMAIN_CODESET: /* arguments: string domainname, string dirname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(bind_textdomain_codeset(str1,str2), rbuf, rlen); case INTL_SETLOCALE: if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(setlocale(int1,str1), rbuf, rlen); } return -1; }
char *dgettext(const char *domainname, const char *msgid) { return dcngettext(domainname, msgid, 0, 1, LC_MESSAGES); }
char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES); }
char *dcgettext(const char *domainname, const char *msgid, int category) { return dcngettext(domainname, msgid, 0, 1, category); }