Skip to main content

cranpose_ui/
ui_strings.rs

1/// Framework-owned strings. Applications override them in the `cranpose-ui` namespace.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum UiString {
4    /// Copies selected text.
5    Copy,
6    /// Cuts selected text.
7    Cut,
8    /// Pastes the clipboard.
9    Paste,
10    /// Selects all text.
11    SelectAll,
12    /// Reverts an edit.
13    Undo,
14    /// Reapplies an edit.
15    Redo,
16    /// Default search-field hint and search-button accessibility label.
17    Search,
18}
19
20impl UiString {
21    /// Resolves this label during composition. Without localization, returns English.
22    #[track_caller]
23    pub fn resolve(self) -> String {
24        #[cfg(feature = "localization")]
25        {
26            crate::localization::localized(&MESSAGES[self as usize], []).into()
27        }
28        #[cfg(not(feature = "localization"))]
29        {
30            [
31                "Copy",
32                "Cut",
33                "Paste",
34                "Select all",
35                "Undo",
36                "Redo",
37                "Search",
38            ][self as usize]
39                .to_owned()
40        }
41    }
42}
43
44#[cfg(feature = "localization")]
45static SOURCE: crate::localization::SourceCatalog =
46    crate::localization::SourceCatalog::new("en", include_str!("../locales/en/cranpose-ui.ftl"));
47
48#[cfg(feature = "localization")]
49static MESSAGES: [crate::localization::Message; 7] = {
50    use crate::localization::Message;
51    [
52        Message::new("cranpose-ui", "copy", &SOURCE),
53        Message::new("cranpose-ui", "cut", &SOURCE),
54        Message::new("cranpose-ui", "paste", &SOURCE),
55        Message::new("cranpose-ui", "select-all", &SOURCE),
56        Message::new("cranpose-ui", "undo", &SOURCE),
57        Message::new("cranpose-ui", "redo", &SOURCE),
58        Message::new("cranpose-ui", "search", &SOURCE),
59    ]
60};
61
62#[cfg(feature = "localization")]
63/// Translations for Cranpose controls, with namespaces applications can override.
64pub fn catalog() -> crate::localization::Catalog {
65    crate::translations!("locales", fallback = "en")
66}