Skip to content

Commit

Permalink
Release new version of i18n-embed and i18n-embed-fl
Browse files Browse the repository at this point in the history
- Bump i18n-embed to 0.13.5
- Bump i18n-embed-fl to 0.6.5 (requiring i18n-embed >=0.13.5)
- Fix clippy lints
  • Loading branch information
Luke Frisken committed Jan 9, 2023
1 parent 4b4d35f commit 46f08a2
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 99 deletions.
23 changes: 5 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions i18n-build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for `i18n-build`

## master

### Internal

+ Fix clippy warnings.

## v0.8.2

+ Update `rust-embed` to `6.3` to address [RUSTSEC-2021-0126](https://rustsec.org/advisories/RUSTSEC-2021-0126.html).
Expand Down
2 changes: 1 addition & 1 deletion i18n-build/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ impl Display for PathError {
),
};

write!(f, "{}", message)
write!(f, "{message}")
}
}
14 changes: 7 additions & 7 deletions i18n-build/src/gettext_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ pub fn run_xtr(

match &gettext_config.copyright_holder {
Some(copyright_holder) => {
xtr.args(&["--copyright-holder", copyright_holder.as_str()]);
xtr.args(["--copyright-holder", copyright_holder.as_str()]);
}
None => {}
}

match &gettext_config.msgid_bugs_address {
Some(msgid_bugs_address) => {
xtr.args(&["--msgid-bugs-address", msgid_bugs_address.as_str()]);
xtr.args(["--msgid-bugs-address", msgid_bugs_address.as_str()]);
}
None => {}
}

xtr.args(&[
xtr.args([
"--package-name",
crt.name.as_str(),
"--package-version",
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn run_msgcat<P: AsRef<Path>, I: IntoIterator<Item = P>>(
};

util::create_dir_all_if_not_exists(
&interim_output_pot_path
interim_output_pot_path
.parent()
.expect("expected there to be a parent to the interim output pot path"),
)?;
Expand Down Expand Up @@ -260,7 +260,7 @@ pub fn run_msginit(crt: &Crate, pot_dir: &Path, po_dir: &Path) -> Result<()> {
PathType::File,
))?
),
format!("--locale={}.UTF-8", locale),
format!("--locale={locale}.UTF-8"),
format!(
"--output={}",
po_path.to_str().ok_or_else(|| PathError::not_valid_utf8(
Expand Down Expand Up @@ -307,7 +307,7 @@ pub fn run_msgmerge(crt: &Crate, pot_dir: &Path, po_dir: &Path) -> Result<()> {
util::check_path_exists(&po_file_path)?;

let mut msgmerge = Command::new(msgmerge_command_name);
msgmerge.args(&[
msgmerge.args([
"--silent",
"--backup=none",
"--update",
Expand Down Expand Up @@ -448,7 +448,7 @@ pub fn run(crt: &Crate) -> Result<()> {
crt.path.canonicalize().unwrap() != config_crate.path.canonicalize().unwrap();
run_xtr(
crt,
&gettext_config,
gettext_config,
src_dir.as_path(),
pot_dir.as_path(),
prepend_crate_path,
Expand Down
6 changes: 6 additions & 0 deletions i18n-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# `i18n-config` Changelog

## master

### Internal

+ Fix clippy warnings.

## v0.4.3

+ Prevent a panic when the crate root is a workspace. [#93](https://github.com/kellpossible/cargo-i18n/pull/93) thanks to [@ctrlcctrlv](https://github.com/ctrlcctrlv).
Expand Down
2 changes: 1 addition & 1 deletion i18n-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a> Crate<'a> {
/// The name of the module/library used for this crate. Replaces
/// `-` characters with `_` in the crate name.
pub fn module_name(&self) -> String {
self.name.replace("-", "_")
self.name.replace('-', "_")
}

/// If there is a parent, get it's
Expand Down
14 changes: 14 additions & 0 deletions i18n-embed-fl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog for `i18n-embed-fl`

## v0.6.5

### New Features

+ Support fluent attributes [#98](https://github.com/kellpossible/cargo-i18n/pull/98) thanks to [@Almost-Senseless-Coder](https://github.com/Almost-Senseless-Coder)!
+ Tweaked the `fl!()` macro definition such that it optionally accepts an attribute ID in addition to a message ID and arguments.
+ Implemented compile-time verification of attributes.

### Internal

+ Bump `i18n-embed` dependency to version `0.13.5`.
+ Bump `env_logger` dev dependency to version `0.10`.
+ Fix clippy warnings.

## v0.6.4

+ Update `dashmap` to version `5.1`.
Expand Down
6 changes: 3 additions & 3 deletions i18n-embed-fl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "i18n-embed-fl"
description = "Macro to perform compile time checks when using the i18n-embed crate and the fluent localization system"
categories = ["localization", "internationalization", "development-tools"]
version = "0.6.4"
version = "0.6.5"
authors = ["Luke Frisken <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -17,7 +17,7 @@ find-crate = "0.6"
fluent = "0.16"
fluent-syntax = "0.11"
i18n-config = { path = "../i18n-config", version = "0.4" }
i18n-embed = { path = "../i18n-embed", version = "0.13", features = ["fluent-system", "filesystem-assets"]}
i18n-embed = { path = "../i18n-embed", version = "0.13.5", features = ["fluent-system", "filesystem-assets"]}
lazy_static = "1.4"
proc-macro2 = "1.0"
proc-macro-error = "1.0"
Expand All @@ -32,6 +32,6 @@ features = ["derive", "proc-macro", "parsing", "printing", "extra-traits", "full

[dev-dependencies]
doc-comment = "0.3"
env_logger = "0.9"
env_logger = "0.10"
pretty_assertions = "1.1"
rust-embed = "^6.3"
96 changes: 45 additions & 51 deletions i18n-embed-fl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ pub fn fl(input: TokenStream) -> TokenStream {

let config_file_path = &crate_paths.i18n_config_file;

let config = i18n_config::I18nConfig::from_file(&config_file_path).unwrap_or_else(|err| {
let config = i18n_config::I18nConfig::from_file(config_file_path).unwrap_or_else(|err| {
abort! {
proc_macro2::Span::call_site(),
format!(
"fl!() had a problem reading i18n config file {0:?}: {1}",
config_file_path, err);
"fl!() had a problem reading i18n config file {config_file_path:?}: {err}"
);
help = "Try creating the `i18n.toml` configuration file.";
}
});
Expand All @@ -366,9 +366,9 @@ pub fn fl(input: TokenStream) -> TokenStream {
abort! {
proc_macro2::Span::call_site(),
format!(
"fl!() had a problem parsing i18n config file {0:?}: \
there is no `[fluent]` subsection.",
config_file_path);
"fl!() had a problem parsing i18n config file {config_file_path:?}: \
there is no `[fluent]` subsection."
);
help = "Add the `[fluent]` subsection to `i18n.toml`, \
along with its required `assets_dir`.";
}
Expand Down Expand Up @@ -397,8 +397,9 @@ pub fn fl(input: TokenStream) -> TokenStream {
proc_macro2::Span::call_site(),
format!(
"fl!() was unable to load the localization \
file for the `fallback_language` (\"{0}\"): {1}",
fallback_language, file,);
file for the `fallback_language` \
(\"{fallback_language}\"): {file}"
);
help = "Try creating the required fluent localization file.";
}
}
Expand Down Expand Up @@ -549,13 +550,13 @@ pub fn fl(input: TokenStream) -> TokenStream {
};

if let Some(message_id_str) = &message_id_string {
if !checked_loader_has_message && !domain_data.loader.has(&message_id_str) {
if !checked_loader_has_message && !domain_data.loader.has(message_id_str) {
let suggestions =
fuzzy_message_suggestions(&domain_data.loader, message_id_str, 5).join("\n");

let hint = format!(
"Perhaps you are looking for one of the following messages?\n\n{}",
suggestions
"Perhaps you are looking for one of the following messages?\n\n\
{suggestions}"
);

emit_error! {
Expand All @@ -572,38 +573,36 @@ pub fn fl(input: TokenStream) -> TokenStream {

hint = hint;
};
} else {
if let Some(attr_id_str) = &attr_str {
if !checked_message_has_attribute
&& !&domain_data.loader.has_attr(message_id_str, attr_id_str)
{
let suggestions = &domain_data
.loader
.with_fluent_message(&message_id_str, |message| {
fuzzy_attribute_suggestions(&message, &attr_id_str, 5).join("\n")
})
.unwrap();
} else if let Some(attr_id_str) = &attr_str {
if !checked_message_has_attribute
&& !&domain_data.loader.has_attr(message_id_str, attr_id_str)
{
let suggestions = &domain_data
.loader
.with_fluent_message(message_id_str, |message| {
fuzzy_attribute_suggestions(&message, attr_id_str, 5).join("\n")
})
.unwrap();

let hint = format!(
"Perhaps you are looking for one of the following attributes?\n\n\
{suggestions}"
);

let hint = format!(
"Perhaps you are looking for one of the following attributes?\n\n{}",
suggestions
emit_error! {
attr_lit,
format!(
"fl!() `attribute_id` validation failed. `attribute_id` \
of \"{0}\" does not exist in the `fallback_language` (\"{1}\")",
attr_id_str,
domain_data.loader.current_language(),
);
help = "Enter the correct `attribute_id` or create \
the attribute associated with the message in the localization file if the \
intended attribute does not yet exist.";

emit_error! {
attr_lit,
format!(
"fl!() `attribute_id` validation failed. `attribute_id` \
of \"{0}\" does not exist in the `fallback_language` (\"{1}\")",
attr_id_str,
domain_data.loader.current_language(),
);
help = "Enter the correct `attribute_id` or create \
the attribute associated with the message in the localization file if the \
intended attribute does not yet exist.";

hint = hint;
};
}
hint = hint;
};
}
}
}
Expand Down Expand Up @@ -645,7 +644,6 @@ fn fuzzy_attribute_suggestions(
) -> Vec<String> {
let mut scored_attributes: Vec<(String, usize)> = message
.attributes()
.into_iter()
.map(|attribute| {
(
attribute.id().to_string(),
Expand Down Expand Up @@ -676,14 +674,13 @@ fn check_message_args(

let key_args: Vec<String> = specified_args
.keys()
.into_iter()
.map(|key| {
let arg = key.value();

if !args_set.contains(arg.as_str()) {
let available_args: String = args_set
.iter()
.map(|arg| format!("`{}`", arg))
.map(|arg| format!("`{arg}`"))
.collect::<Vec<String>>()
.join(", ");

Expand All @@ -710,7 +707,7 @@ fn check_message_args(
.iter()
.filter_map(|arg| {
if !key_args_set.contains(arg) {
Some(format!("`{}`", arg))
Some(format!("`{arg}`"))
} else {
None
}
Expand Down Expand Up @@ -744,14 +741,13 @@ fn check_attribute_args(

let key_args: Vec<String> = specified_args
.keys()
.into_iter()
.map(|key| {
let arg = key.value();

if !args_set.contains(arg.as_str()) {
let available_args: String = args_set
.iter()
.map(|arg| format!("`{}`", arg))
.map(|arg| format!("`{arg}`"))
.collect::<Vec<String>>()
.join(", ");

Expand All @@ -778,7 +774,7 @@ fn check_attribute_args(
.iter()
.filter_map(|arg| {
if !key_args_set.contains(arg) {
Some(format!("`{}`", arg))
Some(format!("`{arg}`"))
} else {
None
}
Expand Down Expand Up @@ -833,11 +829,9 @@ fn args_from_inline_expression<S: Copy>(inline_expr: &InlineExpression<S>, args:
InlineExpression::TermReference {
id: _,
attribute: _,
arguments,
arguments: Some(call_args),
} => {
if let Some(call_args) = arguments {
args_from_call_arguments(call_args, args);
}
args_from_call_arguments(call_args, args);
}
InlineExpression::VariableReference { id } => args.push(id.name),
InlineExpression::Placeable { expression } => args_from_expression(expression, args),
Expand Down
Loading

0 comments on commit 46f08a2

Please sign in to comment.