pull/27/head
Niko PLP 3 months ago
parent 1e3b6455fe
commit 6667fcd37f
  1. 18
      ng-app/src-tauri/src/lib.rs
  2. 4
      ng-app/src/api.ts
  3. 4
      ng-app/src/lib/CenteredLayout.svelte
  4. 28
      ng-repo/src/utils.rs

@ -41,7 +41,23 @@ pub type SetupHook = Box<dyn FnOnce(&mut App) -> Result<(), Box<dyn std::error::
#[tauri::command(rename_all = "snake_case")]
async fn locales() -> Result<Vec<String>, ()> {
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")]

@ -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;

@ -20,7 +20,9 @@
</script>
<div class="centered">
{locales}
{#each locales as loc}
{loc}&nbsp;
{/each}
<slot />
</div>

@ -230,3 +230,31 @@ pub fn display_timestamp(ts: &Timestamp) -> String {
}
pub(crate) type Receiver<T> = mpsc::UnboundedReceiver<T>;
#[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<String> = 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);
}
}

Loading…
Cancel
Save