From cbed8acf010b9064e1379f81b3e64a22bfa08260 Mon Sep 17 00:00:00 2001 From: 01micko <01micko@gmail.com> Date: Sun, 1 May 2022 14:38:45 +1000 Subject: [PATCH] nls: add native language support - adds labwc.pot and po files for de, es, it and sv - added notes in NEWS.md and CONTRIBUTING.md - addresses #269 - conditional upon `msgfmt` being installed - can be disabled at build time --- CONTRIBUTING.md | 6 +++++- NEWS.md | 3 ++- include/labwc.h | 7 +++++++ meson.build | 9 +++++++++ meson_options.txt | 1 + po/LINGUAS | 1 + po/POTFILES.in | 1 + po/de.po | 50 +++++++++++++++++++++++++++++++++++++++++++++++ po/es.po | 50 +++++++++++++++++++++++++++++++++++++++++++++++ po/it.po | 50 +++++++++++++++++++++++++++++++++++++++++++++++ po/labwc.pot | 50 +++++++++++++++++++++++++++++++++++++++++++++++ po/meson.build | 12 ++++++++++++ po/sv.po | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 5 +++++ src/menu/menu.c | 16 +++++++-------- 15 files changed, 301 insertions(+), 10 deletions(-) create mode 100644 po/LINGUAS create mode 100644 po/POTFILES.in create mode 100644 po/de.po create mode 100644 po/es.po create mode 100644 po/it.po create mode 100644 po/labwc.pot create mode 100644 po/meson.build create mode 100644 po/sv.po diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 139edf1f..00838753 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,8 +30,12 @@ line with wlroots. With the introduction of the scene-graph API, some wlroots functions also use node coordinates (nx, ny) but we prefer (sx, sy) where possible. +## Native Language Support + +Translators can add their `MY_LOCALE.po` files to the `po` directory +based on `po/labwc.pot` and issue a pull request. + [coding style]: https://git.sr.ht/~sircmpwn/cstyle [commit messages]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/CONTRIBUTING.md#commit-messages [checkpatch.pl]: https://github.com/johanmalm/checkpatch.pl - diff --git a/NEWS.md b/NEWS.md index f429ef86..44aa02f1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,7 +27,8 @@ that branch. This release contains significant refactoring to use the wlroots scene-graph API, particularly src/output.c, server-side-decoration and the layer-shell implementation. Many thanks to @Consolatis for some -heavy lifting with this. +heavy lifting with this. Native language support has been added by +@01micko. ### Added diff --git a/include/labwc.h b/include/labwc.h index f6430a88..a06b7d48 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -48,6 +48,13 @@ #include "config/keybind.h" #include "config/rcxml.h" #include "ssd.h" +#if HAVE_NLS +#include +#include +#define _ gettext +#else +#define _(s) (s) +#endif #define XCURSOR_DEFAULT "left_ptr" #define XCURSOR_SIZE 24 diff --git a/meson.build b/meson.build index 9cd11810..47413859 100644 --- a/meson.build +++ b/meson.build @@ -75,6 +75,15 @@ have_xwayland = xcb.found() and wlroots_has_xwayland conf_data = configuration_data() conf_data.set10('HAVE_XWAYLAND', have_xwayland) +msgfmt = find_program('msgfmt', required: get_option('nls')) +if msgfmt.found() + source_root = meson.current_source_dir() + conf_data.set('HAVE_NLS', 1) + subdir('po') +else + conf_data.set('HAVE_NLS', 0) +endif + labwc_inc = include_directories('include') subdir('protocols') diff --git a/meson_options.txt b/meson_options.txt index d64f510c..00558f17 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('xwayland', type: 'feature', value: 'auto', description: 'Enable support for X11 applications') +option('nls', type: 'feature', value: 'auto', description: 'Enable native language support') diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 00000000..c6a73c96 --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +de es it sv diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 00000000..ee1427e6 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1 @@ +src/menu/menu.c diff --git a/po/de.po b/po/de.po new file mode 100644 index 00000000..20cc55aa --- /dev/null +++ b/po/de.po @@ -0,0 +1,50 @@ +# Labwc pot file +# Copyright (C) 2022 +# This file is distributed under the same license as the labwc package. +# FIRST AUTHOR , 2022. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: labwc\n" +"Report-Msgid-Bugs-To: https://github.com/labwc/labwc/issues\n" +"POT-Creation-Date: 2022-04-30 16:43+1000\n" +"PO-Revision-Date: 2022-04-30 16:50+1000\n" +"Last-Translator: Consolatis \n" +"Language-Team: LANGUAGE \n" +"Language: German\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/menu/menu.c:428 +msgid "Reconfigure" +msgstr "Rekonfigurieren" + +#: src/menu/menu.c:430 +msgid "Exit" +msgstr "Beenden" + +#: src/menu/menu.c:446 +msgid "Minimize" +msgstr "Minimieren" + +#: src/menu/menu.c:448 +msgid "Maximize" +msgstr "Maximieren" + +#: src/menu/menu.c:450 +msgid "Fullscreen" +msgstr "Vollbild" + +#: src/menu/menu.c:452 +msgid "Decorations" +msgstr "Dekorationen" + +#: src/menu/menu.c:454 +msgid "AlwaysOnTop" +msgstr "Immer im Vordergrund" + +#: src/menu/menu.c:456 +msgid "Close" +msgstr "Schließen" diff --git a/po/es.po b/po/es.po new file mode 100644 index 00000000..bc5390cc --- /dev/null +++ b/po/es.po @@ -0,0 +1,50 @@ +# Labwc pot file +# Copyright (C) 2022 +# This file is distributed under the same license as the labwc package. +# FIRST AUTHOR <01micko@gmail.com>, 2022. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: labwc\n" +"Report-Msgid-Bugs-To: https://github.com/labwc/labwc/issues\n" +"POT-Creation-Date: 2022-04-30 16:43+1000\n" +"PO-Revision-Date: 2022-04-30 16:50+1000\n" +"Last-Translator: Mick Amadio <01micko@gmail.com>\n" +"Language-Team: LANGUAGE \n" +"Language: Spanish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/menu/menu.c:428 +msgid "Reconfigure" +msgstr "Reconfigurar" + +#: src/menu/menu.c:430 +msgid "Exit" +msgstr "Salir" + +#: src/menu/menu.c:446 +msgid "Minimize" +msgstr "Minimizar" + +#: src/menu/menu.c:448 +msgid "Maximize" +msgstr "Maximizar" + +#: src/menu/menu.c:450 +msgid "Fullscreen" +msgstr "Pantalla completa" + +#: src/menu/menu.c:452 +msgid "Decorations" +msgstr "Decoraciones" + +#: src/menu/menu.c:454 +msgid "AlwaysOnTop" +msgstr "Siempre encima" + +#: src/menu/menu.c:456 +msgid "Close" +msgstr "Cerrar" diff --git a/po/it.po b/po/it.po new file mode 100644 index 00000000..0e5da4b1 --- /dev/null +++ b/po/it.po @@ -0,0 +1,50 @@ +# Labwc pot file +# Copyright (C) 2022 +# This file is distributed under the same license as the labwc package. +# FIRST AUTHOR <01micko@gmail.com>, 2022. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: labwc\n" +"Report-Msgid-Bugs-To: https://github.com/labwc/labwc/issues\n" +"POT-Creation-Date: 2022-04-30 16:43+1000\n" +"PO-Revision-Date: 2022-04-30 16:50+1000\n" +"Last-Translator: Mick Amadio <01micko@gmail.com>\n" +"Language-Team: LANGUAGE \n" +"Language: Italian\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/menu/menu.c:428 +msgid "Reconfigure" +msgstr "Riconfigurare" + +#: src/menu/menu.c:430 +msgid "Exit" +msgstr "Uscita" + +#: src/menu/menu.c:446 +msgid "Minimize" +msgstr "Riduci" + +#: src/menu/menu.c:448 +msgid "Maximize" +msgstr "Ingrandisci" + +#: src/menu/menu.c:450 +msgid "Fullscreen" +msgstr "Schermo intero" + +#: src/menu/menu.c:452 +msgid "Decorations" +msgstr "Decorazioni" + +#: src/menu/menu.c:454 +msgid "AlwaysOnTop" +msgstr "Sempre sopra" + +#: src/menu/menu.c:456 +msgid "Close" +msgstr "Chiudi" diff --git a/po/labwc.pot b/po/labwc.pot new file mode 100644 index 00000000..b355c0cb --- /dev/null +++ b/po/labwc.pot @@ -0,0 +1,50 @@ +# Labwc pot file +# Copyright (C) 2022 +# This file is distributed under the same license as the labwc package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: labwc\n" +"Report-Msgid-Bugs-To: https://github.com/labwc/labwc/issues\n" +"POT-Creation-Date: 2022-04-30 16:43+1000\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=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/menu/menu.c:428 +msgid "Reconfigure" +msgstr "" + +#: src/menu/menu.c:430 +msgid "Exit" +msgstr "" + +#: src/menu/menu.c:446 +msgid "Minimize" +msgstr "" + +#: src/menu/menu.c:448 +msgid "Maximize" +msgstr "" + +#: src/menu/menu.c:450 +msgid "Fullscreen" +msgstr "" + +#: src/menu/menu.c:452 +msgid "Decorations" +msgstr "" + +#: src/menu/menu.c:454 +msgid "AlwaysOnTop" +msgstr "" + +#: src/menu/menu.c:456 +msgid "Close" +msgstr "" diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 00000000..d6e1ff31 --- /dev/null +++ b/po/meson.build @@ -0,0 +1,12 @@ +i18n = import('i18n') +add_project_arguments('-DGETTEXT_PACKAGE="' + meson.project_name() + '"', + '-DLOCALEDIR="' + get_option('prefix') / get_option('localedir') + '"', + language:'c') +i18n.gettext(meson.project_name(), + args: ['--directory=' + source_root, + '--add-comments=TRANSLATORS', + '--no-location', + '--keyword=_', + '--msgid-bugs=https://github.com/labwc/labwc/issues'], + preset: 'glib' +) diff --git a/po/sv.po b/po/sv.po new file mode 100644 index 00000000..db24ab54 --- /dev/null +++ b/po/sv.po @@ -0,0 +1,50 @@ +# Labwc pot file +# Copyright (C) 2022 +# This file is distributed under the same license as the labwc package. +# FIRST AUTHOR , 2022. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: labwc\n" +"Report-Msgid-Bugs-To: https://github.com/labwc/labwc/issues\n" +"POT-Creation-Date: 2022-04-30 16:43+1000\n" +"PO-Revision-Date: 2022-04-30 16:50+1000\n" +"Last-Translator: Johan Malm \n" +"Language: Swedish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/menu/menu.c:428 +msgid "Reconfigure" +msgstr "Konfigurera om" + +#: src/menu/menu.c:430 +msgid "Exit" +msgstr "Utgång" + +#: src/menu/menu.c:446 +msgid "Minimize" +msgstr "Minimera" + +#: src/menu/menu.c:448 +msgid "Maximize" +msgstr "Maximera" + +#: src/menu/menu.c:450 +msgid "Fullscreen" +msgstr "Fullskärm" + +#: src/menu/menu.c:452 +msgid "Decorations" +msgstr "Dekorationer" + +#: src/menu/menu.c:454 +msgid "AlwaysOnTop" +msgstr "Alltid överst" + +#: src/menu/menu.c:456 +msgid "Close" +msgstr "Stäng" diff --git a/src/main.c b/src/main.c index 3ee2b6ef..1e2dc1ee 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,11 @@ usage(void) int main(int argc, char *argv[]) { +#if HAVE_NLS + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + textdomain(GETTEXT_PACKAGE); +#endif char *startup_cmd = NULL; char *config_file = NULL; enum wlr_log_importance verbosity = WLR_ERROR; diff --git a/src/menu/menu.c b/src/menu/menu.c index b23fcbcb..8bfb29f2 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -425,9 +425,9 @@ menu_init_rootmenu(struct server *server) menu = menu_create(server, "root-menu", ""); } if (wl_list_empty(&menu->menuitems)) { - current_item = item_create(menu, "Reconfigure"); + current_item = item_create(menu, _("Reconfigure")); fill_item("name.action", "Reconfigure"); - current_item = item_create(menu, "Exit"); + current_item = item_create(menu, _("Exit")); fill_item("name.action", "Exit"); } } @@ -443,17 +443,17 @@ menu_init_windowmenu(struct server *server) menu = menu_create(server, "client-menu", ""); } if (wl_list_empty(&menu->menuitems)) { - current_item = item_create(menu, "Minimize"); + current_item = item_create(menu, _("Minimize")); fill_item("name.action", "Iconify"); - current_item = item_create(menu, "Maximize"); + current_item = item_create(menu, _("Maximize")); fill_item("name.action", "ToggleMaximize"); - current_item = item_create(menu, "Fullscreen"); + current_item = item_create(menu, _("Fullscreen")); fill_item("name.action", "ToggleFullscreen"); - current_item = item_create(menu, "Decorations"); + current_item = item_create(menu, _("Decorations")); fill_item("name.action", "ToggleDecorations"); - current_item = item_create(menu, "AlwaysOnTop"); + current_item = item_create(menu, _("AlwaysOnTop")); fill_item("name.action", "ToggleAlwaysOnTop"); - current_item = item_create(menu, "Close"); + current_item = item_create(menu, _("Close")); fill_item("name.action", "Close"); } }