errors: implement sysroot/testing bundle loading

Extend loading of Fluent bundles so that bundles can be loaded from the
sysroot based on the language requested by the user, or using a nightly
flag.

Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-03-28 09:36:20 +01:00
parent 7f91697b50
commit d5119c5b9f
23 changed files with 322 additions and 46 deletions

View file

@ -174,13 +174,15 @@ pub struct ParseSess {
impl ParseSess {
/// Used for testing.
pub fn new(file_path_mapping: FilePathMapping) -> Self {
let fallback_bundle = fallback_fluent_bundle();
let fallback_bundle =
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
let sm = Lrc::new(SourceMap::new(file_path_mapping));
let handler = Handler::with_tty_emitter(
ColorConfig::Auto,
true,
None,
Some(sm.clone()),
None,
fallback_bundle,
);
ParseSess::with_span_handler(handler, sm)
@ -211,10 +213,11 @@ impl ParseSess {
}
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self {
let fallback_bundle = fallback_fluent_bundle();
let fallback_bundle =
fallback_fluent_bundle().expect("failed to load fallback fluent bundle");
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let fatal_handler =
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, fallback_bundle);
Handler::with_tty_emitter(ColorConfig::Auto, false, None, None, None, fallback_bundle);
let handler = Handler::with_emitter(
false,
None,