Some checks failed
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 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 11s
hadolint check / hadolint check (pull_request) Successful in 14s
Prettier check / Prettier check (pull_request) Failing after 35s
markdownlint check / markdownlint check (pull_request) Failing after 40s
htmlhint check / htmlhint check (pull_request) Successful in 44s
checkov check / checkov check (pull_request) Failing after 1m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 23s
Stylelint check / Stylelint check (pull_request) Successful in 24s
yamllint check / yamllint check (pull_request) Successful in 22s
Rust check / Rust check (pull_request) Failing after 57m45s
100 lines
2.9 KiB
Rust
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)
|
|
}
|