rush_sync_server/commands/lang/
command.rs1use super::manager::LanguageManager;
6use crate::commands::command::Command;
7use crate::core::prelude::*;
8use std::future::Future;
9use std::pin::Pin;
10
11#[derive(Debug)]
12pub struct LanguageCommand;
13
14impl Command for LanguageCommand {
15 fn name(&self) -> &'static str {
16 "language"
17 }
18
19 fn description(&self) -> &'static str {
20 "Change application language"
21 }
22
23 fn matches(&self, command: &str) -> bool {
24 command.trim().to_lowercase().starts_with("lang")
25 }
26
27 fn execute_sync(&self, args: &[&str]) -> Result<String> {
28 match args.first() {
29 None => Ok(LanguageManager::show_status()),
30 Some(&lang) => match LanguageManager::switch_language_only(lang) {
31 Ok(()) => {
32 let msg = crate::i18n::get_command_translation(
33 "system.commands.language.changed",
34 &[&lang.to_uppercase()],
35 );
36 Ok(LanguageManager::create_save_message_format(lang, &msg))
37 }
38 Err(e) => Ok(crate::i18n::get_command_translation(
39 "system.commands.language.invalid",
40 &[&e.to_string()],
41 )),
42 },
43 }
44 }
45
46 fn execute_async<'a>(
48 &'a self,
49 args: &'a [&'a str],
50 ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>> {
51 Box::pin(async move {
52 match args.first() {
53 None => Ok(LanguageManager::show_status()),
54 Some(&lang) => LanguageManager::change_language(lang).await,
55 }
56 })
57 }
58
59 fn supports_async(&self) -> bool {
60 true }
62
63 fn priority(&self) -> u8 {
64 70 }
66}