diff --git a/toolkit/crashreporter/client/app/src/lang/omnijar.rs b/toolkit/crashreporter/client/app/src/lang/omnijar.rs index f3a9ab47422a..2d2c34dd8d99 100644 --- a/toolkit/crashreporter/client/app/src/lang/omnijar.rs +++ b/toolkit/crashreporter/client/app/src/lang/omnijar.rs @@ -21,18 +21,57 @@ pub fn read() -> anyhow::Result { path.push("omni.ja"); let mut zip = read_omnijar_file(&path)?; - let locale = { + let locales = { let buf = BufReader::new( zip.by_name("res/multilocale.txt") .context("failed to read multilocale file in zip archive")?, ); - buf.lines() + let line = buf + .lines() .next() .ok_or(anyhow::anyhow!("multilocale file was empty"))? - .context("failed to read first line of multilocale file")? + .context("failed to read first line of multilocale file")?; + line.split(",") + .map(|s| s.trim().to_owned()) + .collect::>() }; - let mut file = zip + let (locale, ftl_definitions) = 'defs: { + for locale in &locales { + match read_strings(locale, &mut zip) { + Ok(v) => break 'defs (locale.to_string(), v), + Err(e) => log::warn!("{e:#}"), + } + } + anyhow::bail!("failed to find any usable localized strings in the omnijar") + }; + + // The brand ftl is in the browser omnijar. + path.pop(); + path.push("browser"); + path.push("omni.ja"); + + let ftl_branding = 'branding: { + for locale in &locales { + match read_branding(&locale, &mut zip) { + Ok(v) => break 'branding v, + Err(e) => log::warn!("failed to read branding from omnijar: {e:#}"), + } + } + log::info!("using fallback branding info"); + LanguageInfo::default().ftl_branding + }; + + Ok(LanguageInfo { + identifier: locale, + ftl_definitions, + ftl_branding, + }) +} + +/// Read the localized strings from the given zip archive (omnijar). +fn read_strings(locale: &str, archive: &mut ZipArchive) -> anyhow::Result { + let mut file = archive .by_name(&format!( "localization/{locale}/crashreporter/crashreporter.ftl" )) @@ -42,34 +81,18 @@ pub fn read() -> anyhow::Result { file.read_to_string(&mut ftl_definitions) .with_context(|| format!("failed to read localization file for {locale}"))?; - // The brand ftl is in the browser omnijar. - path.pop(); - path.push("browser"); - path.push("omni.ja"); + Ok(ftl_definitions) +} - let ftl_branding = read_omnijar_file(&path) - .and_then(|mut zip| { - let mut file = zip - .by_name(&format!("localization/{locale}/branding/brand.ftl")) - .with_context(|| { - format!("failed to locate branding localization file for {locale}") - })?; - let mut s = String::new(); - file.read_to_string(&mut s) - .with_context(|| format!("failed to read localization file for {locale}"))?; - Ok(s) - }) - .unwrap_or_else(|e| { - log::warn!("failed to read browser omnijar: {e}"); - log::info!("using fallback branding info"); - LanguageInfo::default().ftl_branding - }); - - Ok(LanguageInfo { - identifier: locale, - ftl_definitions, - ftl_branding, - }) +/// Read the branding information from the given zip archive (omnijar). +fn read_branding(locale: &str, archive: &mut ZipArchive) -> anyhow::Result { + let mut file = archive + .by_name(&format!("localization/{locale}/branding/brand.ftl")) + .with_context(|| format!("failed to locate branding localization file for {locale}"))?; + let mut s = String::new(); + file.read_to_string(&mut s) + .with_context(|| format!("failed to read branding localization file for {locale}"))?; + Ok(s) } fn read_omnijar_file(path: &Path) -> anyhow::Result> {