Use LC_TIME locale for strftime format string translations
We commonly mark strftime format strings for translation to account for date/time representations without an existing strftime shortcut ("Yesterday %H%p"). As those translations are looked up according to the locale defined by LC_MESSAGES, while the conversion characters themselves are resolved according to LC_TIME, the result can be rather odd when mixing locales ("Den 27. January"). The correct solution would be to install translations for format strings in the LC_TIME catalogue and look them up with dcgettext(), but we don't have the infrastructure to do that easily. Work around this by adding a helper method that looks up a string in LC_MESSAGES using the locale defined by LC_TIME and use that to translate format strings, which has the same result. https://bugzilla.gnome.org/show_bug.cgi?id=738640
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
|
||||
#include <locale.h>
|
||||
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
@ -208,6 +209,32 @@ shell_util_get_week_start ()
|
||||
return week_start;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_util_translate_time_string:
|
||||
* @str: String to translate
|
||||
*
|
||||
* Translate @str according to the locale defined by LC_TIME; unlike
|
||||
* dcgettext(), the translations is still taken from the LC_MESSAGES
|
||||
* catalogue and not the LC_TIME one.
|
||||
*
|
||||
* Returns: the translated string
|
||||
*/
|
||||
const char *
|
||||
shell_util_translate_time_string (const char *str)
|
||||
{
|
||||
const char *locale = g_getenv ("LC_TIME");
|
||||
const char *res;
|
||||
|
||||
if (locale)
|
||||
setlocale (LC_MESSAGES, locale);
|
||||
|
||||
res = gettext (str);
|
||||
|
||||
setlocale (LC_MESSAGES, "");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_write_string_to_stream:
|
||||
* @stream: a #GOutputStream
|
||||
|
@ -21,6 +21,7 @@ int shell_util_get_week_start (void);
|
||||
|
||||
char *shell_util_format_date (const char *format,
|
||||
gint64 time_ms);
|
||||
const char *shell_util_translate_time_string (const char *str);
|
||||
|
||||
gboolean shell_write_string_to_stream (GOutputStream *stream,
|
||||
const char *str,
|
||||
|
Reference in New Issue
Block a user