Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ glob = "0.3.1"
greetd_ipc = { version = "0.10.0", features = ["sync-codec"] }
async-channel = "2.2.1"
anyhow = "1.0.82"
gettext-rs = "0.7"
libphosh = "0.0.7"
clap = { version = "4.5.4", features = ["derive"] }
wayland-client = "0.31"
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ fn is_phoc_detected() -> anyhow::Result<bool> {
pub fn init() -> anyhow::Result<()> {
gio::resources_register_include!("phrog.gresource").context("failed to register resources.")?;

let _ = gettextrs::bindtextdomain("phosh", "/usr/share/locale");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other projects we take that path from meson but idk what's @samcday 's preference is here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just hardcode for now since this is what distros are gonna use anyway. Maybe @hustlerone could wander past here and let us know whether this would be an issue with Nix packaging. If so I'm sure (or hoping, at least) that we can still easily solve this with Cargo / build.rs and not need to bring in the Meson bazooka.

gettextrs::textdomain("phosh")?;

if !is_phoc_detected().context("failed to detect Wayland compositor globals")? {
return Err(anyhow!("Phoc parent compositor not detected"));
}
Expand Down
12 changes: 6 additions & 6 deletions src/lockscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod imp {
self.session.replace(user.clone());
let username = user.unwrap();
info!("creating greetd session for user {}", username);
self.obj().set_unlock_status("Please wait...");
self.obj().set_unlock_status(&gettextrs::gettext("Please wait..."));
self.obj().set_sensitive(false);
let mut req = Some(Request::CreateSession { username });
while let Some(next_req) = req.take() {
Expand Down Expand Up @@ -248,7 +248,7 @@ mod imp {

if let Err(err) = resp {
error!("failed to send greetd request: {:?}", err);
self.obj().set_unlock_status("Error, please try again");
self.obj().set_unlock_status(&gettextrs::gettext("Error, please try again"));
self.obj().set_sensitive(true);
return None;
}
Expand Down Expand Up @@ -286,7 +286,7 @@ mod imp {
}
}
Response::Success => {
self.obj().set_unlock_status("Success. Logging in...");
self.obj().set_unlock_status(&gettextrs::gettext("Success. Logging in..."));
self.start_session().await.unwrap();
g_message!("phrog", "launched session, exiting in {}ms", QUIT_DELAY);
Shell::default().fade_out(0);
Expand All @@ -300,7 +300,7 @@ mod imp {
description,
} => {
warn!("auth error: '{}'", description);
self.obj().set_unlock_status("Login failed, please try again");
self.obj().set_unlock_status(&gettextrs::gettext("Login failed, please try again"));
self.obj().shake_pin_entry();
// Greetd IPC dox seem to suggest that this isn't necessary, but then agreety
// does this, and if we don't we get a "session is already being configured"
Expand Down Expand Up @@ -329,7 +329,7 @@ mod imp {
impl LockscreenImpl for Lockscreen {
fn unlock_submit(&self) {
glib::spawn_future_local(clone!(@weak self as this => async move {
this.obj().set_unlock_status("Please wait...");
this.obj().set_unlock_status(&gettextrs::gettext("Please wait..."));
this.obj().set_sensitive(false);
let mut req = Some(Request::PostAuthMessageResponse {
response: Some(this.obj().pin_entry().to_string())
Expand All @@ -347,7 +347,7 @@ fn fake_greetd_interaction(req: Request) -> anyhow::Result<Response> {
match req {
Request::CreateSession { .. } => anyhow::Ok(Response::AuthMessage {
auth_message_type: Secret,
auth_message: "Password:".into(),
auth_message: gettextrs::gettext("Password:").into(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add new translations you need to bind another gettext domain (phrog) as otherwise the lookups will be done in phosh only (and then use dgettext("phrog", …) to look things up in the correct gettext domain.

Phosh currently uses the gettext domain for lookups but I we could switch to using gi18n-lib.h everywhere to fix the phosh gettext domain - that said using dgettext here right away doesn't have any downsides as far as I know.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dgettext approach sounds great.

So I think this boils down to:

Suggested change
auth_message: gettextrs::gettext("Password:").into(),
auth_message: gettextrs::dgettext("phrog", "Password:").into(),

(but also note that I think clippy is complaining about this .into())

}),
Request::PostAuthMessageResponse { response } => {
if response.is_none() || response.unwrap() != "0" {
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ struct Args {
}

fn main() -> anyhow::Result<()> {
let _ = gettextrs::bindtextdomain("phosh", "/usr/share/locale");
gettextrs::textdomain("phosh")?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? correct here as that would mean early return if gettext can't be initialized.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the app start up with default English strings rather than not start up at all 😅

So how about:

Suggested change
gettextrs::textdomain("phosh")?;
if let Err(err) = gettextrs::textdomain("phosh") {
log::warn("onoes no i18n"...);
}

(and move this init after the following logger lines so that the log works properly :)


log::set_logger(&GLIB_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Debug);

Expand Down
Loading