wcstring wgettext2(const wcstring &in) { wgettext_init_if_necessary(); std::string mbs_in = wcs2string(in); char *out = gettext(mbs_in.c_str()); wcstring result = format_string(L"%s", out); return result; }
const wcstring &wgettext(const wchar_t *in) { // Preserve errno across this since this is often used in printing error messages. int err = errno; wcstring key = in; wgettext_init_if_necessary(); auto wmap = wgettext_map.acquire(); wcstring &val = wmap.value[key]; if (val.empty()) { cstring mbs_in = wcs2string(key); char *out = fish_gettext(mbs_in.c_str()); val = format_string(L"%s", out); } errno = err; // The returned string is stored in the map. // TODO: If we want to shrink the map, this would be a problem. return val; }
const wchar_t *wgettext(const wchar_t *in) { if (!in) return in; // preserve errno across this since this is often used in printing error messages int err = errno; wgettext_init_if_necessary(); wcstring key = in; scoped_lock lock(wgettext_lock); wcstring *& val = wgettext_map[key]; if (val == NULL) { cstring mbs_in = wcs2string(key); char *out = gettext(mbs_in.c_str()); val = new wcstring(format_string(L"%s", out)); } errno = err; return val->c_str(); }
const wchar_t *wgettext(const wchar_t *in) { if (!in) return in; // preserve errno across this since this is often used in printing error messages int err = errno; wgettext_init_if_necessary(); wcstring key = in; scoped_lock lock(wgettext_lock); wcstring *& val = wgettext_map[key]; if (val == NULL) { cstring mbs_in = wcs2string(key); char *out = fish_gettext(mbs_in.c_str()); val = new wcstring(format_string(L"%s", out)); //note that this writes into the map! } errno = err; return val->c_str(); //looks dangerous but is safe, since the string is stored in the map }