feat: Russian interface language
Adds an i18n module: strings stay in English in the code and are looked
up as tr("…") or trf("… {} …", args), with Russian in i18n/ru.rs.
Includes Russian plurals, genitive month names, "4,1 млн"-style
compact numbers and localised durations. A test scans the sources and
fails on any string without a Russian entry.
A Language setting (match system, English, Русский) defaults to the
system's first preferred language. Yandex's own titles (genres, Home
blocks, station names) switch with it, through a client rebuilt in that
language. Long genre names now wrap instead of spilling over the next
tile. The app bundle declares en and ru localisations.
This commit is contained in:
1 parent
52ad4a2e90
commit
ff41887f30
35 files changed
+1073
-308
No files matched your search
@@ -121,17 +121,50 @@ impl std::fmt::Debug for YmClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// The language Yandex writes its own titles in: genres, Home blocks, stations.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ContentLanguage {
|
||||
Russian,
|
||||
English,
|
||||
}
|
||||
|
||||
impl ContentLanguage {
|
||||
fn yamuse(self) -> yamuse::Language {
|
||||
match self {
|
||||
ContentLanguage::Russian => yamuse::Language::Ru,
|
||||
ContentLanguage::English => yamuse::Language::En,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl YmClient {
|
||||
/// Builds a client for `credentials` and loads the account. Fails with
|
||||
/// [`crate::Error::Unauthorized`] when the token is no longer valid.
|
||||
pub async fn connect(credentials: &Credentials) -> Result<(Self, Account)> {
|
||||
let inner = yamuse::Client::builder().token(&credentials.access_token).build()?;
|
||||
pub async fn connect(credentials: &Credentials, language: ContentLanguage) -> Result<(Self, Account)> {
|
||||
let inner = yamuse::Client::builder()
|
||||
.token(&credentials.access_token)
|
||||
.language(language.yamuse())
|
||||
.build()?;
|
||||
let status = inner.refresh_account().await?;
|
||||
let account = Account::from_status(status)
|
||||
.ok_or_else(|| Error::Unauthorized("account status has no user".into()))?;
|
||||
Ok((Self { inner, token: Some(credentials.access_token.as_str().into()) }, account))
|
||||
}
|
||||
|
||||
/// The same account, with Yandex answering in `language`. Loads the account
|
||||
/// again, since that's how the client learns whose library it reads.
|
||||
pub async fn in_language(&self, language: ContentLanguage) -> Result<Self> {
|
||||
let mut builder = yamuse::Client::builder().language(language.yamuse());
|
||||
if let Some(token) = &self.token {
|
||||
builder = builder.token(token.as_ref());
|
||||
}
|
||||
let inner = builder.build()?;
|
||||
if self.token.is_some() {
|
||||
inner.init().await?;
|
||||
}
|
||||
Ok(Self { inner, token: self.token.clone() })
|
||||
}
|
||||
|
||||
/// A client with no token, for previews and tests. Every account call fails.
|
||||
pub fn unauthenticated() -> Result<Self> {
|
||||
Ok(Self { inner: yamuse::Client::anonymous()?, token: None })
|
||||
|
||||
@@ -13,7 +13,7 @@ mod library;
|
||||
mod models;
|
||||
mod wave;
|
||||
|
||||
pub use client::{Account, YmClient};
|
||||
pub use client::{Account, ContentLanguage, YmClient};
|
||||
pub use clips::Clip;
|
||||
pub use library::{
|
||||
AlbumKind, AlbumPage, AlbumSummary, ArtistPage, ArtistSummary, LibraryPlaylists, PlaylistId,
|
||||
|
||||
@@ -16,6 +16,9 @@ pub enum AlbumKind {
|
||||
}
|
||||
|
||||
impl AlbumKind {
|
||||
pub const ALL: [AlbumKind; 5] =
|
||||
[AlbumKind::Album, AlbumKind::Single, AlbumKind::Compilation, AlbumKind::Podcast, AlbumKind::Audiobook];
|
||||
|
||||
fn from_api(meta_type: Option<&str>, kind: Option<&str>) -> Self {
|
||||
match (meta_type, kind) {
|
||||
(Some("podcast"), _) | (_, Some("podcast")) => AlbumKind::Podcast,
|
||||
|
||||
Reference in new issue
Block a user