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}
27
28impl UiString {
29    /// Resolves this label during composition. Without localization, returns English.
30    #[track_caller]
31    pub fn resolve(self) -> String {
32        #[cfg(feature = "localization")]
33        {
34            crate::localization::localized(&MESSAGES[self as usize], []).into()
35        }
36        #[cfg(not(feature = "localization"))]
37        {
38            [
39                "Copy",
40                "Cut",
41                "Paste",
42                "Select all",
43                "Undo",
44                "Redo",
45                "Search",
46                "Previous month",
47                "Next month",
48                "Hour",
49                "Minute",
50            ][self as usize]
51                .to_owned()
52        }
53    }
54}
55
56#[cfg(feature = "localization")]
57static SOURCE: crate::localization::SourceCatalog =
58    crate::localization::SourceCatalog::new("en", include_str!("../locales/en/cranpose-ui.ftl"));
59
60#[cfg(feature = "localization")]
61static MESSAGES: [crate::localization::Message; 11] = {
62    use crate::localization::Message;
63    [
64        Message::new("cranpose-ui", "copy", &SOURCE),
65        Message::new("cranpose-ui", "cut", &SOURCE),
66        Message::new("cranpose-ui", "paste", &SOURCE),
67        Message::new("cranpose-ui", "select-all", &SOURCE),
68        Message::new("cranpose-ui", "undo", &SOURCE),
69        Message::new("cranpose-ui", "redo", &SOURCE),
70        Message::new("cranpose-ui", "search", &SOURCE),
71        Message::new("cranpose-ui", "previous-month", &SOURCE),
72        Message::new("cranpose-ui", "next-month", &SOURCE),
73        Message::new("cranpose-ui", "hour", &SOURCE),
74        Message::new("cranpose-ui", "minute", &SOURCE),
75    ]
76};
77
78#[cfg(feature = "localization")]
79/// Translations for Cranpose controls, with namespaces applications can override.
80pub fn catalog() -> crate::localization::Catalog {
81    crate::translations!("locales", fallback = "en")
82}