Skip to content

Commit

Permalink
Read the list of locales from /etc/agama.d (#1205)
Browse files Browse the repository at this point in the history
To reduce the size of the live image as much as possible, we remove the
[locales
data](https://github.com/openSUSE/agama/blob/master/live/src/config.sh#L61-L69).
The only exceptions are those locales that contain Agama translations.
As a consequence, Agama cannot find the list of locales.

After some discussion, we agreed to read a static list (in
`/etc/agama.d/locales`). If the list is not there, it keeps running
`localectl list-units`.
  • Loading branch information
imobachgs authored May 14, 2024
2 parents 2fe4142 + 058ce74 commit 09f8c0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
27 changes: 19 additions & 8 deletions rust/agama-server/src/l10n/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use agama_locale_data::{InvalidLocaleCode, LocaleId};
use anyhow::Context;
use serde::Serialize;
use serde_with::{serde_as, DisplayFromStr};
use std::process::Command;
use std::{fs, process::Command};

/// Represents a locale, including the localized language and territory.
#[serde_as]
Expand Down Expand Up @@ -37,15 +37,12 @@ impl LocalesDatabase {

/// Loads the list of locales.
///
/// It checks for a file in /etc/agama.d/locales containing the list of supported locales (one per line).
/// It it does not exists, calls `localectl list-locales`.
///
/// * `ui_language`: language to translate the descriptions (e.g., "en").
pub fn read(&mut self, ui_language: &str) -> Result<(), Error> {
let result = Command::new("localectl")
.args(["list-locales"])
.output()
.context("Failed to get the list of locales")?;
let output =
String::from_utf8(result.stdout).context("Invalid UTF-8 sequence from list-locales")?;
self.known_locales = output
self.known_locales = Self::get_locales_list()?
.lines()
.filter_map(|line| TryInto::<LocaleId>::try_into(line).ok())
.collect();
Expand Down Expand Up @@ -110,6 +107,20 @@ impl LocalesDatabase {

Ok(result)
}

fn get_locales_list() -> Result<String, Error> {
const LOCALES_LIST_PATH: &str = "/etc/agama.d/locales";

if let Ok(locales) = fs::read_to_string(LOCALES_LIST_PATH) {
return Ok(locales);
}

let result = Command::new("localectl")
.args(["list-locales"])
.output()
.context("Failed to get the list of locales")?;
Ok(String::from_utf8(result.stdout).context("Invalid UTF-8 sequence from list-locales")?)
}
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue May 14 12:39:49 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- If present, read the locales list from the /etc/agama.d/locales
file (gh#openSUSE/agama#1205).

-------------------------------------------------------------------
Tue May 14 10:48:42 UTC 2024 - Knut Anderssen <kanderssen@suse.com>

Expand Down

0 comments on commit 09f8c0a

Please sign in to comment.