Skip to content

Commit 1a481f6

Browse files
server: Setup i18n for prompting related parts
1 parent 5e38a56 commit 1a481f6

8 files changed

Lines changed: 145 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 98 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ base64 = "0.22"
1515
caps = "0.5"
1616
clap.workspace = true
1717
enumflags2 = "0.7"
18+
gettext-rs = {version = "0.7", features = ["gettext-system"]}
1819
hkdf = { version = "0.12", optional = true }
1920
nix = { version = "0.30", default-features = false, features = ["user"]}
2021
num = "0.4.0"

server/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ project(
55
meson_version: '>= 0.61.0',
66
)
77

8+
i18n = import('i18n')
9+
810
is_devel = get_option('profile') == 'development'
911
dbus_known_name = 'org.freedesktop.secrets'
1012
service_name = meson.project_name()
13+
gettext_package = meson.project_name()
1114

1215
prefix = get_option('prefix')
1316
datadir = get_option('datadir')
@@ -43,3 +46,4 @@ summary({
4346

4447
subdir('data')
4548
subdir('src')
49+
subdir('po')

server/po/POTFILES.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/gnome/prompter.rs

server/po/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
i18n.gettext(
2+
gettext_package,
3+
args: ['--keyword=i18n_f'],
4+
preset: 'glib',
5+
)

server/src/gnome/prompter.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use gettextrs::gettext;
34
use oo7::{Key, ashpd::WindowIdentifierType, dbus::ServiceError};
45
use serde::{Deserialize, Serialize};
56
use tokio::sync::OnceCell;
@@ -11,6 +12,7 @@ use zbus::zvariant::{
1112
use super::secret_exchange;
1213
use crate::{
1314
error::custom_service_error,
15+
i18n::i18n_f,
1416
prompt::{Prompt, PromptRole},
1517
service::Service,
1618
};
@@ -156,16 +158,16 @@ impl Properties {
156158
fn for_lock(keyring: &str, window_id: Option<&WindowIdentifierType>) -> Self {
157159
Self {
158160
title: None,
159-
message: Some("Lock Keyring".to_owned()),
160-
description: Some(format!("Confirm locking '{keyring}' Keyring")),
161+
message: Some(gettext("Lock Keyring")),
162+
description: Some(i18n_f("Confirm locking '{}' Keyring", &[keyring])),
161163
warning: None,
162164
password_new: None,
163165
password_strength: None,
164166
choice_label: None,
165167
choice_chosen: None,
166168
caller_window: window_id.map(ToOwned::to_owned),
167-
continue_label: Some("Lock".to_owned()),
168-
cancel_label: Some("Cancel".to_owned()),
169+
continue_label: Some(gettext("Lock")),
170+
cancel_label: Some(gettext("Cancel")),
169171
}
170172
}
171173

@@ -175,37 +177,39 @@ impl Properties {
175177
window_id: Option<&WindowIdentifierType>,
176178
) -> Self {
177179
Self {
178-
title: Some("Unlock Keyring".to_owned()),
179-
message: Some("Authentication required".to_owned()),
180-
description: Some(format!(
181-
"An application wants access to the keyring '{keyring}', but it is locked"
180+
title: Some(gettext("Unlock Keyring")),
181+
message: Some(gettext("Authentication required")),
182+
description: Some(i18n_f(
183+
"An application wants access to the keyring '{}', but it is locked",
184+
&[keyring],
182185
)),
183186
warning: warning.map(ToOwned::to_owned),
184187
password_new: None,
185188
password_strength: None,
186189
choice_label: None,
187190
choice_chosen: None,
188191
caller_window: window_id.map(ToOwned::to_owned),
189-
continue_label: Some("Unlock".to_owned()),
190-
cancel_label: Some("Cancel".to_owned()),
192+
continue_label: Some(gettext("Unlock")),
193+
cancel_label: Some(gettext("Cancel")),
191194
}
192195
}
193196

194197
fn for_create_collection(label: &str, window_id: Option<&WindowIdentifierType>) -> Self {
195198
Self {
196-
title: Some("New Keyring Password".to_owned()),
197-
message: Some("Choose password for new keyring".to_owned()),
198-
description: Some(format!(
199-
"An application wants to create a new keyring called '{label}'. Choose the password you want to use for it."
199+
title: Some(gettext("New Keyring Password")),
200+
message: Some(gettext("Choose password for new keyring")),
201+
description: Some(i18n_f(
202+
"An application wants to create a new keyring called '{}'. Choose the password you want to use for it.",
203+
&[label],
200204
)),
201205
warning: None,
202206
password_new: Some(true),
203207
password_strength: None,
204208
choice_label: None,
205209
choice_chosen: None,
206210
caller_window: window_id.map(ToOwned::to_owned),
207-
continue_label: Some("Create".to_owned()),
208-
cancel_label: Some("Cancel".to_owned()),
211+
continue_label: Some(gettext("Create")),
212+
cancel_label: Some(gettext("Cancel")),
209213
}
210214
}
211215
}

server/src/i18n.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use gettextrs::gettext;
2+
3+
fn freplace(input: String, args: &[&str]) -> String {
4+
let mut parts = input.split("{}");
5+
let mut output = parts.next().unwrap_or("").to_string();
6+
for (p, a) in parts.zip(args.iter()) {
7+
output += &(a.to_string() + p);
8+
}
9+
output
10+
}
11+
12+
pub(crate) fn i18n_f(format: &str, args: &[&str]) -> String {
13+
let s = gettext(format);
14+
freplace(s, args)
15+
}

server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod collection;
33
mod error;
44
#[allow(unused)]
55
mod gnome;
6+
mod i18n;
67
mod item;
78
mod prompt;
89
mod service;

0 commit comments

Comments
 (0)