From 74695598c91d10d76b1ef1f1f7c78c7916a54327 Mon Sep 17 00:00:00 2001 From: Javier Steinaker Date: Tue, 14 Dec 2021 14:44:26 -0300 Subject: [PATCH] Added support for i18n and spanish translation --- gtkgreet/actions.c | 12 +++++++----- gtkgreet/gtkgreet.c | 10 ++++++++-- gtkgreet/gtkgreet.h | 2 +- gtkgreet/proto.c | 4 +++- gtkgreet/window.c | 8 +++++--- meson.build | 1 + po/LINGUAS | 1 + po/POTFILES.in | 4 ++++ po/es.po | 48 +++++++++++++++++++++++++++++++++++++++++++++ po/gtkgreet.pot | 47 ++++++++++++++++++++++++++++++++++++++++++++ po/meson.build | 7 +++++++ 11 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 po/LINGUAS create mode 100644 po/POTFILES.in create mode 100644 po/es.po create mode 100644 po/gtkgreet.pot create mode 100644 po/meson.build diff --git a/gtkgreet/actions.c b/gtkgreet/actions.c index fcb6002..6e72a09 100644 --- a/gtkgreet/actions.c +++ b/gtkgreet/actions.c @@ -3,6 +3,8 @@ #include #include +#include + #include #include "actions.h" @@ -30,8 +32,8 @@ static void handle_response(struct response resp, int start_req) { }; roundtrip(req); - char *error = "Unexpected auth question"; - gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, INITIAL_QUESTION, error); + char *error = _("Unexpected auth question"); + gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, gtkgreet_get_initial_question(), error); break; } @@ -51,11 +53,11 @@ static void handle_response(struct response resp, int start_req) { char* error = NULL; if (resp.response_type == response_type_error && resp.body.response_error.error_type == error_type_auth) { - error = "Login failed"; + error = _("Login failed"); } else { error = resp.body.response_error.description; } - gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, INITIAL_QUESTION, error); + gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, gtkgreet_get_initial_question(), error); break; } } @@ -112,5 +114,5 @@ void action_cancel_question(GtkWidget *widget, gpointer data) { exit(1); } - gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, INITIAL_QUESTION, NULL); + gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, gtkgreet_get_initial_question(), NULL); } diff --git a/gtkgreet/gtkgreet.c b/gtkgreet/gtkgreet.c index 1c97767..addad5a 100644 --- a/gtkgreet/gtkgreet.c +++ b/gtkgreet/gtkgreet.c @@ -2,6 +2,8 @@ #include +#include + #include "window.h" #include "gtkgreet.h" @@ -99,7 +101,7 @@ struct GtkGreet* create_gtkgreet() { void gtkgreet_activate(struct GtkGreet *gtkgreet) { gtkgreet->draw_clock_source = g_timeout_add_seconds(5, gtkgreet_update_clocks_handler, gtkgreet); - gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, INITIAL_QUESTION, NULL); + gtkgreet_setup_question(gtkgreet, QuestionTypeInitial, gtkgreet_get_initial_question(), NULL); gtkgreet_update_clocks(gtkgreet); } @@ -121,4 +123,8 @@ void gtkgreet_destroy(struct GtkGreet *gtkgreet) { gtkgreet->draw_clock_source = 0; } free(gtkgreet); -} \ No newline at end of file +} + +char* gtkgreet_get_initial_question() { + return _("Username:"); +} diff --git a/gtkgreet/gtkgreet.h b/gtkgreet/gtkgreet.h index fad1e2a..4c358e5 100644 --- a/gtkgreet/gtkgreet.h +++ b/gtkgreet/gtkgreet.h @@ -3,7 +3,6 @@ #include -#define INITIAL_QUESTION "Username:" enum QuestionType { QuestionTypeInitial = 0, @@ -48,5 +47,6 @@ void gtkgreet_update_clocks(struct GtkGreet *gtkgreet); struct GtkGreet* create_gtkgreet(); void gtkgreet_activate(struct GtkGreet *gtkgreet); void gtkgreet_destroy(struct GtkGreet *gtkgreet); +char* gtkgreet_get_initial_question(); #endif diff --git a/gtkgreet/proto.c b/gtkgreet/proto.c index a527e85..688757c 100644 --- a/gtkgreet/proto.c +++ b/gtkgreet/proto.c @@ -10,6 +10,8 @@ #include #include +#include + #include "proto.h" #include "window.h" @@ -179,7 +181,7 @@ struct response roundtrip(struct request req) { struct json_object* json_resp = roundtrip_json(json_req); if (json_resp == NULL) { - snprintf(resp.body.response_error.description, 128, "proto: roundtrip failed"); + snprintf(resp.body.response_error.description, 128, _("proto: roundtrip failed")); goto done; } diff --git a/gtkgreet/window.c b/gtkgreet/window.c index c4cd283..0fac5a3 100644 --- a/gtkgreet/window.c +++ b/gtkgreet/window.c @@ -3,6 +3,8 @@ #include #include +#include + #include #include "proto.h" @@ -117,7 +119,7 @@ void window_setup_question(struct Window *ctx, enum QuestionType type, char* que gtk_combo_box_set_active((GtkComboBox*)ctx->command_selector, 0); GtkWidget *selector_entry = gtk_bin_get_child((GtkBin*)ctx->command_selector); - gtk_entry_set_placeholder_text((GtkEntry*)selector_entry, "Command to run on login"); + gtk_entry_set_placeholder_text((GtkEntry*)selector_entry, _("Command to run on login")); g_signal_connect(selector_entry, "activate", G_CALLBACK(action_answer_question), ctx); gtk_container_add(GTK_CONTAINER(ctx->input_box), ctx->command_selector); @@ -143,7 +145,7 @@ void window_setup_question(struct Window *ctx, enum QuestionType type, char* que case QuestionTypeSecret: case QuestionTypeInfo: case QuestionTypeError: { - GtkWidget *cancel_button = gtk_button_new_with_label("Cancel"); + GtkWidget *cancel_button = gtk_button_new_with_label(_("Cancel")); gtk_widget_set_halign(cancel_button, GTK_ALIGN_END); gtk_container_add(GTK_CONTAINER(button_box), cancel_button); g_signal_connect(cancel_button, "clicked", G_CALLBACK(action_cancel_question), ctx); @@ -153,7 +155,7 @@ void window_setup_question(struct Window *ctx, enum QuestionType type, char* que break; } - GtkWidget *continue_button = gtk_button_new_with_label("Log in"); + GtkWidget *continue_button = gtk_button_new_with_label(_("Log in")); g_signal_connect(continue_button, "clicked", G_CALLBACK(action_answer_question), ctx); GtkStyleContext *continue_button_style = gtk_widget_get_style_context(continue_button); gtk_style_context_add_class(continue_button_style, "suggested-action"); diff --git a/meson.build b/meson.build index fa7c7c9..6feb26b 100644 --- a/meson.build +++ b/meson.build @@ -14,6 +14,7 @@ project( add_project_arguments('-Wno-unused-parameter', language: 'c') add_project_arguments('-Wno-missing-braces', language: 'c') +subdir('po') subdir('gtkgreet') scdoc = dependency('scdoc', required: get_option('man-pages'), version: '>= 1.9.7') diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..8357fca --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +es diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..b39cf7c --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,4 @@ +gtkgreet/actions.c +gtkgreet/gtkgreet.c +gtkgreet/proto.c +gtkgreet/window.c diff --git a/po/es.po b/po/es.po new file mode 100644 index 0000000..455b8e3 --- /dev/null +++ b/po/es.po @@ -0,0 +1,48 @@ +# Spanish translations for gtkgreet package. +# Copyright (C) 2021 THE gtkgreet'S COPYRIGHT HOLDER +# This file is distributed under the same license as the gtkgreet package. +# Automatically generated, 2021. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: gtkgreet\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-12-14 14:12-0300\n" +"PO-Revision-Date: 2021-12-14 14:12-0300\n" +"Last-Translator: Javier Steinaker \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: gtkgreet/actions.c:35 +msgid "Unexpected auth question" +msgstr "Pregunta de autenticación inesperada" + +#: gtkgreet/actions.c:56 +msgid "Login failed" +msgstr "Inicio de sesión fallido" + +#: gtkgreet/gtkgreet.c:129 +msgid "Username:" +msgstr "Nombre de usuario" + +#: gtkgreet/proto.c:184 +#, c-format +msgid "proto: roundtrip failed" +msgstr "Error de protocolo" + +#: gtkgreet/window.c:122 +msgid "Command to run on login" +msgstr "Comando a ejecutar al iniciar sesión" + +#: gtkgreet/window.c:148 +msgid "Cancel" +msgstr "Cancelar" + +#: gtkgreet/window.c:158 +msgid "Log in" +msgstr "Iniciar sesión" diff --git a/po/gtkgreet.pot b/po/gtkgreet.pot new file mode 100644 index 0000000..67b1e3c --- /dev/null +++ b/po/gtkgreet.pot @@ -0,0 +1,47 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the gtkgreet package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: gtkgreet\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-12-14 14:12-0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: gtkgreet/actions.c:35 +msgid "Unexpected auth question" +msgstr "" + +#: gtkgreet/actions.c:56 +msgid "Login failed" +msgstr "" + +#: gtkgreet/gtkgreet.c:129 +msgid "Username:" +msgstr "" + +#: gtkgreet/proto.c:184 +#, c-format +msgid "proto: roundtrip failed" +msgstr "" + +#: gtkgreet/window.c:122 +msgid "Command to run on login" +msgstr "" + +#: gtkgreet/window.c:148 +msgid "Cancel" +msgstr "" + +#: gtkgreet/window.c:158 +msgid "Log in" +msgstr "" diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..407bd69 --- /dev/null +++ b/po/meson.build @@ -0,0 +1,7 @@ +i18n = import('i18n') +# define GETTEXT_PACKAGE +add_project_arguments('-DGETTEXT_PACKAGE="gtkgreet"', '-DLOCALEDIR="/usr/local/share/locale"', language:'c') +i18n.gettext(meson.project_name(), + args: '--directory=' + meson.source_root(), + preset: 'glib' +) -- 2.38.5