Struct i18n_config::Crate
source · pub struct Crate<'a> {
pub name: String,
pub version: String,
pub path: PathBuf,
pub parent: Option<&'a Crate<'a>>,
pub config_file_path: PathBuf,
pub i18n_config: Option<I18nConfig>,
}
Expand description
Represents a rust crate.
Fields§
§name: String
The name of the crate.
version: String
The version of the crate.
path: PathBuf
The path to the crate.
parent: Option<&'a Crate<'a>>
Path to the parent crate which is triggering the localization for this crate.
config_file_path: PathBuf
The file path expected to be used for i18n_config
relative to this crate’s root.
i18n_config: Option<I18nConfig>
The localization config for this crate (if it exists).
Implementations§
source§impl<'a> Crate<'a>
impl<'a> Crate<'a>
sourcepub fn from<P1: Into<PathBuf>, P2: Into<PathBuf>>(
path: P1,
parent: Option<&'a Crate<'_>>,
config_file_path: P2
) -> Result<Crate<'a>, I18nConfigError>
pub fn from<P1: Into<PathBuf>, P2: Into<PathBuf>>( path: P1, parent: Option<&'a Crate<'_>>, config_file_path: P2 ) -> Result<Crate<'a>, I18nConfigError>
Read crate from Cargo.toml
i18n config using the
config_file_path
(if there is one).
sourcepub fn module_name(&self) -> String
pub fn module_name(&self) -> String
The name of the module/library used for this crate. Replaces
-
characters with _
in the crate name.
sourcepub fn parent_active_config(
&'a self
) -> Result<Option<(&'a Crate<'_>, &'a I18nConfig)>, I18nConfigError>
pub fn parent_active_config( &'a self ) -> Result<Option<(&'a Crate<'_>, &'a I18nConfig)>, I18nConfigError>
If there is a parent, get it’s I18nConfig#active_config(), otherwise return None.
sourcepub fn active_config(
&'a self
) -> Result<Option<(&'a Crate<'_>, &'a I18nConfig)>, I18nConfigError>
pub fn active_config( &'a self ) -> Result<Option<(&'a Crate<'_>, &'a I18nConfig)>, I18nConfigError>
Identify the config which should be used for this crate, and the crate (either this crate or one of it’s parents) associated with that config.
sourcepub fn config_or_err(&self) -> Result<&I18nConfig, I18nConfigError>
pub fn config_or_err(&self) -> Result<&I18nConfig, I18nConfigError>
Get the I18nConfig in this crate, or return an error if there is none present.
sourcepub fn gettext_config_or_err(&self) -> Result<&GettextConfig, I18nConfigError>
pub fn gettext_config_or_err(&self) -> Result<&GettextConfig, I18nConfigError>
Get the GettextConfig in this crate, or return an error if there is none present.
sourcepub fn collated_subcrate(&self) -> bool
pub fn collated_subcrate(&self) -> bool
If this crate has a parent, check whether the parent wants to collate subcrates string extraction, as per the parent’s GettextConfig#collate_extracted_subcrates. This also requires that the current crate’s GettextConfig#extract_to_parent is true.
Returns false if there is no parent or the parent has no gettext config.
sourcepub fn find_parent(&self) -> Option<Crate<'a>>
pub fn find_parent(&self) -> Option<Crate<'a>>
Attempt to resolve the parents of this crate which have this crate listed as a subcrate in their i18n config.