Skip to main content

FormatType

Enum FormatType 

Source
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

Source

pub fn extension(&self) -> &'static str

Returns the typical file extension for this format.

Source

pub fn language(&self) -> Option<&String>

Returns the language code for this format, if available.

Source

pub fn with_language(&self, lang: Option<String>) -> Self

Recreates the format type with a new language code, if applicable.

Source

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

Source§

fn clone(&self) -> FormatType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormatType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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());
Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for FormatType

Source§

fn eq(&self, other: &FormatType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for FormatType

Source§

impl StructuralPartialEq for FormatType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.