Files
todo-baggins/dioxus-i18n/tests/graceful_fallback_spec.rs
Matouš Volf 2c2ad7ad21
Some checks failed
hadolint check / hadolint check (pull_request) Successful in 13s
actionlint check / actionlint check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 3s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 6s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 7s
GitLeaks check / GitLeaks check (pull_request) Successful in 13s
markdownlint check / markdownlint check (pull_request) Failing after 54s
Prettier check / Prettier check (pull_request) Failing after 51s
htmlhint check / htmlhint check (pull_request) Successful in 1m3s
checkov check / checkov check (pull_request) Failing after 2m26s
ShellCheck check / ShellCheck check (pull_request) Successful in 1m14s
Stylelint check / Stylelint check (pull_request) Successful in 1m27s
Rust check / Rust check (pull_request) Failing after 11m40s
yamllint check / yamllint check (pull_request) Successful in 13m36s
fix: automatically reconnect after losing a WebSocket connection
2026-01-23 11:04:10 +01:00

100 lines
2.9 KiB
Rust

mod common;
use common::*;
use dioxus_i18n::prelude::{use_init_i18n, I18n, I18nConfig};
use unic_langid::{langid, LanguageIdentifier};
#[test]
fn exact_locale_match_will_use_translation() {
test_hook(i18n, |value, proxy| {
proxy.assert(
value
.try_translate("variants")
.expect("test message id must exist"),
"variants only".to_string(),
"exact_locale_match_will_use_translation",
);
});
}
#[test]
fn non_exact_locale_match_will_use_region() {
test_hook(i18n, |value, proxy| {
proxy.assert(
value
.try_translate("region")
.expect("test message id must exist"),
"region only".to_string(),
"non_exact_locale_match_will_use_region",
);
});
}
#[test]
fn non_exact_locale_match_will_use_script() {
test_hook(i18n, |value, proxy| {
proxy.assert(
value
.try_translate("script")
.expect("test message id must exist"),
"script only".to_string(),
"non_exact_locale_match_will_use_script",
);
});
}
#[test]
fn non_exact_locale_match_will_use_language() {
test_hook(i18n, |value, proxy| {
proxy.assert(
value
.try_translate("language")
.expect("test message id must exist"),
"language only".to_string(),
"non_exact_locale_match_will_use_language",
);
});
}
#[test]
fn no_locale_match_will_use_fallback() {
test_hook(i18n, |value, proxy| {
proxy.assert(
value
.try_translate("fallback")
.expect("test message id must exist"),
"fallback only".to_string(),
"no_locale_match_will_use_fallback",
);
});
}
fn i18n() -> I18n {
const FALLBACK_LANG: LanguageIdentifier = langid!("fb-FB");
const LANGUAGE_LANG: LanguageIdentifier = langid!("la");
const SCRIPT_LANG: LanguageIdentifier = langid!("la-Scpt");
const REGION_LANG: LanguageIdentifier = langid!("la-Scpt-LA");
let variants_lang: LanguageIdentifier = langid!("la-Scpt-LA-variants");
let config = I18nConfig::new(variants_lang.clone())
.with_locale((LANGUAGE_LANG, include_str!("../tests/data/fallback/la.ftl")))
.with_locale((
SCRIPT_LANG,
include_str!("../tests/data/fallback/la-Scpt.ftl"),
))
.with_locale((
REGION_LANG,
include_str!("../tests/data/fallback/la-Scpt-LA.ftl"),
))
.with_locale((
variants_lang.clone(),
include_str!("../tests/data/fallback/la-Scpt-LA-variants.ftl"),
))
.with_locale((
FALLBACK_LANG,
include_str!("../tests/data/fallback/fb-FB.ftl"),
))
.with_fallback(FALLBACK_LANG);
use_init_i18n(|| config)
}