Skip to content

Commit

Permalink
fix(rust): localize the keymaps descriptions (#1643)
Browse files Browse the repository at this point in the history
## Problem

Agama's UI always displays the keymaps descriptions in English.

## Solution

Translate keymaps descriptions at API level.

## Testing

- Tested manually
  • Loading branch information
imobachgs authored Sep 27, 2024
2 parents c94f7d9 + 22d4db7 commit e900505
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 14 additions & 5 deletions rust/agama-server/src/l10n/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@

use agama_locale_data::{get_localectl_keymaps, keyboard::XkbConfigRegistry, KeymapId};
use gettextrs::*;
use serde::Serialize;
use serde_with::{serde_as, DisplayFromStr};
use serde::ser::{Serialize, SerializeStruct};
use std::collections::HashMap;

#[serde_as]
// Minimal representation of a keymap
#[derive(Clone, Debug, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, utoipa::ToSchema)]
pub struct Keymap {
/// Keymap identifier (e.g., "us")
#[serde_as(as = "DisplayFromStr")]
pub id: KeymapId,
/// Keymap description
description: String,
Expand All @@ -48,6 +45,18 @@ impl Keymap {
}
}

impl Serialize for Keymap {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("Keymap", 2)?;
state.serialize_field("id", &self.id.to_string())?;
state.serialize_field("description", &self.localized_description())?;
state.end()
}
}

/// Represents the keymaps database.
///
/// The list of supported keymaps is read from `systemd-localed` and the
Expand Down
5 changes: 5 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Sep 27 10:44:22 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Expose keymaps localized descriptions (gh#agama-project/agama#1643).

-------------------------------------------------------------------
Wed Sep 25 14:33:50 UTC 2024 - Clemens Famulla-Conrad <cfamullaconrad@suse.com>

Expand Down

0 comments on commit e900505

Please sign in to comment.