Merge lp:~mterry/indicator-datetime/lc-time-fixes into lp:indicator-datetime/0.3

Proposed by Michael Terry
Status: Merged
Merged at revision: 29
Proposed branch: lp:~mterry/indicator-datetime/lc-time-fixes
Merge into: lp:indicator-datetime/0.3
Diff against target: 183 lines (+76/-26)
3 files modified
data/org.ayatana.indicator.datetime.gschema.xml (+1/-1)
po/Makevars (+7/-0)
src/indicator-datetime.c (+68/-25)
To merge this branch: bzr merge lp:~mterry/indicator-datetime/lc-time-fixes
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+43793@code.launchpad.net

Description of the change

This branch does several locale/time-related things:

 * Uses N_ on DEFAULT_TIME_12_FORMAT and DEFAULT_TIME_24_FORMAT so they will appear in the pot file
 * Adds a is_locale_12h function so that we don't have to rely on translators to determine if the locale is 12 or 24 hours
 * Adds a T_ function to translate a string according to the locale specified by LC_TIME, not the one specified by LC_MESSAGES. This means that when the user sets their preferred time locale in gnome-language-selector (for example), indicator-datetime will respect that when looking up time-related translations.
 * Added a po/Makevars to pass --keyword=T_ to xgettext
 * Fixes a minor typo in the gsettings schema

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

Wow, very cool. Only comment is that g_setenv's third parameter should really be TRUE/FALSE instead of an int. I'll fix that on merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/org.ayatana.indicator.datetime.gschema.xml'
--- data/org.ayatana.indicator.datetime.gschema.xml 2010-07-15 20:02:17 +0000
+++ data/org.ayatana.indicator.datetime.gschema.xml 2010-12-15 17:02:56 +0000
@@ -13,7 +13,7 @@
13 Controls the time format that is displayed in the indicator. For almost13 Controls the time format that is displayed in the indicator. For almost
14 all users this should be the default for their locale. If you think the14 all users this should be the default for their locale. If you think the
15 setting is wrong for your locale please join or talk to the translation15 setting is wrong for your locale please join or talk to the translation
16 team for your langauge. If you just want something different you can16 team for your language. If you just want something different you can
17 adjust this to be either 12 or 24 time. Or, you can use a custom format17 adjust this to be either 12 or 24 time. Or, you can use a custom format
18 string and set the custom-time-format setting.18 string and set the custom-time-format setting.
19 </description>19 </description>
2020
=== added file 'po/Makevars'
--- po/Makevars 1970-01-01 00:00:00 +0000
+++ po/Makevars 2010-12-15 17:02:56 +0000
@@ -0,0 +1,7 @@
1DOMAIN = $(PACKAGE)
2subdir = po
3top_builddir = ..
4XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=T_ --from-code=UTF-8
5COPYRIGHT_HOLDER = Canonical Ltd.
6MSGID_BUGS_ADDRESS = ted@canonical.com
7EXTRA_LOCALE_CATEGORIES =
08
=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c 2010-09-30 13:52:20 +0000
+++ src/indicator-datetime.c 2010-12-15 17:02:56 +0000
@@ -23,6 +23,10 @@
23#include "config.h"23#include "config.h"
24#endif24#endif
2525
26#include <locale.h>
27#include <langinfo.h>
28#include <string.h>
29
26/* GStuff */30/* GStuff */
27#include <glib.h>31#include <glib.h>
28#include <glib-object.h>32#include <glib-object.h>
@@ -119,8 +123,14 @@
119 SETTINGS_TIME_CUSTOM = 3123 SETTINGS_TIME_CUSTOM = 3
120};124};
121125
122#define DEFAULT_TIME_12_FORMAT "%l:%M %p"126/* TRANSLATORS: A format string for the strftime function for
123#define DEFAULT_TIME_24_FORMAT "%H:%M"127 a clock showing 12-hour time without seconds. */
128#define DEFAULT_TIME_12_FORMAT N_("%l:%M %p")
129
130/* TRANSLATORS: A format string for the strftime function for
131 a clock showing 24-hour time without seconds. */
132#define DEFAULT_TIME_24_FORMAT N_("%H:%M")
133
124#define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT134#define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT
125135
126#define INDICATOR_DATETIME_GET_PRIVATE(o) \136#define INDICATOR_DATETIME_GET_PRIVATE(o) \
@@ -840,6 +850,53 @@
840 return;850 return;
841}851}
842852
853/* Translate msg according to the locale specified by LC_TIME */
854static char *
855T_(const char *msg)
856{
857 /* General strategy here is to make sure LANGUAGE is empty (since that
858 trumps all LC_* vars) and then to temporarily swap LC_TIME and
859 LC_MESSAGES. Then have gettext translate msg.
860
861 We strdup the strings because the setlocale & *env functions do not
862 guarantee anything about the storage used for the string, and thus
863 the string may not be portably safe after multiple calls.
864
865 Note that while you might think g_dcgettext would do the trick here,
866 that actually looks in /usr/share/locale/XX/LC_TIME, not the
867 LC_MESSAGES directory, so we won't find any translation there.
868 */
869 char *message_locale = g_strdup(setlocale(LC_MESSAGES, NULL));
870 char *time_locale = g_strdup(setlocale(LC_TIME, NULL));
871 char *language = g_strdup(g_getenv("LANGUAGE"));
872 char *rv;
873 g_unsetenv("LANGUAGE");
874 setlocale(LC_MESSAGES, time_locale);
875
876 /* Get the LC_TIME version */
877 rv = _(msg);
878
879 /* Put everything back the way it was */
880 setlocale(LC_MESSAGES, message_locale);
881 g_setenv("LANGUAGE", language, 1);
882 g_free(message_locale);
883 g_free(time_locale);
884 g_free(language);
885 return rv;
886}
887
888static gboolean
889is_locale_12h()
890{
891 static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL};
892 const char *t_fmt = nl_langinfo(T_FMT);
893 int i;
894 for (i = 0; formats_24h[i]; ++i)
895 if (strstr(t_fmt, formats_24h[i]))
896 return FALSE;
897 return TRUE;
898}
899
843/* Tries to figure out what our format string should be. Lots900/* Tries to figure out what our format string should be. Lots
844 of translator comments in here. */901 of translator comments in here. */
845static gchar *902static gchar *
@@ -852,17 +909,7 @@
852 gboolean twelvehour = TRUE;909 gboolean twelvehour = TRUE;
853910
854 if (self->priv->time_mode == SETTINGS_TIME_LOCALE) {911 if (self->priv->time_mode == SETTINGS_TIME_LOCALE) {
855 /* TRANSLATORS: This string is used to determine the default912 twelvehour = is_locale_12h();
856 clock style for your locale. If it is the string '12' then
857 the default will be a 12-hour clock using AM/PM string. If
858 it is '24' then it will be a 24-hour clock. Users may over
859 ride this setting so it's still important to translate the
860 other strings no matter how this is set. */
861 const gchar * locale_default = _("12");
862
863 if (g_strcmp0(locale_default, "24") == 0) {
864 twelvehour = FALSE;
865 }
866 } else if (self->priv->time_mode == SETTINGS_TIME_24_HOUR) {913 } else if (self->priv->time_mode == SETTINGS_TIME_24_HOUR) {
867 twelvehour = FALSE;914 twelvehour = FALSE;
868 }915 }
@@ -872,21 +919,17 @@
872 if (self->priv->show_seconds) {919 if (self->priv->show_seconds) {
873 /* TRANSLATORS: A format string for the strftime function for920 /* TRANSLATORS: A format string for the strftime function for
874 a clock showing 12-hour time with seconds. */921 a clock showing 12-hour time with seconds. */
875 time_string = _("%l:%M:%S %p");922 time_string = T_("%l:%M:%S %p");
876 } else {923 } else {
877 /* TRANSLATORS: A format string for the strftime function for924 time_string = T_(DEFAULT_TIME_12_FORMAT);
878 a clock showing 12-hour time. */
879 time_string = _(DEFAULT_TIME_12_FORMAT);
880 }925 }
881 } else {926 } else {
882 if (self->priv->show_seconds) {927 if (self->priv->show_seconds) {
883 /* TRANSLATORS: A format string for the strftime function for928 /* TRANSLATORS: A format string for the strftime function for
884 a clock showing 24-hour time with seconds. */929 a clock showing 24-hour time with seconds. */
885 time_string = _("%H:%M:%S");930 time_string = T_("%H:%M:%S");
886 } else {931 } else {
887 /* TRANSLATORS: A format string for the strftime function for932 time_string = T_(DEFAULT_TIME_24_FORMAT);
888 a clock showing 24-hour time. */
889 time_string = _(DEFAULT_TIME_24_FORMAT);
890 }933 }
891 }934 }
892 935
@@ -903,15 +946,15 @@
903 if (self->priv->show_date && self->priv->show_day) {946 if (self->priv->show_date && self->priv->show_day) {
904 /* TRANSLATORS: This is a format string passed to strftime to represent947 /* TRANSLATORS: This is a format string passed to strftime to represent
905 the day of the week, the month and the day of the month. */948 the day of the week, the month and the day of the month. */
906 date_string = _("%a %b %e");949 date_string = T_("%a %b %e");
907 } else if (self->priv->show_date) {950 } else if (self->priv->show_date) {
908 /* TRANSLATORS: This is a format string passed to strftime to represent951 /* TRANSLATORS: This is a format string passed to strftime to represent
909 the month and the day of the month. */952 the month and the day of the month. */
910 date_string = _("%b %e");953 date_string = T_("%b %e");
911 } else if (self->priv->show_day) {954 } else if (self->priv->show_day) {
912 /* TRANSLATORS: This is a format string passed to strftime to represent955 /* TRANSLATORS: This is a format string passed to strftime to represent
913 the day of the week. */956 the day of the week. */
914 date_string = _("%a");957 date_string = T_("%a");
915 }958 }
916959
917 /* Check point, we should have a date string */960 /* Check point, we should have a date string */
@@ -920,7 +963,7 @@
920 /* TRANSLATORS: This is a format string passed to strftime to combine the963 /* TRANSLATORS: This is a format string passed to strftime to combine the
921 date and the time. The value of "%s, %s" would result in a string like964 date and the time. The value of "%s, %s" would result in a string like
922 this in US English 12-hour time: 'Fri Jul 16, 11:50 AM' */965 this in US English 12-hour time: 'Fri Jul 16, 11:50 AM' */
923 return g_strdup_printf(_("%s, %s"), date_string, time_string);966 return g_strdup_printf(T_("%s, %s"), date_string, time_string);
924}967}
925968
926static gboolean969static gboolean

Subscribers

People subscribed via source and target branches