diff --git a/ng-app/src-tauri/src/lib.rs b/ng-app/src-tauri/src/lib.rs index 73db314..58c1e1f 100644 --- a/ng-app/src-tauri/src/lib.rs +++ b/ng-app/src-tauri/src/lib.rs @@ -41,7 +41,23 @@ pub type SetupHook = Box Result<(), Box Result, ()> { - Ok(get_locales().filter(|lang| lang != "C").collect()) + Ok(get_locales() + .filter_map(|lang| { + if lang == "C" || lang == "c" { + None + } else { + let mut split = lang.split('.'); + let code = split.next().unwrap(); + let code = code.replace("_", "-"); + let mut split = code.rsplitn(2, '-'); + let country = split.next().unwrap(); + Some(match split.next() { + Some(next) => format!("{}-{}", next, country.to_uppercase()), + None => country.to_string(), + }) + } + }) + .collect()) } #[tauri::command(rename_all = "snake_case")] diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index abdc710..7891d6f 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -102,6 +102,10 @@ const handler = { let from_js = window.navigator.languages; console.log(from_rust,from_js); for (let lang of from_js) { + let split = lang.split("-"); + if (split[1]) { + lang = split[0] + "-" + split[1].toUpperCase(); + } if (!from_rust.includes(lang)) { from_rust.push(lang);} } return from_rust; diff --git a/ng-app/src/lib/CenteredLayout.svelte b/ng-app/src/lib/CenteredLayout.svelte index cc7114b..4db2a7b 100644 --- a/ng-app/src/lib/CenteredLayout.svelte +++ b/ng-app/src/lib/CenteredLayout.svelte @@ -20,7 +20,9 @@
- {locales} + {#each locales as loc} + {loc}  + {/each}
diff --git a/ng-repo/src/utils.rs b/ng-repo/src/utils.rs index c1eb1db..971e012 100644 --- a/ng-repo/src/utils.rs +++ b/ng-repo/src/utils.rs @@ -230,3 +230,31 @@ pub fn display_timestamp(ts: &Timestamp) -> String { } pub(crate) type Receiver = mpsc::UnboundedReceiver; + +#[cfg(test)] +mod test { + use crate::log::*; + #[test] + pub fn test_locales() { + let list = vec!["C", "c", "aa-bb-cc-dd", "aa-ff_bb.456d"]; + let res: Vec = list + .iter() + .filter_map(|lang| { + if *lang == "C" || *lang == "c" { + None + } else { + let mut split = lang.split('.'); + let code = split.next().unwrap(); + let code = code.replace("_", "-"); + let mut split = code.rsplitn(2, '-'); + let country = split.next().unwrap(); + Some(match split.next() { + Some(next) => format!("{}-{}", next, country.to_uppercase()), + None => country.to_string(), + }) + } + }) + .collect(); + log_debug!("{:?}", res); + } +}