Add plural support

Fixes #139.
This commit is contained in:
Ben Wiederhake 2015-10-19 20:10:47 +02:00
parent 954ed6048b
commit 77317fb99f
4 changed files with 25 additions and 9 deletions

View file

@ -4,7 +4,7 @@ autoreconf
echo bootstrapping translation files ...
cd po
intltool-update --pot
XGETTEXT='xgettext -kP_:1,2' intltool-update --pot
## Translations are managed at https://www.transifex.com/telegram-purple-developers/telegram-purple/
## To update the .po files, download it from there, since intltool, msginit, and transifex produce slightly different files, and I'd like to avoid gigantic git diffs that only change indentation or similar things.
#for lang in $(cat LINGUAS); do

View file

@ -28,8 +28,10 @@
// libintl.h. If this is not the case a dummy macro is defined to bypass the translation functions
#ifdef ENABLE_NLS
# include <glib/gi18n-lib.h>
# define P_(Singular,Plural,N) ((char *) g_dngettext (GETTEXT_PACKAGE, Singular, Plural, N))
#else
# define _(String) String
# define P_(Singular,Plural,N) Plural
#endif
#include <tgl.h>

View file

@ -128,16 +128,29 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) {
break;
}
case tgl_message_action_set_message_ttl:
txt = g_strdup_printf (_("%2$s set self destruction timer to %1$d seconds."), M->action.ttl, txt_user);
txt = g_strdup_printf (P_("%2$s set self destruction timer to %1$d second.",
"%2$s set self destruction timer to %1$d seconds.",
M->action.ttl),
M->action.ttl, txt_user);
break;
case tgl_message_action_read_messages:
txt = g_strdup_printf (_("%2$s marked %1$d messages read."), M->action.read_cnt, txt_user);
txt = g_strdup_printf (P_("%2$s marked %1$d message read.",
"%2$s marked %1$d messages read.",
M->action.read_cnt),
M->action.read_cnt, txt_user);
break;
case tgl_message_action_delete_messages:
txt = g_strdup_printf (_("%2$s deleted %1$d messages."), M->action.delete_cnt, txt_user);
txt = g_strdup_printf (P_("%2$s deleted %1$d message.",
"%2$s deleted %1$d messages.",
M->action.delete_cnt),
M->action.delete_cnt, txt_user);
break;
case tgl_message_action_screenshot_messages:
txt = g_strdup_printf (_("%2$s made a screenshot of %1$d messages."), M->action.screenshot_cnt, txt_user);
txt = g_strdup_printf (P_("%2$s made a screenshot of %1$d message.",
"%2$s made a screenshot of %1$d messages.",
M->action.screenshot_cnt),
M->action.screenshot_cnt, txt_user);
break;
default:
break;

View file

@ -21,6 +21,7 @@
#include "telegram-purple.h"
const char *format_time (time_t date) {
/* TODO: Inline this function for better readability? */
struct tm *datetime = localtime(&date);
/* This should be the language's timestamp format. This is preceded by a colon. */
return purple_utf8_strftime (_("%d.%m.%Y %H:%M"), datetime);
@ -40,19 +41,19 @@ char *tgp_format_user_status (struct tgl_user_status *status) {
char *when;
switch (status->online) {
case -1:
when = g_strdup_printf("%s", format_time (status->when));
when = g_strdup_printf ("%s", format_time (status->when));
break;
case -2:
/* This is preceded by a colon. */
when = g_strdup_printf (_("recently"));
when = g_strdup (_("recently"));
break;
case -3:
/* This is preceded by a colon. */
when = g_strdup_printf (_("last week"));
when = g_strdup (_("last week"));
break;
case -4:
/* This is preceded by a colon. */
when = g_strdup_printf (_("last month"));
when = g_strdup (_("last month"));
break;
default:
/* This is preceded by a colon. It refers to a point on time. */