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    /// Shows the month before in a date picker.
19    PreviousMonth,
20    /// Shows the month after in a date picker.
21    NextMonth,
22    /// Names the hour wheel of a time picker.
23    Hour,
24    /// Names the minute wheel of a time picker.
25    Minute,
26    /// Raises a stepper's value by one step.
27    Increment,
28    /// Lowers a stepper's value by one step.
29    Decrement,
30}
31
32impl UiString {
33    /// Resolves this label during composition. Without localization, returns English.
34    #[track_caller]
35    pub fn resolve(self) -> String {
36        #[cfg(feature = "localization")]
37        {
38            crate::localization::localized(&MESSAGES[self as usize], []).into()
39        }
40        #[cfg(not(feature = "localization"))]
41        {
42            [
43                "Copy",
44                "Cut",
45                "Paste",
46                "Select all",
47                "Undo",
48                "Redo",
49                "Search",
50                "Previous month",
51                "Next month",
52                "Hour",
53                "Minute",
54                "Increment",
55                "Decrement",
56            ][self as usize]
57                .to_owned()
58        }
59    }
60}
61
62#[cfg(feature = "localization")]
63static SOURCE: crate::localization::SourceCatalog =
64    crate::localization::SourceCatalog::new("en", include_str!("../locales/en/cranpose-ui.ftl"));
65
66#[cfg(feature = "localization")]
67static MESSAGES: [crate::localization::Message; 13] = {
68    use crate::localization::Message;
69    [
70        Message::new("cranpose-ui", "copy", &SOURCE),
71        Message::new("cranpose-ui", "cut", &SOURCE),
72        Message::new("cranpose-ui", "paste", &SOURCE),
73        Message::new("cranpose-ui", "select-all", &SOURCE),
74        Message::new("cranpose-ui", "undo", &SOURCE),
75        Message::new("cranpose-ui", "redo", &SOURCE),
76        Message::new("cranpose-ui", "search", &SOURCE),
77        Message::new("cranpose-ui", "previous-month", &SOURCE),
78        Message::new("cranpose-ui", "next-month", &SOURCE),
79        Message::new("cranpose-ui", "hour", &SOURCE),
80        Message::new("cranpose-ui", "minute", &SOURCE),
81        Message::new("cranpose-ui", "increment", &SOURCE),
82        Message::new("cranpose-ui", "decrement", &SOURCE),
83    ]
84};
85
86#[cfg(feature = "localization")]
87/// Translations for Cranpose controls, with namespaces applications can override.
88pub fn catalog() -> crate::localization::Catalog {
89    crate::translations!("locales", fallback = "en")
90}