Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support interface localisation using GNU gettext #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Install dependencies:
* wayland
* wayland-protocols \*
* libxkbcommon
* xkeyboard-config
* cairo
* gdk-pixbuf2 \*\*
* pam (optional)
Expand Down
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <unistd.h>
#include <wayland-client.h>
#include <wordexp.h>
#include <locale.h>
#include <libintl.h>
#include "background-image.h"
#include "cairo.h"
#include "comm.h"
Expand Down Expand Up @@ -1101,6 +1103,10 @@ int main(int argc, char **argv) {
initialize_pw_backend(argc, argv);
srand(time(NULL));

setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
textdomain(GETTEXT_PACKAGE);

enum line_mode line_mode = LM_LINE;
state.failed_attempts = 0;
state.args = (struct swaylock_args){
Expand Down
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(
'c',
version: '1.6',
license: 'MIT',
meson_version: '>=0.48.0',
meson_version: '>=0.50.0',
default_options: [
'c_std=c11',
'warning_level=2',
Expand All @@ -27,6 +27,8 @@ sysconfdir = get_option('sysconfdir')
prefix = get_option('prefix')
is_freebsd = host_machine.system().startswith('freebsd')

subdir('po')

add_project_arguments(
'-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)),
language : 'c')
Expand All @@ -38,13 +40,15 @@ endif
wayland_client = dependency('wayland-client')
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
xkbcommon = dependency('xkbcommon')
xkeyboard_config = dependency('xkeyboard-config')
cairo = dependency('cairo')
gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: get_option('gdk-pixbuf'))
bash_comp = dependency('bash-completion', required: false)
fish_comp = dependency('fish', required: false)
libpam = cc.find_library('pam', required: get_option('pam'))
crypt = cc.find_library('crypt', required: not libpam.found())
math = cc.find_library('m')
intl = cc.find_library('intl', required: false)

git = find_program('git', required: false)
scdoc = find_program('scdoc', required: get_option('man-pages'))
Expand Down Expand Up @@ -116,6 +120,7 @@ dependencies = [
cairo,
client_protos,
gdk_pixbuf,
intl,
math,
xkbcommon,
wayland_client,
Expand Down
1 change: 1 addition & 0 deletions po/LINGUAS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de fr
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
render.c
34 changes: 34 additions & 0 deletions po/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# German translations for swaylock package.
# Copyright (C) 2020 THE swaylock'S COPYRIGHT HOLDER
# This file is distributed under the same license as the swaylock package.
# Automatically generated, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: swaylock 1.6\n"
"Report-Msgid-Bugs-To: https://github.com/swaywm/swaylock/issues\n"
"POT-Creation-Date: 2020-08-18 14:46+0200\n"
"PO-Revision-Date: 2020-08-18 15:25+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: de\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"

#: render.c:161
msgid "verifying"
msgstr "脺berpr眉fung"

#: render.c:164
msgid "wrong"
msgstr "falsch"

#: render.c:167
msgid "cleared"
msgstr "gel枚scht"

#: render.c:174
msgid "Caps Lock"
msgstr "Feststelltaste"
34 changes: 34 additions & 0 deletions po/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# French translations for swaylock package.
# Copyright (C) 2020 THE swaylock'S COPYRIGHT HOLDER
# This file is distributed under the same license as the swaylock package.
# Automatically generated, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: swaylock 1.6\n"
"Report-Msgid-Bugs-To: https://github.com/swaywm/swaylock/issues\n"
"POT-Creation-Date: 2020-08-18 14:46+0200\n"
"PO-Revision-Date: 2020-08-18 14:50+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: fr\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"

#: render.c:161
msgid "verifying"
msgstr "v茅rification"

#: render.c:164
msgid "wrong"
msgstr "incorrect"

#: render.c:167
msgid "cleared"
msgstr "effac茅"

#: render.c:174
msgid "Caps Lock"
msgstr "Verr Maj"
17 changes: 17 additions & 0 deletions po/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
i18n = import('i18n')

add_project_arguments(
[
'-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()),
'-DLOCALEDIR="@0@"'.format(get_option('prefix') / get_option('localedir'))
],
language:'c'
)
i18n.gettext(meson.project_name(),
args: [
'--directory=' + meson.source_root(),
'--package-name=' + meson.project_name(),
'--package-version=' + meson.project_version(),
'--msgid-bugs-address=https://github.com/swaywm/swaylock/issues',
]
)
34 changes: 34 additions & 0 deletions po/swaylock.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the swaylock package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: swaylock 1.6\n"
"Report-Msgid-Bugs-To: https://github.com/swaywm/swaylock/issues\n"
"POT-Creation-Date: 2020-08-18 14:46+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: render.c:161
msgid "verifying"
msgstr ""

#: render.c:164
msgid "wrong"
msgstr ""

#: render.c:167
msgid "cleared"
msgstr ""

#: render.c:174
msgid "Caps Lock"
msgstr ""
12 changes: 7 additions & 5 deletions render.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <math.h>
#include <stdlib.h>
#include <wayland-client.h>
#include <libintl.h>
#include "cairo.h"
#include "background-image.h"
#include "swaylock.h"
Expand Down Expand Up @@ -157,20 +158,20 @@ void render_frame(struct swaylock_surface *surface) {
}
switch (state->auth_state) {
case AUTH_STATE_VALIDATING:
text = "verifying";
text = gettext("verifying");
break;
case AUTH_STATE_INVALID:
text = "wrong";
text = gettext("wrong");
break;
case AUTH_STATE_CLEAR:
text = "cleared";
text = gettext("cleared");
break;
case AUTH_STATE_INPUT:
case AUTH_STATE_INPUT_NOP:
case AUTH_STATE_BACKSPACE:
// Caps Lock has higher priority
if (state->xkb.caps_lock && state->args.show_caps_lock_text) {
text = "Caps Lock";
text = gettext("Caps Lock");
} else if (state->args.show_failed_attempts &&
state->failed_attempts > 0) {
if (state->failed_attempts > 999) {
Expand All @@ -193,7 +194,8 @@ void render_frame(struct swaylock_surface *surface) {
++curr_layout;
}
// will handle invalid index if none are active
layout_text = xkb_keymap_layout_get_name(state->xkb.keymap, curr_layout);
layout_text = dgettext("xkeyboard-config",
xkb_keymap_layout_get_name(state->xkb.keymap, curr_layout));
}
break;
default:
Expand Down