pub mod en;
pub mod ja;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Locale {
#[default]
En,
Ja,
}
impl Locale {
pub const ALL: &'static [Locale] = &[Locale::En, Locale::Ja];
pub fn as_str(&self) -> &'static str {
match self {
Locale::En => "en",
Locale::Ja => "ja",
}
}
pub fn parse(s: &str) -> Option<Locale> {
match s {
"en" => Some(Locale::En),
"ja" => Some(Locale::Ja),
_ => None,
}
}
pub fn display_name(&self) -> &'static str {
match self {
Locale::En => "English",
Locale::Ja => "日本語",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageKey {
AppTitle,
LocalOnlyBadge,
NavSearch,
NavSources,
NavIndexing,
NavStorage,
NavModels,
NavSettings,
SearchPlaceholder,
SearchButton,
SearchNoSourcesTitle,
SearchNoSourcesBody,
SearchAddSource,
SearchNoResults,
SearchKeywordOnlyNotice,
SourcesTitle,
SourcesEmptyTitle,
SourcesEmptyBody,
SourcesAddFolder,
SourcesStatusActive,
SourcesStatusPaused,
SourcesStatusMissing,
IndexingTitle,
IndexingIdle,
IndexingHealthIndexed,
IndexingHealthStale,
IndexingHealthFailed,
IndexingHealthQueued,
StorageTitle,
StorageIntro,
StorageSafeCleanupHeading,
StorageClearSnippets,
StorageClearSearchCache,
StorageDangerHeading,
StorageResetCatalog,
StorageResetWarning,
ModelsTitle,
ModelsEmbeddingRole,
ModelsRerankerRole,
ModelsStatusAvailable,
ModelsStatusMissing,
ModelsKeywordOnlyHint,
SettingsTitle,
SettingsLanguageHeading,
SettingsPrivacyHeading,
SettingsPrivacyLocalOnly,
SearchModeLabel,
SearchModeAuto,
SearchModeExact,
SearchModeConceptual,
SearchModeFast,
BadgeKeyword,
BadgeSemantic,
BadgeFused,
WizardTitleNotConfigured,
WizardTitleFileMissing,
WizardTitleValidating,
WizardTitleReady,
WizardBodyNotConfigured,
WizardBodyFileMissing,
WizardFilesNeededLabel,
WizardDownloadHint,
WizardPathInputPlaceholder,
WizardActionLocate,
WizardActionValidate,
WizardActionUseModel,
WizardActionContinue,
WizardActionSkip,
WizardPreviousPathLabel,
WizardValidationOk,
WizardValidationFail,
WizardReadyBody,
Cancel,
Confirm,
}
pub fn tr(locale: Locale, key: MessageKey) -> &'static str {
match locale {
Locale::En => en::message(key),
Locale::Ja => ja::message(key),
}
}
pub fn files_indexed(locale: Locale, count: u64) -> String {
match locale {
Locale::En => format!("{count} files indexed"),
Locale::Ja => format!("{count} 件のファイルをインデックス済み"),
}
}
pub fn source_summary(locale: Locale, indexed: u64, stale: u64, failed: u64) -> String {
match locale {
Locale::En => format!("{indexed} indexed · {stale} stale · {failed} failed"),
Locale::Ja => format!("インデックス済み {indexed} · 要更新 {stale} · 失敗 {failed}"),
}
}
pub fn search_result_count(locale: Locale, count: usize) -> String {
match locale {
Locale::En => format!("{count} result{}", if count == 1 { "" } else { "s" }),
Locale::Ja => format!("{count} 件の結果"),
}
}