1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-06-27 13:06:45 +02:00

Add localization system (gettext)

This commit is contained in:
Ansa89
2015-05-25 16:38:52 +02:00
committed by cnhenry
parent a455c80a1f
commit 0a2ad23c15
36 changed files with 5493 additions and 395 deletions

View File

@ -31,6 +31,12 @@
#include <assert.h>
#include <limits.h>
#ifdef NO_GETTEXT
#define gettext(A) (A)
#else
#include <libintl.h>
#endif
#include "toxic.h"
#include "windows.h"
#include "execute.h"
@ -47,6 +53,9 @@
#include "notify.h"
#include "message_queue.h"
#define YES_STR gettext("yes")
#define NO_STR gettext("no")
#ifdef AUDIO
#include "audio_call.h"
#endif /* AUDIO */
@ -211,7 +220,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, TOX_C
? tox_friend_get_typing(m, num, NULL) : false;
chat_resume_file_transfers(m, num);
msg = "has come online";
msg = gettext("has come online");
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
write_to_log(msg, nick, ctx->log, true);
} else if (connection_status == TOX_CONNECTION_NONE) {
@ -222,7 +231,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, TOX_C
chat_stop_file_senders(m, num);
msg = "has gone offline";
msg = gettext("has gone offline");
line_info_add(self, timefrmt, nick, NULL, DISCONNECTION, 0, RED, msg);
write_to_log(msg, nick, ctx->log, true);
}
@ -307,21 +316,21 @@ static void chat_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t friendnum,
char msg[MAX_STR_SIZE];
if (length == 0) {
snprintf(msg, sizeof(msg), "File '%s' successfully sent.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File '%s' successfully sent."), ft->file_name);
print_progress_bar(self, ft->bps, 100.0, ft->line_id);
close_file_transfer(self, m, ft, -1, msg, transfer_completed);
return;
}
if (ft->file == NULL) {
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Null file pointer.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' failed: Null file pointer."), ft->file_name);
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
return;
}
if (ft->position != position) {
if (fseek(ft->file, position, SEEK_SET) == -1) {
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Seek fail.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' failed: Seek fail."), ft->file_name);
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
return;
}
@ -333,7 +342,7 @@ static void chat_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t friendnum,
size_t send_length = fread(send_data, 1, sizeof(send_data), ft->file);
if (send_length != length) {
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Read fail.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' failed: Read fail."), ft->file_name);
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
return;
}
@ -342,7 +351,7 @@ static void chat_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t friendnum,
tox_file_send_chunk(m, ft->friendnum, ft->filenum, position, send_data, send_length, &err);
if (err != TOX_ERR_FILE_SEND_CHUNK_OK)
fprintf(stderr, "tox_file_send_chunk failed in chat callback (error %d)\n", err);
fprintf(stderr, gettext("tox_file_send_chunk failed in chat callback (error %d)\n"), err);
ft->position += send_length;
ft->bps += send_length;
@ -365,20 +374,20 @@ static void chat_onFileRecvChunk(ToxWindow *self, Tox *m, uint32_t friendnum, ui
char msg[MAX_STR_SIZE];
if (length == 0) {
snprintf(msg, sizeof(msg), "File '%s' successfully received.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File '%s' successfully received."), ft->file_name);
print_progress_bar(self, ft->bps, 100.0, ft->line_id);
close_file_transfer(self, m, ft, -1, msg, transfer_completed);
return;
}
if (ft->file == NULL) {
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Invalid file pointer.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' failed: Invalid file pointer."), ft->file_name);
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
return;
}
if (fwrite(data, length, 1, ft->file) != 1) {
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Write fail.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' failed: Write fail."), ft->file_name);
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
return;
}
@ -404,7 +413,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
/* transfer is accepted */
if (ft->state == FILE_TRANSFER_PENDING) {
ft->state = FILE_TRANSFER_STARTED;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%d] for '%s' accepted.",
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("File transfer [%d] for '%s' accepted."),
ft->index, ft->file_name);
char progline[MAX_STR_SIZE];
prep_prog_line(progline);
@ -422,7 +431,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
break;
case TOX_FILE_CONTROL_CANCEL:
snprintf(msg, sizeof(msg), "File transfer for '%s' was aborted.", ft->file_name);
snprintf(msg, sizeof(msg), gettext("File transfer for '%s' was aborted."), ft->file_name);
close_file_transfer(self, m, ft, -1, msg, notif_error);
break;
}
@ -438,13 +447,13 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
if (!ft) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: Too many concurrent file transfers.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("File transfer failed: Too many concurrent file transfers."));
return;
}
char sizestr[32];
bytes_convert_str(sizestr, sizeof(sizestr), file_size);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer request for '%s' (%s)", filename, sizestr);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("File transfer request for '%s' (%s)"), filename, sizestr);
char file_path[MAX_STR_SIZE];
size_t path_len = name_length;
@ -459,7 +468,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
if (path_len >= sizeof(ft->file_path) || name_length >= sizeof(ft->file_name)) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer faield: File path too long.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("File transfer faield: File path too long."));
return;
}
@ -485,12 +494,12 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
if (count > 999) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: invalid file path.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("File transfer failed: invalid file path."));
return;
}
}
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type '/savefile %d' to accept the file transfer.", ft->index);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Type '%s %d' to accept the file transfer."), "/savefile", ft->index);
ft->state = FILE_TRANSFER_PENDING;
ft->direction = FILE_TRANSFER_RECV;
@ -503,10 +512,10 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
if (self->active_box != -1)
box_notify2(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS, self->active_box,
"Incoming file: %s", filename );
gettext("Incoming file: %s"), filename );
else
box_notify(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS, &self->active_box, self->name,
"Incoming file: %s", filename );
gettext("Incoming file: %s"), filename );
}
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
@ -521,7 +530,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, ui
char *k = malloc(length);
if (k == NULL)
exit_toxic_err("Failed in chat_onGroupInvite", FATALERR_MEMORY);
exit_toxic_err(gettext("Failed in chat_onGroupInvite"), FATALERR_MEMORY);
memcpy(k, group_pub_key, length);
Friends.list[friendnumber].group_invite.key = k;
@ -535,12 +544,12 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, ui
get_nick_truncate(m, name, friendnumber);
if (self->active_box != -1)
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, "invites you to join group chat");
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, gettext("invites you to join group chat"));
else
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, gettext("invites you to join group chat"));
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to a group chat.", name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("%s has invited you to a group chat."), name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Type \"%s\" to join the chat."), "/join");
}
/* AV Stuff */
@ -560,9 +569,9 @@ void chat_onInvite (ToxWindow *self, ToxAV *av, uint32_t friend_number, int stat
sound_notify(self, call_incoming, NT_LOOP, &self->ringing_sound);
if (self->active_box != -1)
box_silent_notify2(self, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
box_silent_notify2(self, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, gettext("Incoming audio call!"));
else
box_silent_notify(self, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name, "Incoming audio call!");
box_silent_notify(self, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name, gettext("Incoming audio call!"));
}
void chat_onRinging (ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
@ -570,7 +579,7 @@ void chat_onRinging (ToxWindow *self, ToxAV *av, uint32_t friend_number, int sta
if (!self || !self->is_call || self->num != friend_number)
return;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...type \"/hangup\" to cancel it.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Ringing...type \"%s\" to cancel it."), "/hangup");
#ifdef SOUND_NOTIFY
if (self->ringing_sound == -1)
@ -630,7 +639,8 @@ void chat_onStart (ToxWindow *self, ToxAV *av, uint32_t friend_number, int state
self->is_call = true;
init_infobox(self);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Call started! Type: \"%s\" to end it."), "/hangup");
#ifdef SOUND_NOTIFY
stop_sound(self->ringing_sound);
@ -755,31 +765,31 @@ static void draw_infobox(ToxWindow *self)
infobox->lastupdate = curtime;
const char *in_is_muted = infobox->in_is_muted ? "yes" : "no";
const char *out_is_muted = infobox->out_is_muted ? "yes" : "no";
const char *in_is_muted = infobox->in_is_muted ? YES_STR : NO_STR;
const char *out_is_muted = infobox->out_is_muted ? YES_STR : NO_STR;
wmove(infobox->win, 1, 1);
wattron(infobox->win, COLOR_PAIR(RED) | A_BOLD);
wprintw(infobox->win, " Call Active\n");
wprintw(infobox->win, gettext(" Call Active\n"));
wattroff(infobox->win, COLOR_PAIR(RED) | A_BOLD);
wattron(infobox->win, A_BOLD);
wprintw(infobox->win, " Duration: ");
wprintw(infobox->win, gettext(" Duration: "));
wattroff(infobox->win, A_BOLD);
wprintw(infobox->win, "%s\n", infobox->timestr);
wattron(infobox->win, A_BOLD);
wprintw(infobox->win, " In muted: ");
wprintw(infobox->win, gettext(" In muted: "));
wattroff(infobox->win, A_BOLD);
wprintw(infobox->win, "%s\n", in_is_muted);
wattron(infobox->win, A_BOLD);
wprintw(infobox->win, " Out muted: ");
wprintw(infobox->win, gettext(" Out muted: "));
wattroff(infobox->win, A_BOLD);
wprintw(infobox->win, "%s\n", out_is_muted);
wattron(infobox->win, A_BOLD);
wprintw(infobox->win, " VAD level: ");
wprintw(infobox->win, gettext(" VAD level: "));
wattroff(infobox->win, A_BOLD);
wprintw(infobox->win, "%.2f\n", infobox->vad_lvl);
@ -1071,7 +1081,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
ctx->cqueue = calloc(1, sizeof(struct chat_queue));
if (ctx->log == NULL || ctx->hst == NULL || ctx->cqueue == NULL)
exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);
exit_toxic_err(gettext("failed in chat_onInit"), FATALERR_MEMORY);
line_info_init(ctx->hst);
@ -1143,7 +1153,7 @@ ToxWindow new_chat(Tox *m, uint32_t friendnum)
Help *help = calloc(1, sizeof(Help));
if (stb == NULL || chatwin == NULL || help == NULL)
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
exit_toxic_err(gettext("failed in new_chat"), FATALERR_MEMORY);
ret.chatwin = chatwin;
ret.stb = stb;