mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
errors: don't try load default locale from sysroot
If the user requests a diagnostic locale of "en-US" then it doesn't make sense to try and load that from the `$sysroot` because it is just the default built-in locale. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
22685b9607
commit
141f8404a8
@ -1,3 +1,4 @@
|
|||||||
|
#![feature(let_chains)]
|
||||||
#![feature(path_try_exists)]
|
#![feature(path_try_exists)]
|
||||||
|
|
||||||
use fluent_bundle::FluentResource;
|
use fluent_bundle::FluentResource;
|
||||||
@ -105,9 +106,12 @@ pub fn fluent_bundle(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fallback_locale = langid!("en-US");
|
||||||
|
let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
|
||||||
|
|
||||||
// If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
|
// If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
|
||||||
// provided locale.
|
// provided locale.
|
||||||
let locale = requested_locale.clone().unwrap_or_else(|| langid!("en-US"));
|
let locale = requested_locale.clone().unwrap_or(fallback_locale);
|
||||||
trace!(?locale);
|
trace!(?locale);
|
||||||
let mut bundle = FluentBundle::new(vec![locale]);
|
let mut bundle = FluentBundle::new(vec![locale]);
|
||||||
|
|
||||||
@ -118,7 +122,8 @@ pub fn fluent_bundle(
|
|||||||
// surrounding diagnostic messages are right-to-left, then these might be helpful).
|
// surrounding diagnostic messages are right-to-left, then these might be helpful).
|
||||||
bundle.set_use_isolating(false);
|
bundle.set_use_isolating(false);
|
||||||
|
|
||||||
if let Some(requested_locale) = requested_locale {
|
// If the user requests the default locale then don't try to load anything.
|
||||||
|
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
|
||||||
let mut sysroot = sysroot.to_path_buf();
|
let mut sysroot = sysroot.to_path_buf();
|
||||||
sysroot.push("share");
|
sysroot.push("share");
|
||||||
sysroot.push("locale");
|
sysroot.push("locale");
|
||||||
@ -140,7 +145,8 @@ pub fn fluent_bundle(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resource_str = fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
|
let resource_str =
|
||||||
|
fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
|
||||||
let resource =
|
let resource =
|
||||||
FluentResource::try_new(resource_str).map_err(TranslationBundleError::from)?;
|
FluentResource::try_new(resource_str).map_err(TranslationBundleError::from)?;
|
||||||
trace!(?resource);
|
trace!(?resource);
|
||||||
|
Loading…
Reference in New Issue
Block a user