mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Get user language from GLib
This commit is contained in:
parent
220821a0e0
commit
3c8f5b8c31
5 changed files with 24 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1050,6 +1050,7 @@ dependencies = [
|
||||||
"gettext-rs",
|
"gettext-rs",
|
||||||
"gstreamer-play",
|
"gstreamer-play",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
|
"lazy_static",
|
||||||
"libadwaita",
|
"libadwaita",
|
||||||
"log",
|
"log",
|
||||||
"mpris-player",
|
"mpris-player",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ fragile = "2"
|
||||||
gettext-rs = { version = "0.7", features = ["gettext-system"] }
|
gettext-rs = { version = "0.7", features = ["gettext-system"] }
|
||||||
gstreamer-play = "0.22"
|
gstreamer-play = "0.22"
|
||||||
gtk = { package = "gtk4", version = "0.7", features = ["v4_12", "blueprint"] }
|
gtk = { package = "gtk4", version = "0.7", features = ["v4_12", "blueprint"] }
|
||||||
|
lazy_static = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mpris-player = "0.6"
|
mpris-player = "0.6"
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ use diesel::{
|
||||||
use diesel_migrations::{EmbeddedMigrations, MigrationHarness};
|
use diesel_migrations::{EmbeddedMigrations, MigrationHarness};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::util;
|
||||||
|
|
||||||
// This makes the SQL migration scripts accessible from the code.
|
// This makes the SQL migration scripts accessible from the code.
|
||||||
const MIGRATIONS: EmbeddedMigrations = diesel_migrations::embed_migrations!();
|
const MIGRATIONS: EmbeddedMigrations = diesel_migrations::embed_migrations!();
|
||||||
|
|
||||||
|
|
@ -48,10 +50,7 @@ impl TranslatedString {
|
||||||
/// generic translation exists (which is a bug in the data), an empty string is
|
/// generic translation exists (which is a bug in the data), an empty string is
|
||||||
/// returned and a warning is logged.
|
/// returned and a warning is logged.
|
||||||
pub fn get(&self) -> &str {
|
pub fn get(&self) -> &str {
|
||||||
// TODO: Get language from locale.
|
match self.0.get(&*util::LANG) {
|
||||||
let lang = "generic";
|
|
||||||
|
|
||||||
match self.0.get(lang) {
|
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => match self.0.get("generic") {
|
None => match self.0.get("generic") {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ mod recording_tile;
|
||||||
mod search_entry;
|
mod search_entry;
|
||||||
mod search_tag;
|
mod search_tag;
|
||||||
mod tag_tile;
|
mod tag_tile;
|
||||||
|
mod util;
|
||||||
mod welcome_page;
|
mod welcome_page;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
|
|
|
||||||
18
src/util.rs
Normal file
18
src/util.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
use gtk::glib;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
/// The user's language code.
|
||||||
|
pub static ref LANG: String = {
|
||||||
|
let lang = match glib::language_names().first() {
|
||||||
|
Some(language_name) => match language_name.split('_').next() {
|
||||||
|
Some(lang) => lang.to_string(),
|
||||||
|
None => "generic".to_string(),
|
||||||
|
},
|
||||||
|
None => "generic".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
log::info!("Intialized user language to '{lang}'.");
|
||||||
|
lang
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue