pub enum LocalizedField {
Plain(String),
Multilingual(BTreeMap<String, String>),
}Expand description
A field that may be either a plain string or a multilingual map.
§Examples
use ceres_core::LocalizedField;
// Plain string (most portals)
let plain: LocalizedField = serde_json::from_str(r#""My Dataset""#).unwrap();
assert_eq!(plain.resolve("en"), "My Dataset");
assert_eq!(plain.resolve("de"), "My Dataset"); // language ignored for plain
// Multilingual object (e.g., Swiss portals)
let multi: LocalizedField = serde_json::from_str(
r#"{"en": "English", "de": "Deutsch", "fr": "Francais"}"#
).unwrap();
assert_eq!(multi.resolve("de"), "Deutsch");
assert_eq!(multi.resolve("en"), "English");
assert_eq!(multi.resolve("it"), "English"); // falls back to "en"Variants§
Plain(String)
A simple string value (most portals).
Multilingual(BTreeMap<String, String>)
A sorted map of language code to localized text (multilingual portals).
Uses BTreeMap for deterministic fallback ordering when neither the
preferred language nor "en" is available.
Implementations§
Source§impl LocalizedField
impl LocalizedField
Sourcepub fn resolve(&self, preferred_language: &str) -> String
pub fn resolve(&self, preferred_language: &str) -> String
Resolves the field to a single string using the preferred language.
Resolution strategy:
- If plain string, return it directly (language is ignored).
- If multilingual, try the preferred language (skip if empty).
- Fall back to
"en"if the preferred language is unavailable or empty. - Fall back to the first non-empty translation.
- Return an empty string if no translations exist.
Trait Implementations§
Source§impl Clone for LocalizedField
impl Clone for LocalizedField
Source§fn clone(&self) -> LocalizedField
fn clone(&self) -> LocalizedField
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LocalizedField
impl Debug for LocalizedField
Source§impl<'de> Deserialize<'de> for LocalizedField
impl<'de> Deserialize<'de> for LocalizedField
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for LocalizedField
impl PartialEq for LocalizedField
impl Eq for LocalizedField
impl StructuralPartialEq for LocalizedField
Auto Trait Implementations§
impl Freeze for LocalizedField
impl RefUnwindSafe for LocalizedField
impl Send for LocalizedField
impl Sync for LocalizedField
impl Unpin for LocalizedField
impl UnsafeUnpin for LocalizedField
impl UnwindSafe for LocalizedField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more