How to export a macro that relies on third party crate

I'm trying to export a macro that wraps another crates macro, but at the usage site I get the error that the other crate's dependency is undeclared.

Macro export:

#[macro_export]
macro_rules! fl {
    ($message_id:literal) => {{
        i18n_embed_fl::fl!($crate::get_language_loader(), $message_id)
    }};

    ($message_id:literal, $($args:expr),*) => {{
        i18n_embed_fl::fl!($crate::get_language_loader(), $message_id, $($args), *)
    }};
}

Usage site in another crate:

window.set_title(&fl!("hello-world"));

Error:

error[E0433]: failed to resolve: use of undeclared crate or module `i18n_embed_fl`
  --> nih\src\main.rs:28:27
   |
28 |         window.set_title(&fl!("hello-world")); // todo: this should not be config but language i18n file.
   |                           ^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `i18n_embed_fl`
   |
   = note: this error originates in the macro `fl` (in Nightly builds, run with -Z macro-backtrace for more info)

How can I export this macro without needing to explicitly add the i18n_embed_fl crate and use it within each crate I want to use the fl macro?

you can re-export the dependencies. e.g.:

method 1:

// re-export the macro (rename to avoid name clash)
pub use i18n_embed_fl::fl as original_fl;
#[macro_export]
macro_rules! fl {
    ($message_id:literal) => {{
        $crate::original_fl!($crate::get_language_loader(), $message_id)
    }};
    //...
}

method 2:

// re-export the crate (can rename, e.g. for abbreviation) 
pub use i18n_embed_fl as i18n;
#[macro_export]
macro_rules! fl {
    ($message_id:literal) => {{
        $crate::i18n::fl!($crate::get_language_loader(), $message_id)
    }};
    //...
}
2 Likes

Thanks. I thought I had tried that but I'd missed the $crate part from the usage.

Appreciate the help.