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

@ -59,6 +59,7 @@ impl HumanReadableErrorType {
self,
dst: Box<dyn Write + Send>,
source_map: Option<Lrc<SourceMap>>,
bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
teach: bool,
terminal_width: Option<usize>,
@ -69,6 +70,7 @@ impl HumanReadableErrorType {
EmitterWriter::new(
dst,
source_map,
bundle,
fallback_bundle,
short,
teach,
@ -568,7 +570,7 @@ impl Emitter for EmitterWriter {
}
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
None
self.fluent_bundle.as_ref()
}
fn fallback_fluent_bundle(&self) -> &Lrc<FluentBundle> {
@ -686,6 +688,7 @@ impl ColorConfig {
pub struct EmitterWriter {
dst: Destination,
sm: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
short_message: bool,
teach: bool,
@ -706,6 +709,7 @@ impl EmitterWriter {
pub fn stderr(
color_config: ColorConfig,
source_map: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
short_message: bool,
teach: bool,
@ -716,6 +720,7 @@ impl EmitterWriter {
EmitterWriter {
dst,
sm: source_map,
fluent_bundle,
fallback_bundle,
short_message,
teach,
@ -728,6 +733,7 @@ impl EmitterWriter {
pub fn new(
dst: Box<dyn Write + Send>,
source_map: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
short_message: bool,
teach: bool,
@ -738,6 +744,7 @@ impl EmitterWriter {
EmitterWriter {
dst: Raw(dst, colored),
sm: source_map,
fluent_bundle,
fallback_bundle,
short_message,
teach,