1use crate::AniError;
2
3pub struct I18n {
4 locale: Locale,
5}
6
7pub enum Locale {
8 En,
9 }
11
12impl Default for I18n {
13 fn default() -> Self {
14 Self::new(Locale::En)
15 }
16}
17
18impl I18n {
19 pub fn new(locale: Locale) -> Self {
20 Self { locale }
21 }
22
23 pub fn error(&self, error: &AniError) -> String {
24 match self.locale {
25 Locale::En => self.error_en(error),
26 }
27 }
28
29 fn error_en(&self, error: &AniError) -> String {
30 match error {
31 AniError::Network(msg) => format!("Network request failed: {msg}"),
32 AniError::Provider(msg) => format!("Provider returned invalid data: {msg}"),
33 AniError::Catalog { provider, message } => {
34 format!("{provider} catalog error: {message}")
35 }
36 AniError::ProviderRateLimited {
37 provider,
38 retry_after_seconds,
39 } => {
40 format!(
41 "{provider} is rate limiting requests. Try again in {retry_after_seconds} seconds."
42 )
43 }
44
45 AniError::Unavailable(msg) => format!("Episode unavailable: {msg}"),
46 AniError::Player(msg) => format!("Player failed: {msg}"),
47 AniError::Download(msg) => format!("Download failed: {msg}"),
48 AniError::History(msg) => format!("History operation failed: {msg}"),
49 AniError::Update(msg) => format!("Update failed: {msg}"),
50 AniError::Input(msg) => format!("Invalid input: {msg}"),
51
52 AniError::Io(msg) => format!("Could not access local data: {msg}"),
53 AniError::Json(msg) => format!("Could not process response data: {msg}"),
54 AniError::Url(msg) => format!("Invalid URL: {msg}"),
55
56 AniError::DownloadNoDownloader => {
57 "HLS downloads require yt-dlp or FFmpeg to be installed and available in PATH."
58 .to_string()
59 }
60 AniError::DownloadFailed => "HLS download failed.".to_string(),
61
62 AniError::HistoryStateDirectory => {
63 "Could not determine where to store history data.".to_string()
64 }
65
66 AniError::PlayerNotFound => {
67 "Player executable not found. Make sure your configured player is installed."
68 .to_string()
69 }
70
71 AniError::PlayerLaunchFailed => "Could not launch the player.".to_string(),
72
73 AniError::PlayerExitFailed => "Player exited with an error.".to_string(),
74
75 AniError::PlayerAndroidTerminalRequired => {
76 "Android HLS playback requires an interactive Termux terminal.".to_string()
77 }
78
79 AniError::InputSelectionOutOfRange => "Selection is out of range.".to_string(),
80
81 AniError::InputEmptyQuery => "Search query cannot be empty.".to_string(),
82
83 AniError::InputInvalidEpisode => "Invalid episode selection.".to_string(),
84
85 AniError::InputRequiresQuery => "This command requires an anime query.".to_string(),
86
87 AniError::UnavailableNoResults => "No results found.".to_string(),
88
89 AniError::UnavailableNoStreams => {
90 "No streams are available for this episode.".to_string()
91 }
92
93 AniError::UnavailableNoEpisodes => "No episodes are available.".to_string(),
94 }
95 }
96}