/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththisfile,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
usecrate::builtins::{FluentDateTime, FluentDateTimeOptions, NumberFormat}; use cstr::cstr; pubuse fluent::{FluentArgs, FluentBundle, FluentError, FluentResource, FluentValue}; use fluent_pseudo::transform_dom; pubuse intl_memoizer::IntlLangMemoizer; use nsstring::{nsACString, nsCString}; use std::borrow::Cow; use std::ffi::CStr; use std::mem; use std::rc::Rc; use thin_vec::ThinVec; use unic_langid::LanguageIdentifier; use xpcom::interfaces::nsIPrefBranch;
bundle
.add_function("PLATFORM", |_args, _named_args| { if cfg!(target_os = "linux") { "linux".into()
} elseif cfg!(target_os = "windows") { "windows".into()
} elseif cfg!(target_os = "macos") { "macos".into()
} elseif cfg!(target_os = "android") { "android".into()
} else { "other".into()
}
})
.expect("Failed to add a function to the bundle.");
bundle
.add_function("NUMBER", |args, named| { iflet Some(FluentValue::Number(n)) = args.get(0) { letmut num = n.clone();
num.options.merge(named);
FluentValue::Number(num)
} else {
FluentValue::None
}
})
.expect("Failed to add a function to the bundle.");
bundle
.add_function("DATETIME", |args, named| { iflet Some(FluentValue::Number(n)) = args.get(0) { letmut options = FluentDateTimeOptions::default();
options.merge(&named);
FluentValue::Custom(Box::new(FluentDateTime::new(n.value, options)))
} else {
FluentValue::None
}
})
.expect("Failed to add a function to the bundle.");
enum PseudoStrategy {
Accented,
Bidi,
None,
} // This is quirky because we can't coerce Option<&nsACString> and Option<nsCString> // into bytes easily without allocating. let strategy_kind = match pseudo_strategy.map(|s| &s[..]) {
Some(b"accented") => PseudoStrategy::Accented,
Some(b"bidi") => PseudoStrategy::Bidi,
_ => { iflet Some(pseudo_strategy) = get_string_pref(cstr!("intl.l10n.pseudo")) { match &pseudo_strategy[..] {
b"accented" => PseudoStrategy::Accented,
b"bidi" => PseudoStrategy::Bidi,
_ => PseudoStrategy::None,
}
} else {
PseudoStrategy::None
}
}
}; match strategy_kind {
PseudoStrategy::Accented => bundle.set_transform(Some(transform_accented)),
PseudoStrategy::Bidi => bundle.set_transform(Some(transform_bidi)),
PseudoStrategy::None => bundle.set_transform(None),
}
// Temporarily disable bidi isolation due to Microsoft not supporting FSI/PDI. // See bug 1439018 for details. let default_use_isolating = false; let use_isolating =
get_bool_pref(cstr!("intl.l10n.enable-bidi-marks")).unwrap_or(default_use_isolating);
bundle.set_use_isolating(use_isolating);
}
#[no_mangle] pubextern"C"fn fluent_bundle_new_single(
locale: &nsACString,
use_isolating: bool,
pseudo_strategy: &nsACString,
) -> *mut FluentBundleRc { let id = match locale.to_utf8().parse::<LanguageIdentifier>() {
Ok(id) => id,
Err(..) => return std::ptr::null_mut(),
};
letmut result = FluentArgs::with_capacity(args.len()); for arg in args { let val = match arg.value {
FluentArgument::Double_(d) => FluentValue::from(d),
FluentArgument::String(s) => FluentValue::from(s.to_utf8()),
};
result.set(arg.id.to_string(), val);
}
Some(result)
}
fn append_fluent_errors_to_ret_errors(ret_errors: &mut ThinVec<nsCString>, errors: &[FluentError]) { for error in errors {
ret_errors.push(error.to_string().into());
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.