Struct Intl

Source
pub struct Intl { /* private fields */ }
Expand description

Internationalization index file.

Translations are loaded by convention from the directory pointed to by the arb-dir. The default convention is to use app as the prefix concatenated with a lowercase language identifier delimited by an underscore. Language identifiers in file names should use underscores and not hyphens. For example, the file name for the EN-US language would be app_en_us.arb.

Implementations§

Source§

impl Intl

Source

pub fn new(path: impl AsRef<Path>) -> Result<Self>

Load the YAML file using the default file name prefix.

Source

pub fn new_with_prefix( path: impl AsRef<Path>, name_prefix: Option<String>, ) -> Result<Self>

Load the YAML file with a given file name prefix.

Source

pub fn arb_dir(&self) -> &str

Directory for application resource bundles.

Source

pub fn template_arb_file(&self) -> &str

Template application resource bundle.

Source

pub fn name_prefix(&self) -> &str

Prefix used to compute file names.

Source

pub fn overrides_dir(&self) -> Option<&str>

Directory for override files.

Source

pub fn template_language(&self) -> &Lang

Language of the template application resource bundle.

Source

pub fn cache(&self) -> &ArbCache

Get the cache of original translations.

Source

pub fn template_content(&self) -> Result<ArbFile>

Load and parse the template application resource bundle.

Source

pub fn parent_path(&self) -> Result<&Path>

Compute the parent of the index file.

Source

pub fn file_path(&self, lang: Lang) -> Result<PathBuf>

Path to a language file.

Source

pub fn format_file_name(&self, lang: Lang) -> String

Format a language to a file name.

Source

pub fn parse_file_name(&self, path: impl AsRef<Path>) -> Option<Lang>

Parse a file path to a language.

Source

pub fn arb_directory(&self) -> Result<PathBuf>

Compute the application resource bundle directory relative to the parent of the internationalization index file.

Source

pub fn list_translated(&self) -> Result<BTreeMap<Lang, PathBuf>>

List translations in the configured arb-dir.

Source

pub fn list_directory( &self, dir: impl AsRef<Path>, ) -> Result<BTreeMap<Lang, PathBuf>>

List translated languages in a directory.

Source

pub fn load_overrides( &self, dir: impl AsRef<Path>, languages: Option<Vec<Lang>>, ) -> Result<HashMap<Lang, ArbFile>>

Attempt to load override definitions.

If a languages list is given only load the given languages.

Source

pub fn load(&self, lang: Lang) -> Result<ArbFile>

Load a language file from disc.

Source

pub fn load_or_default(&self, lang: Lang) -> Result<ArbFile>

Load a language file if it exists otherwise use an empty file.

Source

pub async fn translate( &mut self, api: &DeeplApi, options: TranslationOptions, ) -> Result<TranslateResult>

Translate to a target language.

Placeholders are converted to XML tags and ignored from translation to preserve the placeholder names.

Trait Implementations§

Source§

impl Debug for Intl

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Intl

§

impl RefUnwindSafe for Intl

§

impl Send for Intl

§

impl Sync for Intl

§

impl Unpin for Intl

§

impl UnwindSafe for Intl

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,