Repository: kellpossible/cargo-i18n (language: rust)

Issue:
Config option to specify the domain to use for i18n-embed and i18n-embed-fl when using Fluent
(override the default which is the crate name)


Discussion / hints:

Fix patch:
diff --git a/i18n-config/src/fluent.rs b/i18n-config/src/fluent.rs
index 60723ae..61cfa2c 100644
--- a/i18n-config/src/fluent.rs
+++ b/i18n-config/src/fluent.rs
@@ -10,4 +10,9 @@ pub struct FluentConfig {
     /// The paths inside the assets directory should be  structured
     /// like so: `assets_dir/{language}/{domain}.ftl`
     pub assets_dir: PathBuf,
+
+    /// (Optional) Domain name to override default value (i.e. package name)
+    /// The paths inside the assets directory should be  structured
+    /// like so: `assets_dir/{language}/{domain}.ftl`
+    pub domain: Option<String>,
 }
diff --git a/i18n-embed/i18n-embed-impl/src/lib.rs b/i18n-embed/i18n-embed-impl/src/lib.rs
index e956d9b..b8e556c 100644
--- a/i18n-embed/i18n-embed-impl/src/lib.rs
+++ b/i18n-embed/i18n-embed-impl/src/lib.rs
@@ -85,7 +85,6 @@ pub fn gettext_language_loader(_: proc_macro::TokenStream) -> proc_macro::TokenS
 pub fn fluent_language_loader(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
     let manifest = find_crate::Manifest::new().expect("Error reading Cargo.toml");
     let current_crate_package = manifest.crate_package().expect("Error reading Cargo.toml");
-    let domain = syn::LitStr::new(&current_crate_package.name, proc_macro2::Span::call_site());
 
     // Special case for when this macro is invoked in i18n-embed tests/docs
     let i18n_embed_crate_name = if current_crate_package.name == "i18n_embed" {
@@ -129,6 +128,12 @@ pub fn fluent_language_loader(_: proc_macro::TokenStream) -> proc_macro::TokenSt
         proc_macro2::Span::call_site(),
     );
 
+    let domain_str = config
+        .fluent
+        .and_then(|f| f.domain)
+        .unwrap_or(current_crate_package.name);
+    let domain = syn::LitStr::new(&domain_str, proc_macro2::Span::call_site());
+
     let gen = quote::quote! {
         #i18n_embed_crate_ident::fluent::FluentLanguageLoader::new(
             #domain,


Test patch: