ludusavi 0.18.0

Game save backup tool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
use std::sync::Mutex;

use byte_unit::Byte;
use fluent::{bundle::FluentBundle, FluentArgs, FluentResource};
use intl_memoizer::concurrent::IntlLangMemoizer;
use once_cell::sync::Lazy;
use regex::Regex;
use unic_langid::LanguageIdentifier;

use crate::{
    prelude::{CommandError, Error, StrictPath, VARIANT, VERSION},
    resource::{
        config::{BackupFormat, RedirectKind, RootsConfig, SortKey, Theme, ZipCompression},
        manifest::Store,
    },
    scan::{game_filter, OperationStatus, OperationStepDecision, ScanChange},
};

const PATH: &str = "path";
const LOCAL_PATH: &str = "local-path";
const CLOUD_PATH: &str = "cloud-path";
const PATH_ACTION: &str = "path-action";
const PROCESSED_GAMES: &str = "processed-games";
const PROCESSED_SIZE: &str = "processed-size";
const TOTAL: &str = "total";
const TOTAL_GAMES: &str = "total-games";
const TOTAL_SIZE: &str = "total-size";
const COMMAND: &str = "command";
const CODE: &str = "code";
const MESSAGE: &str = "message";
const APP: &str = "app";

pub const TRANSLATOR: Translator = Translator {};
pub const ADD_SYMBOL: &str = "+";
pub const CHANGE_SYMBOL: &str = "Δ";
pub const REMOVAL_SYMBOL: &str = "x";

fn title_case(text: &str) -> String {
    let lowercase = text.to_lowercase();
    let mut chars = lowercase.chars();
    match chars.next() {
        None => lowercase,
        Some(char) => format!("{}{}", char.to_uppercase(), chars.as_str()),
    }
}

// TODO: Some are blocked by https://github.com/mtkennerly/ludusavi/issues/9.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum Language {
    #[allow(dead_code)]
    #[serde(rename = "ar-SA")]
    Arabic,
    #[allow(dead_code)]
    #[serde(rename = "zh-Hans")]
    ChineseSimplified,
    #[serde(rename = "nl-NL")]
    Dutch,
    #[default]
    #[serde(rename = "en-US")]
    English,
    #[serde(rename = "eo")]
    Esperanto,
    #[serde(rename = "fil-PH")]
    Filipino,
    #[serde(rename = "fr-FR")]
    French,
    #[serde(rename = "de-DE")]
    German,
    #[serde(rename = "it-IT")]
    Italian,
    #[allow(dead_code)]
    #[serde(rename = "ja-JP")]
    Japanese,
    #[allow(dead_code)]
    #[serde(rename = "ko-KR")]
    Korean,
    #[serde(rename = "pt-BR")]
    PortugueseBrazilian,
    #[serde(rename = "pl-PL")]
    Polish,
    #[allow(dead_code)]
    #[serde(rename = "ja-JP")]
    Russian,
    #[serde(rename = "ru-RU")]
    Spanish,
    #[allow(dead_code)]
    #[serde(rename = "uk-UA")]
    Ukrainian,
}

impl Language {
    pub const ALL: &'static [Self] = &[
        Self::German,
        Self::English,
        Self::Spanish,
        Self::Esperanto,
        Self::Filipino,
        Self::French,
        Self::Italian,
        Self::Dutch,
        Self::Polish,
        Self::PortugueseBrazilian,
        Self::Russian,
        Self::Ukrainian,
    ];

    pub fn id(&self) -> LanguageIdentifier {
        let id = match self {
            Self::Arabic => "ar-SA",
            Self::ChineseSimplified => "zh-Hans",
            Self::Dutch => "nl-NL",
            Self::English => "en-US",
            Self::Esperanto => "eo",
            Self::Filipino => "fil-PH",
            Self::French => "fr-FR",
            Self::German => "de-DE",
            Self::Italian => "it-IT",
            Self::Japanese => "ja-JP",
            Self::Korean => "ko-KR",
            Self::Polish => "pl-PL",
            Self::PortugueseBrazilian => "pt-BR",
            Self::Russian => "ru-RU",
            Self::Spanish => "es-ES",
            Self::Ukrainian => "uk-UA",
        };
        id.parse().unwrap()
    }
}

impl ToString for Language {
    fn to_string(&self) -> String {
        match self {
            Self::Arabic => "العربية (64%)",
            Self::ChineseSimplified => "中文(简体) (64%)",
            Self::Dutch => "Nederlands (25%)",
            Self::English => "English",
            Self::Esperanto => "Esperanto (22%)",
            Self::Filipino => "Filipino (41%)",
            Self::French => "Français (99%)",
            Self::German => "Deutsch (100%)",
            Self::Italian => "Italiano (64%)",
            Self::Japanese => "日本語 (55%)",
            Self::Korean => "한국어 (33%)",
            Self::Polish => "Polski (65%)",
            Self::PortugueseBrazilian => "Português brasileiro (95%)",
            Self::Russian => "Русский язык (20%)",
            Self::Spanish => "Español (54%)",
            Self::Ukrainian => "Украї́нська мо́ва (7%)",
        }
        .to_string()
    }
}

#[derive(Clone, Copy, Debug, Default)]
pub struct Translator {}

static LANGUAGE: Mutex<Language> = Mutex::new(Language::English);

static BUNDLE: Lazy<Mutex<FluentBundle<FluentResource, IntlLangMemoizer>>> = Lazy::new(|| {
    let ftl = include_str!("../lang/en-US.ftl").to_owned();
    let res = FluentResource::try_new(ftl).expect("Failed to parse Fluent file content.");

    let mut bundle = FluentBundle::new_concurrent(vec![Language::English.id()]);
    bundle.set_use_isolating(false);

    bundle
        .add_resource(res)
        .expect("Failed to add Fluent resources to the bundle.");

    Mutex::new(bundle)
});

fn set_language(language: Language) {
    let mut bundle = BUNDLE.lock().unwrap();

    let ftl = match language {
        Language::Arabic => include_str!("../lang/ar-SA.ftl"),
        Language::ChineseSimplified => include_str!("../lang/zh-CN.ftl"),
        Language::Dutch => include_str!("../lang/nl-NL.ftl"),
        Language::English => include_str!("../lang/en-US.ftl"),
        Language::Esperanto => include_str!("../lang/eo-UY.ftl"),
        Language::Filipino => include_str!("../lang/fil-PH.ftl"),
        Language::French => include_str!("../lang/fr-FR.ftl"),
        Language::German => include_str!("../lang/de-DE.ftl"),
        Language::Italian => include_str!("../lang/it-IT.ftl"),
        Language::Japanese => include_str!("../lang/ja-JP.ftl"),
        Language::Korean => include_str!("../lang/ko-KR.ftl"),
        Language::Polish => include_str!("../lang/pl-PL.ftl"),
        Language::PortugueseBrazilian => include_str!("../lang/pt-BR.ftl"),
        Language::Russian => include_str!("../lang/ru-RU.ftl"),
        Language::Spanish => include_str!("../lang/es-ES.ftl"),
        Language::Ukrainian => include_str!("../lang/uk-UA.ftl"),
    }
    .to_owned();

    let res = FluentResource::try_new(ftl).expect("Failed to parse Fluent file content.");
    bundle.locales = vec![language.id()];

    bundle.add_resource_overriding(res);

    let mut last_language = LANGUAGE.lock().unwrap();
    *last_language = language;
}

static RE_EXTRA_SPACES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([^\r\n ]) {2,}"#).unwrap());
static RE_EXTRA_LINES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([^\r\n ])[\r\n]([^\r\n ])"#).unwrap());
static RE_EXTRA_PARAGRAPHS: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([^\r\n ])[\r\n]{2,}([^\r\n ])"#).unwrap());

fn translate(id: &str) -> String {
    translate_args(id, &FluentArgs::new())
}

fn translate_args(id: &str, args: &FluentArgs) -> String {
    let bundle = match BUNDLE.lock() {
        Ok(x) => x,
        Err(_) => return "fluent-cannot-lock".to_string(),
    };

    let parts: Vec<&str> = id.splitn(2, '.').collect();
    let (name, attr) = if parts.len() < 2 {
        (id, None)
    } else {
        (parts[0], Some(parts[1]))
    };

    let message = match bundle.get_message(name) {
        Some(x) => x,
        None => return format!("fluent-no-message={}", name),
    };

    let pattern = match attr {
        None => match message.value() {
            Some(x) => x,
            None => return format!("fluent-no-message-value={}", id),
        },
        Some(attr) => match message.get_attribute(attr) {
            Some(x) => x.value(),
            None => return format!("fluent-no-attr={}", id),
        },
    };
    let mut errors = vec![];
    let value = bundle.format_pattern(pattern, Some(args), &mut errors);

    RE_EXTRA_PARAGRAPHS
        .replace_all(
            &RE_EXTRA_LINES.replace_all(&RE_EXTRA_SPACES.replace_all(&value, "${1} "), "${1} ${2}"),
            "${1}\n\n${2}",
        )
        .to_string()
}

impl Translator {
    pub fn set_language(&self, language: Language) {
        set_language(Language::English);
        if language != Language::English {
            set_language(language);
        }
    }

    pub fn window_title(&self) -> String {
        let name = translate("ludusavi");
        match VARIANT {
            Some(variant) => format!("{} v{} ({})", name, *VERSION, variant),
            None => format!("{} v{}", name, *VERSION),
        }
    }

    pub fn pcgamingwiki(&self) -> String {
        "PCGamingWiki".to_string()
    }

    pub fn comment_button(&self) -> String {
        translate("button-comment")
    }

    pub fn lock_button(&self) -> String {
        translate("button-lock")
    }

    pub fn unlock_button(&self) -> String {
        translate("button-unlock")
    }

    pub fn handle_error(&self, error: &Error) -> String {
        match error {
            Error::ConfigInvalid { why } => self.config_is_invalid(why),
            Error::ManifestInvalid { why } => self.manifest_is_invalid(why),
            Error::ManifestCannotBeUpdated => self.manifest_cannot_be_updated(),
            Error::CliUnrecognizedGames { games } => self.cli_unrecognized_games(games),
            Error::CliUnableToRequestConfirmation => self.cli_unable_to_request_confirmation(),
            Error::CliBackupIdWithMultipleGames => self.cli_backup_id_with_multiple_games(),
            Error::CliInvalidBackupId => self.cli_invalid_backup_id(),
            Error::SomeEntriesFailed => self.some_entries_failed(),
            Error::CannotPrepareBackupTarget { path } => self.cannot_prepare_backup_target(path),
            Error::RestorationSourceInvalid { path } => self.restoration_source_is_invalid(path),
            Error::RegistryIssue => self.registry_issue(),
            Error::UnableToBrowseFileSystem => self.unable_to_browse_file_system(),
            Error::UnableToOpenDir(path) => self.unable_to_open_dir(path),
            Error::UnableToOpenUrl(url) => self.unable_to_open_url(url),
            Error::RcloneUnavailable => self.rclone_unavailable(),
            Error::CloudNotConfigured => self.cloud_not_configured(),
            Error::CloudPathInvalid => self.cloud_path_invalid(),
            Error::UnableToConfigureCloud(error) => {
                format!(
                    "{}\n\n{}",
                    self.prefix_error(&self.unable_to_configure_cloud()),
                    self.handle_command_error(error)
                )
            }
            Error::UnableToSynchronizeCloud(error) => {
                format!(
                    "{}\n\n{}",
                    self.prefix_error(&self.unable_to_synchronize_with_cloud()),
                    self.handle_command_error(error)
                )
            }
            Error::CloudConflict => TRANSLATOR.prefix_error(&TRANSLATOR.cloud_synchronize_conflict()),
        }
    }

    fn handle_command_error(&self, error: &CommandError) -> String {
        let mut args = FluentArgs::new();
        args.set(COMMAND, error.command());
        match error {
            CommandError::Launched { raw, .. } => {
                format!("{}\n\n{}", translate_args("command-unlaunched", &args), raw)
            }
            CommandError::Terminated { .. } => translate_args("command-terminated", &args),
            CommandError::Exited {
                code, stdout, stderr, ..
            } => {
                args.set(CODE, code);
                let mut out = translate_args("command-failed", &args);

                if let Some(stdout) = stdout {
                    out.push_str("\n\n");
                    out.push_str(stdout);
                }

                if let Some(stderr) = stderr {
                    out.push_str("\n\n");
                    out.push_str(stderr);
                }

                out
            }
        }
    }

    pub fn cli_unrecognized_games(&self, games: &[String]) -> String {
        let prefix = translate("cli-unrecognized-games");
        let lines: Vec<_> = games.iter().map(|x| format!("  - {}", x)).collect();
        format!("{}\n{}", prefix, lines.join("\n"))
    }

    pub fn cli_unable_to_request_confirmation(&self) -> String {
        #[cfg(target_os = "windows")]
        let extra_note = translate("cli-unable-to-request-confirmation.winpty-workaround");

        #[cfg(not(target_os = "windows"))]
        let extra_note = "";

        format!("{} {}", translate("cli-unable-to-request-confirmation"), extra_note)
    }

    pub fn cli_backup_id_with_multiple_games(&self) -> String {
        translate("cli-backup-id-with-multiple-games")
    }

    pub fn cli_invalid_backup_id(&self) -> String {
        translate("cli-invalid-backup-id")
    }

    pub fn cloud_not_configured(&self) -> String {
        translate("cloud-not-configured")
    }

    pub fn cloud_path_invalid(&self) -> String {
        translate("cloud-path-invalid")
    }

    pub fn some_entries_failed(&self) -> String {
        translate("some-entries-failed")
    }

    fn label(&self, text: &str) -> String {
        format!("[{}]", text)
    }

    pub fn label_failed(&self) -> String {
        self.label(&self.badge_failed())
    }

    pub fn label_duplicates(&self) -> String {
        self.label(&self.badge_duplicates())
    }

    pub fn label_duplicated(&self) -> String {
        self.label(&self.badge_duplicated())
    }

    pub fn label_ignored(&self) -> String {
        self.label(&self.badge_ignored())
    }

    fn field(&self, text: &str) -> String {
        let language = LANGUAGE.lock().unwrap();
        match *language {
            Language::French => format!("{} :", text),
            _ => format!("{}:", text),
        }
    }

    pub fn field_language(&self) -> String {
        self.field(&translate("language"))
    }

    pub fn field_theme(&self) -> String {
        self.field(&translate("theme"))
    }

    pub fn badge_failed(&self) -> String {
        translate("badge-failed")
    }

    pub fn badge_duplicates(&self) -> String {
        translate("badge-duplicates")
    }

    pub fn badge_duplicated(&self) -> String {
        translate("badge-duplicated")
    }

    pub fn badge_ignored(&self) -> String {
        translate("badge-ignored")
    }

    pub fn badge_redirected_from(&self, original: &StrictPath) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, original.render());
        translate_args("badge-redirected-from", &args)
    }

    pub fn badge_redirecting_to(&self, path: &StrictPath) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, path.render());
        translate_args("badge-redirecting-to", &args)
    }

    pub fn cli_game_header(
        &self,
        name: &str,
        bytes: u64,
        decision: &OperationStepDecision,
        duplicated: bool,
        change: ScanChange,
    ) -> String {
        let mut labels = vec![];
        match change {
            ScanChange::New => {
                labels.push(format!("[{}]", crate::lang::ADD_SYMBOL));
            }
            ScanChange::Different => {
                labels.push(format!("[{}]", crate::lang::CHANGE_SYMBOL));
            }
            ScanChange::Removed | ScanChange::Same | ScanChange::Unknown => (),
        }
        if *decision == OperationStepDecision::Ignored {
            labels.push(self.label_ignored());
        }
        if duplicated {
            labels.push(self.label_duplicates());
        }

        if labels.is_empty() {
            format!("{} [{}]:", name, self.adjusted_size(bytes))
        } else {
            format!("{} [{}] {}:", name, self.adjusted_size(bytes), labels.join(" "))
        }
    }

    pub fn cli_game_line_item(
        &self,
        item: &str,
        successful: bool,
        ignored: bool,
        duplicated: bool,
        change: ScanChange,
        nested: bool,
    ) -> String {
        let mut parts = vec![];
        match change {
            ScanChange::Same | ScanChange::Unknown => (),
            ScanChange::New => parts.push(format!("[{}]", ADD_SYMBOL)),
            ScanChange::Different => parts.push(format!("[{}]", CHANGE_SYMBOL)),
            ScanChange::Removed => parts.push(format!("[{}]", REMOVAL_SYMBOL)),
        }
        if !successful {
            parts.push(self.label_failed());
        }
        if ignored {
            parts.push(self.label_ignored());
        }
        if duplicated {
            parts.push(self.label_duplicated());
        }
        parts.push(item.to_string());

        if nested {
            format!("    - {}", parts.join(" "))
        } else {
            format!("  - {}", parts.join(" "))
        }
    }

    pub fn cli_game_line_item_redirected(&self, item: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, item);
        format!("    - {}", translate_args("cli-game-line-item-redirected", &args),)
    }

    pub fn cli_game_line_item_redirecting(&self, item: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, item);
        format!("    - {}", translate_args("cli-game-line-item-redirecting", &args),)
    }

    pub fn cli_summary(&self, status: &OperationStatus, location: &StrictPath) -> String {
        let new_games = if status.changed_games.new > 0 {
            format!(" [{}{}]", crate::lang::ADD_SYMBOL, status.changed_games.new)
        } else {
            "".to_string()
        };
        let changed_games = if status.changed_games.different > 0 {
            format!(" [{}{}]", crate::lang::CHANGE_SYMBOL, status.changed_games.different)
        } else {
            "".to_string()
        };

        format!(
            "{}:\n  {}: {}{}{}\n  {}: {}\n  {}: {}",
            translate("overall"),
            translate("total-games"),
            if status.processed_all_games() {
                status.processed_games.to_string()
            } else {
                format!("{} / {}", status.processed_games, status.total_games)
            },
            new_games,
            changed_games,
            translate("file-size"),
            if status.processed_all_bytes() {
                self.adjusted_size(status.processed_bytes)
            } else {
                format!(
                    "{} / {}",
                    self.adjusted_size(status.processed_bytes),
                    self.adjusted_size(status.total_bytes)
                )
            },
            translate("file-location"),
            location.render(),
        )
    }

    pub fn backup_button(&self) -> String {
        translate("button-backup")
    }

    pub fn backup_button_no_confirmation(&self) -> String {
        format!("{} ({})", self.backup_button(), self.suffix_no_confirmation())
    }

    pub fn preview_button(&self) -> String {
        translate("button-preview")
    }

    pub fn preview_button_in_custom_mode(&self) -> String {
        format!("{} ({})", self.preview_button(), self.backup_button().to_lowercase())
    }

    pub fn restore_button(&self) -> String {
        translate("button-restore")
    }

    pub fn restore_button_no_confirmation(&self) -> String {
        format!("{} ({})", self.restore_button(), self.suffix_no_confirmation())
    }

    pub fn nav_backup_button(&self) -> String {
        translate("button-nav-backup")
    }

    pub fn nav_restore_button(&self) -> String {
        translate("button-nav-restore")
    }

    pub fn nav_custom_games_button(&self) -> String {
        translate("button-nav-custom-games")
    }

    pub fn nav_other_button(&self) -> String {
        translate("button-nav-other")
    }

    pub fn customize_button(&self) -> String {
        translate("button-customize")
    }

    pub fn no_missing_roots(&self) -> String {
        translate("no-missing-roots")
    }

    pub fn loading(&self) -> String {
        translate("loading")
    }

    pub fn updating_manifest(&self) -> String {
        translate("updating-manifest")
    }

    pub fn confirm_add_missing_roots(&self, roots: &[RootsConfig]) -> String {
        use std::fmt::Write;
        let mut msg = translate("confirm-add-missing-roots") + "\n";

        for root in roots {
            let _ = &write!(msg, "\n[{}] {}", self.store(&root.store), root.path.render());
        }

        msg
    }

    pub fn add_game_button(&self) -> String {
        translate("button-add-game")
    }

    pub fn continue_button(&self) -> String {
        translate("button-continue")
    }

    pub fn cancel_button(&self) -> String {
        translate("button-cancel")
    }

    pub fn cancelling_button(&self) -> String {
        translate("button-cancelling")
    }

    pub fn okay_button(&self) -> String {
        translate("button-okay")
    }

    pub fn select_all_button(&self) -> String {
        translate("button-select-all")
    }

    pub fn deselect_all_button(&self) -> String {
        translate("button-deselect-all")
    }

    pub fn enable_all_button(&self) -> String {
        translate("button-enable-all")
    }

    pub fn disable_all_button(&self) -> String {
        translate("button-disable-all")
    }

    pub fn exit_button(&self) -> String {
        translate("button-exit")
    }

    pub fn get_rclone_button(&self) -> String {
        let mut args = FluentArgs::new();
        args.set(APP, "Rclone");
        translate_args("button-get-app", &args)
    }

    pub fn no_roots_are_configured(&self) -> String {
        translate("no-roots-are-configured")
    }

    pub fn config_is_invalid(&self, why: &str) -> String {
        format!("{}\n{}", translate("config-is-invalid"), why)
    }

    pub fn manifest_is_invalid(&self, why: &str) -> String {
        format!("{}\n{}", translate("manifest-is-invalid"), why)
    }

    pub fn manifest_cannot_be_updated(&self) -> String {
        translate("manifest-cannot-be-updated")
    }

    pub fn cannot_prepare_backup_target(&self, target: &StrictPath) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, target.render());
        translate_args("cannot-prepare-backup-target", &args)
    }

    pub fn restoration_source_is_invalid(&self, source: &StrictPath) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH, source.render());
        translate_args("restoration-source-is-invalid", &args)
    }

    pub fn registry_issue(&self) -> String {
        translate("registry-issue")
    }

    pub fn unable_to_browse_file_system(&self) -> String {
        translate("unable-to-browse-file-system")
    }

    pub fn unable_to_open_dir(&self, path: &StrictPath) -> String {
        format!("{}\n\n{}", translate("unable-to-open-directory"), path.render())
    }

    pub fn unable_to_open_url(&self, url: &str) -> String {
        format!("{}\n\n{}", translate("unable-to-open-url"), url)
    }

    pub fn unable_to_configure_cloud(&self) -> String {
        translate("unable-to-configure-cloud")
    }

    pub fn unable_to_synchronize_with_cloud(&self) -> String {
        translate("unable-to-synchronize-with-cloud")
    }

    pub fn cloud_synchronize_conflict(&self) -> String {
        translate("cloud-synchronize-conflict")
    }

    pub fn adjusted_size(&self, bytes: u64) -> String {
        let byte = Byte::from_bytes(bytes.into());
        let adjusted_byte = byte.get_appropriate_unit(true);
        adjusted_byte.to_string()
    }

    pub fn processed_games(&self, status: &OperationStatus) -> String {
        let mut args = FluentArgs::new();
        args.set(TOTAL_GAMES, status.total_games);
        args.set(PROCESSED_GAMES, status.processed_games);

        if status.processed_all_games() {
            translate_args("processed-games", &args)
        } else {
            translate_args("processed-games-subset", &args)
        }
    }

    pub fn processed_bytes(&self, status: &OperationStatus) -> String {
        if status.processed_all_bytes() {
            self.adjusted_size(status.total_bytes)
        } else {
            let mut args = FluentArgs::new();
            args.set(TOTAL_SIZE, self.adjusted_size(status.total_bytes));
            args.set(PROCESSED_SIZE, self.adjusted_size(status.processed_bytes));
            translate_args("processed-size-subset", &args)
        }
    }

    pub fn processed_subset(&self, total: usize, processed: usize) -> String {
        let mut args = FluentArgs::new();
        args.set(TOTAL_SIZE, total as u64);
        args.set(PROCESSED_SIZE, processed as u64);
        translate_args("processed-size-subset", &args)
    }

    pub fn backup_target_label(&self) -> String {
        translate("field-backup-target")
    }

    pub fn restore_source_label(&self) -> String {
        translate("field-restore-source")
    }

    pub fn custom_files_label(&self) -> String {
        translate("field-custom-files")
    }

    pub fn custom_registry_label(&self) -> String {
        translate("field-custom-registry")
    }

    pub fn sort_label(&self) -> String {
        translate("field-sort")
    }

    pub fn store(&self, store: &Store) -> String {
        translate(match store {
            Store::Ea => "store-ea",
            Store::Epic => "store-epic",
            Store::Gog => "store-gog",
            Store::GogGalaxy => "store-gog-galaxy",
            Store::Heroic => "store-heroic",
            Store::Lutris => "store-lutris",
            Store::Microsoft => "store-microsoft",
            Store::Origin => "store-origin",
            Store::Prime => "store-prime",
            Store::Steam => "store-steam",
            Store::Uplay => "store-uplay",
            Store::OtherHome => "store-other-home",
            Store::OtherWine => "store-other-wine",
            Store::Other => "store-other",
        })
    }

    pub fn sort_key(&self, key: &SortKey) -> String {
        translate(match key {
            SortKey::Name => "game-name",
            SortKey::Size => "file-size",
            SortKey::Status => "status",
        })
    }

    pub fn filter_uniqueness(&self, filter: game_filter::Uniqueness) -> String {
        match filter {
            game_filter::Uniqueness::Unique => translate("label-unique"),
            game_filter::Uniqueness::Duplicate => title_case(&self.badge_duplicated()),
        }
    }

    pub fn filter_completeness(&self, filter: game_filter::Completeness) -> String {
        translate(match filter {
            game_filter::Completeness::Complete => "label-complete",
            game_filter::Completeness::Partial => "label-partial",
        })
    }

    pub fn filter_enablement(&self, filter: game_filter::Enablement) -> String {
        translate(match filter {
            game_filter::Enablement::Enabled => "label-enabled",
            game_filter::Enablement::Disabled => "label-disabled",
        })
    }

    pub fn backup_format(&self, key: &BackupFormat) -> String {
        translate(match key {
            BackupFormat::Simple => "backup-format-simple",
            BackupFormat::Zip => "backup-format-zip",
        })
    }

    pub fn backup_compression(&self, key: &ZipCompression) -> String {
        translate(match key {
            ZipCompression::None => "compression-none",
            ZipCompression::Deflate => "compression-deflate",
            ZipCompression::Bzip2 => "compression-bzip2",
            ZipCompression::Zstd => "compression-zstd",
        })
    }

    pub fn theme_name(&self, theme: &Theme) -> String {
        translate(match theme {
            Theme::Light => "theme-light",
            Theme::Dark => "theme-dark",
        })
    }

    pub fn redirect_kind(&self, redirect: &RedirectKind) -> String {
        match redirect {
            RedirectKind::Backup => self.backup_button(),
            RedirectKind::Restore => self.restore_button(),
            RedirectKind::Bidirectional => translate("redirect-bidirectional"),
        }
    }

    pub fn redirect_source_placeholder(&self) -> String {
        translate("field-redirect-source.placeholder")
    }

    pub fn redirect_target_placeholder(&self) -> String {
        translate("field-redirect-target.placeholder")
    }

    pub fn custom_game_name_placeholder(&self) -> String {
        translate("game-name")
    }

    pub fn search_game_name_placeholder(&self) -> String {
        translate("game-name")
    }

    pub fn show_deselected_games(&self) -> String {
        translate("show-deselected-games")
    }

    pub fn show_unchanged_games(&self) -> String {
        translate("show-unchanged-games")
    }

    pub fn show_unscanned_games(&self) -> String {
        translate("show-unscanned-games")
    }

    pub fn override_max_threads(&self) -> String {
        format!(
            "{} ({})",
            translate("override-max-threads"),
            self.suffix_restart_required()
        )
    }

    pub fn explanation_for_exclude_store_screenshots(&self) -> String {
        translate("explanation-for-exclude-store-screenshots")
    }

    pub fn roots_label(&self) -> String {
        translate("field-roots")
    }

    pub fn ignored_items_label(&self) -> String {
        translate("field-backup-excluded-items")
    }

    pub fn redirects_label(&self) -> String {
        translate("field-redirects")
    }

    pub fn full_retention(&self) -> String {
        translate("field-retention-full")
    }

    pub fn differential_retention(&self) -> String {
        translate("field-retention-differential")
    }

    pub fn backup_format_field(&self) -> String {
        translate("field-backup-format")
    }

    pub fn backup_compression_field(&self) -> String {
        translate("field-backup-compression")
    }

    pub fn backup_compression_level_field(&self) -> String {
        translate("field-backup-compression-level")
    }

    pub fn manifest_label(&self) -> String {
        self.field(&translate("label-manifest"))
    }

    pub fn checked_label(&self) -> String {
        self.field(&translate("label-checked"))
    }

    pub fn updated_label(&self) -> String {
        self.field(&translate("label-updated"))
    }

    pub fn comment_label(&self) -> String {
        translate("label-comment")
    }

    pub fn scan_label(&self) -> String {
        translate("label-scan")
    }

    pub fn scan_field(&self) -> String {
        self.field(&self.scan_label())
    }

    pub fn filter_label(&self) -> String {
        self.field(&translate("label-filter"))
    }

    pub fn threads_label(&self) -> String {
        self.field(&translate("label-threads"))
    }

    pub fn cloud_label(&self) -> String {
        translate("label-cloud")
    }

    pub fn cloud_field(&self) -> String {
        self.field(&self.cloud_label())
    }

    pub fn rclone_label(&self) -> String {
        self.field("Rclone")
    }

    pub fn remote_label(&self) -> String {
        self.field(&translate("label-remote"))
    }

    pub fn remote_name_label(&self) -> String {
        self.field(&translate("label-remote-name"))
    }

    pub fn folder_label(&self) -> String {
        self.field(&translate("label-folder"))
    }

    pub fn executable_label(&self) -> String {
        translate("label-executable")
    }

    pub fn arguments_label(&self) -> String {
        translate("label-arguments")
    }

    pub fn url_label(&self) -> String {
        self.field(&translate("label-url"))
    }

    pub fn host_label(&self) -> String {
        self.field(&translate("label-host"))
    }

    pub fn port_label(&self) -> String {
        self.field(&translate("label-port"))
    }

    pub fn username_label(&self) -> String {
        self.field(&translate("label-username"))
    }

    pub fn password_label(&self) -> String {
        self.field(&translate("label-password"))
    }

    pub fn provider_label(&self) -> String {
        self.field(&translate("label-provider"))
    }

    pub fn none_label(&self) -> String {
        translate("label-none")
    }

    pub fn custom_label(&self) -> String {
        translate("label-custom")
    }

    pub fn change_count_label(&self, total: usize) -> String {
        let mut args = FluentArgs::new();
        args.set(TOTAL, total);
        translate_args("label-change-count", &args)
    }

    pub fn synchronize_automatically(&self) -> String {
        translate("synchronize-automatically")
    }

    pub fn total_games(&self) -> String {
        translate("total-games")
    }

    pub fn new_tooltip(&self) -> String {
        translate("label-new")
    }

    pub fn updated_tooltip(&self) -> String {
        translate("label-updated")
    }

    pub fn removed_tooltip(&self) -> String {
        translate("label-removed")
    }

    fn consider_doing_a_preview(&self) -> String {
        translate("consider-doing-a-preview")
    }

    pub fn confirm_backup(&self, target: &StrictPath, target_exists: bool, suggest: bool) -> String {
        let mut args = FluentArgs::new();
        args.set(PATH_ACTION, if !target_exists { "create" } else { "merge" });
        let primary = translate_args("confirm-backup", &args);

        if suggest {
            format!(
                "{}\n\n{}\n\n{}",
                primary,
                target.render(),
                self.consider_doing_a_preview(),
            )
        } else {
            format!("{}\n\n{}", primary, target.render(),)
        }
    }

    pub fn confirm_restore(&self, source: &StrictPath, suggest: bool) -> String {
        let primary = translate("confirm-restore");

        if suggest {
            format!(
                "{}\n\n{}\n\n{}",
                primary,
                source.render(),
                self.consider_doing_a_preview(),
            )
        } else {
            format!("{}\n\n{}", primary, source.render(),)
        }
    }

    pub fn confirm_cloud_upload(&self, local: &str, cloud: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(LOCAL_PATH, local);
        args.set(CLOUD_PATH, cloud);
        translate_args("confirm-cloud-upload", &args)
    }

    pub fn confirm_cloud_download(&self, local: &str, cloud: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(LOCAL_PATH, local);
        args.set(CLOUD_PATH, cloud);
        translate_args("confirm-cloud-download", &args)
    }

    pub fn no_cloud_changes(&self) -> String {
        translate("no-cloud-changes")
    }

    pub fn notify_single_game_status(&self, found: bool) -> String {
        if found {
            translate("saves-found")
        } else {
            translate("no-saves-found")
        }
    }

    pub fn suffix_no_confirmation(&self) -> String {
        translate("suffix-no-confirmation")
    }

    pub fn suffix_restart_required(&self) -> String {
        translate("suffix-restart-required")
    }

    pub fn prefix_error(&self, message: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(MESSAGE, message);
        translate_args("prefix-error", &args)
    }

    pub fn prefix_warning(&self, message: &str) -> String {
        let mut args = FluentArgs::new();
        args.set(MESSAGE, message);
        translate_args("prefix-warning", &args)
    }

    pub fn rclone_unavailable(&self) -> String {
        let mut args = FluentArgs::new();
        args.set(APP, "Rclone");
        translate_args("cloud-app-unavailable", &args)
    }

    pub fn cloud_progress(&self, processed_bytes: u64, total_bytes: u64) -> String {
        format!(
            "{} / {}",
            self.adjusted_size(processed_bytes),
            self.adjusted_size(total_bytes)
        )
    }
}