pub enum FormatType {
AndroidStrings(Option<String>),
Strings(Option<String>),
Xcstrings,
CSV,
TSV,
}Expand description
Represents all supported localization file formats for generic handling.
This enum allows you to work with any supported file format in a type-safe way.
Variants§
AndroidStrings(Option<String>)
Android strings.xml format, with optional language code.
Strings(Option<String>)
Apple .strings format, with optional language code.
Xcstrings
Apple .xcstrings format (no language code).
CSV
CSV format (multi-language support built-in).
TSV
TSV format (multi-language support built-in).
Implementations§
Source§impl FormatType
impl FormatType
Sourcepub fn language(&self) -> Option<&String>
pub fn language(&self) -> Option<&String>
Returns the language code for this format, if available.
Sourcepub fn with_language(&self, lang: Option<String>) -> Self
pub fn with_language(&self, lang: Option<String>) -> Self
Recreates the format type with a new language code, if applicable.
Sourcepub fn matches_language_of(&self, other: &FormatType) -> bool
pub fn matches_language_of(&self, other: &FormatType) -> bool
Checks if this format matches the language of another format.
For Xcstrings, it always returns true since it has no language
and matches any other Xcstrings. Note that this does not look at the
actual content of the files, only the format type and its language. So if the
the xcstrings file does not have that language, it will still return true.
§Example
use langcodec::formats::FormatType;
let format1 = FormatType::AndroidStrings(Some("en".to_string()));
let format2 = FormatType::AndroidStrings(Some("en".to_string()));
let format3 = FormatType::Strings(Some("fr".to_string()));
let format4 = FormatType::Xcstrings;
assert!(format1.matches_language_of(&format2));
assert!(!format1.matches_language_of(&format3));
assert!(format4.matches_language_of(&format4));
assert!(format4.matches_language_of(&format1));This is useful for ensuring that two formats can be compared or converted without language mismatch issues.
Trait Implementations§
Source§impl Clone for FormatType
impl Clone for FormatType
Source§fn clone(&self) -> FormatType
fn clone(&self) -> FormatType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FormatType
impl Debug for FormatType
Source§impl Display for FormatType
Implements std::fmt::Display for FormatType.
impl Display for FormatType
Implements std::fmt::Display for FormatType.
This provides a human-friendly string for each format type:
AndroidStrings(_)→"android"Strings(_)→"strings"Xcstrings→"xcstrings"
§Example
use langcodec::formats::FormatType;
use std::fmt::Display;
assert_eq!(FormatType::AndroidStrings(None).to_string(), "android");
assert_eq!(FormatType::Strings(None).to_string(), "strings");
assert_eq!(FormatType::Xcstrings.to_string(), "xcstrings");Source§impl FromStr for FormatType
Implements std::str::FromStr for FormatType.
impl FromStr for FormatType
Implements std::str::FromStr for FormatType.
Accepts the following case-insensitive strings:
"android","androidstrings","xml"→FormatType::AndroidStrings(None)"strings"→FormatType::Strings(None)"xcstrings"→FormatType::Xcstrings
Returns crate::error::Error::UnknownFormat for unknown strings.
§Example
use langcodec::formats::FormatType;
use std::str::FromStr;
assert_eq!(FormatType::from_str("android").unwrap(), FormatType::AndroidStrings(None));
assert_eq!(FormatType::from_str("strings").unwrap(), FormatType::Strings(None));
assert_eq!(FormatType::from_str("xcstrings").unwrap(), FormatType::Xcstrings);
assert!(FormatType::from_str("foobar").is_err());