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
impl Intl
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Load the YAML file using the default file name prefix.
Sourcepub fn new_with_prefix(
path: impl AsRef<Path>,
name_prefix: Option<String>,
) -> Result<Self>
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.
Sourcepub fn template_arb_file(&self) -> &str
pub fn template_arb_file(&self) -> &str
Template application resource bundle.
Sourcepub fn name_prefix(&self) -> &str
pub fn name_prefix(&self) -> &str
Prefix used to compute file names.
Sourcepub fn overrides_dir(&self) -> Option<&str>
pub fn overrides_dir(&self) -> Option<&str>
Directory for override files.
Sourcepub fn template_language(&self) -> &Lang
pub fn template_language(&self) -> &Lang
Language of the template application resource bundle.
Sourcepub fn template_content(&self) -> Result<ArbFile>
pub fn template_content(&self) -> Result<ArbFile>
Load and parse the template application resource bundle.
Sourcepub fn parent_path(&self) -> Result<&Path>
pub fn parent_path(&self) -> Result<&Path>
Compute the parent of the index file.
Sourcepub fn format_file_name(&self, lang: Lang) -> String
pub fn format_file_name(&self, lang: Lang) -> String
Format a language to a file name.
Sourcepub fn parse_file_name(&self, path: impl AsRef<Path>) -> Option<Lang>
pub fn parse_file_name(&self, path: impl AsRef<Path>) -> Option<Lang>
Parse a file path to a language.
Sourcepub fn arb_directory(&self) -> Result<PathBuf>
pub fn arb_directory(&self) -> Result<PathBuf>
Compute the application resource bundle directory relative to the parent of the internationalization index file.
Sourcepub fn list_translated(&self) -> Result<BTreeMap<Lang, PathBuf>>
pub fn list_translated(&self) -> Result<BTreeMap<Lang, PathBuf>>
List translations in the configured arb-dir
.
Sourcepub fn list_directory(
&self,
dir: impl AsRef<Path>,
) -> Result<BTreeMap<Lang, PathBuf>>
pub fn list_directory( &self, dir: impl AsRef<Path>, ) -> Result<BTreeMap<Lang, PathBuf>>
List translated languages in a directory.
Sourcepub fn load_overrides(
&self,
dir: impl AsRef<Path>,
languages: Option<Vec<Lang>>,
) -> Result<HashMap<Lang, ArbFile>>
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.
Sourcepub fn load_or_default(&self, lang: Lang) -> Result<ArbFile>
pub fn load_or_default(&self, lang: Lang) -> Result<ArbFile>
Load a language file if it exists otherwise use an empty file.
Sourcepub async fn translate(
&mut self,
api: &DeeplApi,
options: TranslationOptions,
) -> Result<TranslateResult>
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.