feat(i18n): Make i18n default feature and always use embedded assets
- Add i18n to default features in Cargo.toml - Modify I18nBundle::load() to always use embedded assets when i18n feature is enabled - Remove confusing warning about "locales directory not found" - Locales are now embedded via rust-embed by default Fixes issue where translations showed placeholders like [nav-chat] instead of actual text. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5d73abe9f8
commit
84e8f1fe3a
2 changed files with 45 additions and 41 deletions
|
|
@ -10,9 +10,9 @@ keywords = ["bot", "chatbot", "ai", "conversational", "library"]
|
|||
categories = ["api-bindings", "web-programming"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["database", "i18n"]
|
||||
full = ["database", "http-client", "validation", "resilience", "i18n"]
|
||||
database = []
|
||||
database = ["i18n"]
|
||||
http-client = ["dep:reqwest"]
|
||||
validation = []
|
||||
resilience = []
|
||||
|
|
|
|||
|
|
@ -173,18 +173,21 @@ pub struct I18nBundle {
|
|||
|
||||
impl I18nBundle {
|
||||
pub fn load(base_path: &str) -> BotResult<Self> {
|
||||
// When i18n feature is enabled, locales are ALWAYS embedded via rust-embed
|
||||
// Filesystem loading is deprecated - use embedded assets only
|
||||
#[cfg(feature = "i18n")]
|
||||
{
|
||||
log::info!("Loading embedded locale translations (rust-embed)");
|
||||
return Self::load_embedded();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "i18n"))]
|
||||
{
|
||||
let _base_path = base_path; // Suppress unused warning when i18n is enabled
|
||||
|
||||
let base = Path::new(base_path);
|
||||
|
||||
if !base.exists() {
|
||||
#[cfg(feature = "i18n")]
|
||||
{
|
||||
log::info!(
|
||||
"Locales directory not found at {}, trying embedded assets",
|
||||
base_path
|
||||
);
|
||||
return Self::load_embedded();
|
||||
}
|
||||
#[cfg(not(feature = "i18n"))]
|
||||
return Err(BotError::config(format!(
|
||||
"locales directory not found: {base_path}"
|
||||
)));
|
||||
|
|
@ -223,6 +226,7 @@ impl I18nBundle {
|
|||
fallback,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "i18n")]
|
||||
fn load_embedded() -> BotResult<Self> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue