Respect territory in locale (e.g. de_CH) for byte formatting (#3560)

This commit is contained in:
Pirmin Kalberer 2021-06-06 19:25:03 +02:00 committed by GitHub
parent a2e6f5ebdb
commit 57a009b8e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -202,11 +202,12 @@ impl InlineShape {
// Since get_locale() and Locale::from_name() don't always return the same items
// we need to try and parse it to match. For instance, a valid locale is de_DE
// however Locale::from_name() wants only de so we split and parse it out.
let locale_string = locale_string.replace("_", "-"); // en_AU -> en-AU
let locale = match Locale::from_name(&locale_string) {
Ok(loc) => loc,
_ => {
let all = num_format::Locale::available_names();
let locale_prefix = &locale_string.split('_').collect::<Vec<&str>>();
let locale_prefix = &locale_string.split('-').collect::<Vec<&str>>();
if all.contains(&locale_prefix[0]) {
// eprintln!("Found alternate: {}", &locale_prefix[0]);
Locale::from_name(locale_prefix[0]).unwrap_or(Locale::en)