i18n-embed-impl-0.8.0/.cargo_vcs_info.json0000644000000001120000000000100136230ustar { "git": { "sha1": "72358f64f7cb4c971d2173475cf78765a89cd7c8" } } i18n-embed-impl-0.8.0/.gitignore000064400000000000000000000000450072674642500144400ustar 00000000000000/target **/*.rs.bk .vscode Cargo.locki18n-embed-impl-0.8.0/Cargo.toml0000644000000030040000000000100116240ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "i18n-embed-impl" version = "0.8.0" authors = ["Luke Frisken "] description = "Macro implementations for i18n-embed" readme = "../README.md" keywords = ["build", "i18n", "gettext", "locale", "fluent"] categories = ["localization", "internationalization"] license = "MIT" repository = "https://github.com/kellpossible/cargo-i18n/tree/master/i18n-embed" [lib] proc-macro = true [dependencies.find-crate] version = "0.6" optional = true [dependencies.i18n-config] version = "0.4" optional = true [dependencies.proc-macro2] version = "1.0" [dependencies.quote] version = "1.0" optional = true [dependencies.syn] version = "1.0" features = ["derive", "proc-macro", "parsing", "printing", "extra-traits"] default-features = false [dev-dependencies.rust-embed] version = "6" [features] default = [] fluent-system = ["i18n-config", "find-crate", "quote"] gettext-system = ["i18n-config", "find-crate", "quote"] [badges.maintenance] status = "actively-developed" i18n-embed-impl-0.8.0/Cargo.toml.orig000064400000000000000000000017620072674642500153460ustar 00000000000000[package] authors = ["Luke Frisken "] description = "Macro implementations for i18n-embed" edition = "2018" keywords = ["build", "i18n", "gettext", "locale", "fluent"] categories = ["localization", "internationalization"] license = "MIT" name = "i18n-embed-impl" readme = "../README.md" repository = "https://github.com/kellpossible/cargo-i18n/tree/master/i18n-embed" version = "0.8.0" [badges] maintenance = { status = "actively-developed" } [lib] proc-macro = true [dependencies] find-crate = { version = "0.6", optional = true } i18n-config = { version = "0.4", path = "../../i18n-config", optional = true } proc-macro2 = "1.0" quote = { version = "1.0", optional = true } [dev-dependencies] rust-embed = "6" [dependencies.syn] version = "1.0" default-features = false features = ["derive", "proc-macro", "parsing", "printing", "extra-traits",] [features] default = [] gettext-system = ["i18n-config", "find-crate", "quote"] fluent-system = ["i18n-config", "find-crate", "quote"] i18n-embed-impl-0.8.0/src/lib.rs000064400000000000000000000116320072674642500143570ustar 00000000000000/// A procedural macro to create a new `GettextLanguageLoader` using /// the current crate's `i18n.toml` configuration, and domain. /// /// ⚠️ *This API requires the following crate features to be /// activated: `gettext-system`.* /// /// ## Example /// /// ```ignore /// use i18n_embed::gettext::{gettext_language_loader, GettextLanguageLoader}; /// let my_language_loader: GettextLanguageLoader = gettext_language_loader!(); /// ``` #[proc_macro] #[cfg(feature = "gettext-system")] pub fn gettext_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"); // 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" { "i18n_embed".to_string() } else { manifest .find(|s| s == "i18n-embed") .expect("i18n-embed should be an active dependency in your Cargo.toml") .name }; let i18n_embed_crate_ident = syn::Ident::new(&i18n_embed_crate_name, proc_macro2::Span::call_site()); let config_file_path = i18n_config::locate_crate_paths() .unwrap_or_else(|error| { panic!( "gettext_language_loader!() is unable to locate i18n config file: {}", error ) }) .i18n_config_file; let config = i18n_config::I18nConfig::from_file(&config_file_path).unwrap_or_else(|err| { panic!( "gettext_language_loader!() had a problem reading i18n config file {0:?}: {1}", std::fs::canonicalize(&config_file_path).unwrap_or_else(|_| config_file_path.clone()), err ) }); if config.gettext.is_none() { panic!( "gettext_language_loader!() had a problem parsing i18n config file {0:?}: there is no `[gettext]` section", std::fs::canonicalize(&config_file_path).unwrap_or(config_file_path) ) } let fallback_language = syn::LitStr::new( &config.fallback_language.to_string(), proc_macro2::Span::call_site(), ); let gen = quote::quote! { #i18n_embed_crate_ident::gettext::GettextLanguageLoader::new( module_path!(), #fallback_language.parse().unwrap(), ) }; gen.into() } /// A procedural macro to create a new `FluentLanguageLoader` using /// the current crate's `i18n.toml` configuration, and domain. /// /// ⚠️ *This API requires the following crate features to be /// activated: `fluent-system`.* /// /// ## Example /// /// ```ignore /// use i18n_embed::fluent::{fluent_language_loader, FluentLanguageLoader}; /// let my_language_loader: FluentLanguageLoader = fluent_language_loader!(); /// ``` #[proc_macro] #[cfg(feature = "fluent-system")] 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(¤t_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" { "i18n_embed".to_string() } else { manifest .find(|s| s == "i18n-embed") .expect("i18n-embed should be an active dependency in your Cargo.toml") .name }; let i18n_embed_crate_ident = syn::Ident::new(&i18n_embed_crate_name, proc_macro2::Span::call_site()); let config_file_path = i18n_config::locate_crate_paths() .unwrap_or_else(|error| { panic!( "fluent_language_loader!() is unable to locate i18n config file: {}", error ) }) .i18n_config_file; let config = i18n_config::I18nConfig::from_file(&config_file_path).unwrap_or_else(|err| { panic!( "fluent_language_loader!() had a problem reading i18n config file {0:?}: {1}", std::fs::canonicalize(&config_file_path).unwrap_or_else(|_| config_file_path.clone()), err ) }); if config.fluent.is_none() { panic!( "fluent_language_loader!() had a problem parsing i18n config file {0:?}: there is no `[fluent]` section", std::fs::canonicalize(&config_file_path).unwrap_or(config_file_path) ) } let fallback_language = syn::LitStr::new( &config.fallback_language.to_string(), proc_macro2::Span::call_site(), ); let gen = quote::quote! { #i18n_embed_crate_ident::fluent::FluentLanguageLoader::new( #domain, #fallback_language.parse().unwrap(), ) }; gen.into() }