euv-example 0.26.5

An example application demonstrating the euv UI framework with reactive signals, custom components, and WebAssembly.
Documentation
use super::*;

/// Default locale tag for the i18n demo.
pub(crate) const HOOKS_I18N_DEFAULT_LOCALE: &str = "en";

/// Secondary locale tag the demo can switch into.
pub(crate) const HOOKS_I18N_OTHER_LOCALE: &str = "zh-CN";

/// English-language button label.
pub(crate) const HOOKS_I18N_LABEL_EN: &str = "English";

/// "Other" (Chinese) language button label.
pub(crate) const HOOKS_I18N_LABEL_OTHER: &str = "中文";

/// Translation key for the greeting message.
pub(crate) const HOOKS_I18N_KEY_GREETING: &str = "greeting";

/// Translation key for the farewell message.
pub(crate) const HOOKS_I18N_KEY_FAREWELL: &str = "farewell";

/// English (`en`) translation table — `&'static` tuples are the
/// only form `i18n_register` can accept without leaking. The
/// underlying `I18n::add_messages` does the
/// `&str -> String` round-trip on the caller's behalf.
pub(crate) const HOOKS_I18N_EN_MESSAGES: [(&str, &str); 2] = [
    ("greeting", "Hello, world!"),
    ("farewell", "Goodbye, world!"),
];

/// `zh-CN` translation table.
pub(crate) const HOOKS_I18N_ZH_MESSAGES: [(&str, &str); 2] =
    [("greeting", "你好,世界!"), ("farewell", "再见,世界!")];

/// Builds a click handler that switches the supplied i18n
/// handle to the supplied locale.
pub(crate) fn hooks_i18n_switch(handle: I18n, locale: String) -> Option<Rc<dyn Fn(Event)>> {
    Some(Rc::new(move |_: Event| {
        handle.change_locale(locale.as_str());
    }))
}

/// Returns the translated message for `key` on the supplied
/// handle, falling back to the key itself if missing.
pub(crate) fn hooks_i18n_translate(handle: I18n, key: &'static str) -> String {
    handle.t(key)
}