Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Mar 31, 2024
1 parent ee2f9f4 commit ce0de56
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ impl Config {
{
let mut translators = IndexMap::new();

config.translators.unwrap_or_default().iter().try_for_each(
|(key, value)| -> Result<()> {
config
.translators
.unwrap_or_default()
.into_iter()
.try_for_each(|(key, value)| -> Result<()> {
match value {
Data::File(DataFile { path }) => {
let filepath = config_path.join(path);
Expand All @@ -298,45 +301,46 @@ impl Config {
}
Data::Simple(value) => {
let filepath = config_path.join(value).to_str().unwrap().to_string();
translators.insert(key.to_owned(), Data::Simple(filepath));
translators.insert(key, Data::Simple(filepath));
}
_ => Err(anyhow!("{value:?} not allowed in the translator table"))
.with_context(|| format!("Invalid configuration file {filepath:?}."))?,
};
Ok(())
},
)?;
})?;
config.translators = Some(translators);
}

// Translation
let mut translation = IndexMap::new();

config.translation.unwrap_or_default().iter().try_for_each(
|(key, value)| -> Result<()> {
config
.translation
.unwrap_or_default()
.into_iter()
.try_for_each(|(key, value)| -> Result<()> {
match value {
Data::File(DataFile { path }) => {
let filepath = config_path.join(path);
let conf = Config::from_filesystem(&filepath, fs)?;
translation.extend(conf.translation.unwrap_or_default());
}
Data::Simple(_) | Data::Multi(_) => {
translation.insert(key.to_owned(), value.to_owned());
translation.insert(key, value);
}
Data::Detailed(DetailedData { value, alias }) => {
alias.iter().chain([key.to_owned()].iter()).for_each(|e| {
alias.iter().chain([key].iter()).for_each(|e| {
translation.insert(e.to_owned(), Data::Simple(value.to_owned()));
});
}
Data::MoreDetailed(MoreDetailedData { values, alias }) => {
alias.iter().chain([key.to_owned()].iter()).for_each(|key| {
alias.iter().chain([key].iter()).for_each(|key| {
translation.insert(key.to_owned(), Data::Multi(values.to_owned()));
});
}
};
Ok(())
},
)?;
})?;

config.translation = Some(translation);

Expand Down

0 comments on commit ce0de56

Please sign in to comment.