mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44: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)]
|
||||
|
||||
use fluent_bundle::FluentResource;
|
||||
@ -105,9 +106,12 @@ pub fn fluent_bundle(
|
||||
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
|
||||
// provided locale.
|
||||
let locale = requested_locale.clone().unwrap_or_else(|| langid!("en-US"));
|
||||
let locale = requested_locale.clone().unwrap_or(fallback_locale);
|
||||
trace!(?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).
|
||||
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();
|
||||
sysroot.push("share");
|
||||
sysroot.push("locale");
|
||||
@ -140,7 +145,8 @@ pub fn fluent_bundle(
|
||||
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 =
|
||||
FluentResource::try_new(resource_str).map_err(TranslationBundleError::from)?;
|
||||
trace!(?resource);
|
||||
|
Loading…
Reference in New Issue
Block a user