The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
Chromium's language follows macOS as in Chrome and Arc, so speech without a lang uses a voice for it (#167)
Victor3d6705532074
diff --git a/Packages/CraCore/Sources/CraCore/ChromiumLocale.swift b/Packages/CraCore/Sources/CraCore/ChromiumLocale.swiftnew file mode 100644index 0000000..12a756c--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/ChromiumLocale.swift@@ -0,0 +1,25 @@+import Foundation++/// Chromium's application locale (`CefSettings.locale`, `--lang`), picked the way Chrome and+/// Arc pick it on macOS: the first macOS language the browser has a translation for, matched by+/// macOS itself (Chrome's `OverrideLocaleWithCocoaLocale` reads its bundle's+/// `preferredLocalizations`, and Arc's bundle carries one `.lproj` per Chromium locale).+///+/// It decides which voice speaks an utterance that has no `lang` (#167), what language+/// Chromium's own pages, dialogs and menus are in, how pages format dates by default, and a new+/// profile's Accept-Language. Without it CEF forces en-US whatever macOS is set to.+public enum ChromiumLocale {+ /// `available` is the framework's localization folder names ("en", "en_GB", "zh_CN",+ /// "af_FEMININE"), `preferredLanguages` the user's macOS languages, most wanted first+ /// ("zh-Hans-CN"). Nil when the framework lists no locales, which leaves CEF's en-US.+ public static func pick(available: [String], preferredLanguages: [String]) -> String? {+ // Chromium 156 ships gendered variants of each locale; they aren't separate languages.+ let candidates = available+ .filter { !["_FEMININE", "_MASCULINE", "_NEUTER"].contains(where: $0.hasSuffix) && $0 != "Base" }+ .map { $0.replacingOccurrences(of: "_", with: "-") }+ guard !candidates.isEmpty else { return nil }+ guard let match = Bundle.preferredLocalizations(from: candidates, forPreferences: preferredLanguages).first else { return nil }+ // On disk Chromium's en-US is just "en" (crbug.com/25578); Chrome maps it back.+ return match == "en" ? "en-US" : match+ }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/ChromiumLocaleTests.swift b/Packages/CraCore/Tests/CraCoreTests/ChromiumLocaleTests.swiftnew file mode 100644index 0000000..b3b631b--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/ChromiumLocaleTests.swift@@ -0,0 +1,41 @@+import CraCore+import Testing++/// Chromium's application locale follows macOS the way Chrome's and Arc's do (#167).+struct ChromiumLocaleTests {+ /// The folder names in CEF 156's Resources: one per locale plus gendered variants.+ static let cef: [String] = {+ let locales = ["af", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "en_GB", "es", "es_419",+ "et", "fa", "fi", "fil", "fr", "gu", "he", "hi", "hr", "hu", "id", "it", "ja", "kn", "ko",+ "lt", "lv", "ml", "mr", "ms", "nb", "nl", "pl", "pt_BR", "pt_PT", "ro", "ru", "sk", "sl",+ "sr", "sv", "sw", "ta", "te", "th", "tr", "uk", "ur", "vi", "zh_CN", "zh_TW"]+ return locales.flatMap { [$0, $0 + "_FEMININE", $0 + "_MASCULINE", $0 + "_NEUTER"] }+ }()++ // Each expectation is what Arc 1.171's bundle resolves for the same macOS languages.+ @Test(arguments: [+ (["zh-Hans-CN"], "zh-CN"),+ (["zh-Hans"], "zh-CN"),+ (["zh-Hant-TW"], "zh-TW"),+ (["zh-Hant-HK"], "zh-TW"),+ (["en-US"], "en-US"),+ (["en"], "en-US"),+ (["en-DK", "da-DK"], "en-GB"),+ (["en-AU"], "en-GB"),+ (["da-DK"], "da"),+ (["pt-PT"], "pt-PT"),+ (["es-MX"], "es-419"),+ (["nb-NO"], "nb"),+ // A language Chromium has no translation for falls through to the next one.+ (["is-IS", "de-DE"], "de"),+ (["is-IS"], "en-US"),+ ])+ func followsMacOS(preferred: [String], locale: String) {+ #expect(ChromiumLocale.pick(available: Self.cef, preferredLanguages: preferred) == locale)+ }++ @Test func noLocalesLeavesCEFsDefault() {+ #expect(ChromiumLocale.pick(available: [], preferredLanguages: ["zh-Hans-CN"]) == nil)+ #expect(ChromiumLocale.pick(available: ["Base"], preferredLanguages: ["zh-Hans-CN"]) == nil)+ }+}diff --git a/Sources/Cra/App/main.swift b/Sources/Cra/App/main.swiftindex cf0dcb9..071ffff 100644--- a/Sources/Cra/App/main.swift+++ b/Sources/Cra/App/main.swift@@ -41,10 +41,17 @@ MainActor.assumeIsolated {CraCEFRuntime.setExtensionPaths(extensions.paths, profiles: extensions.profiles)if let p = extensions.profiles { CraLog.note("extension profiles: \(p)") }+ // Chromium's language follows macOS as in Chrome and Arc: it picks the voice for speech+ // without a lang (#167), Chromium's own pages and dialogs, and pages' default date format.+ let framework = Bundle.main.privateFrameworksURL?.appendingPathComponent("Chromium Embedded Framework.framework")+ let locale = ChromiumLocale.pick(available: framework.flatMap { Bundle(url: $0) }?.localizations ?? [],+ preferredLanguages: Locale.preferredLanguages)+ CraLog.note("chromium locale: \(locale ?? "en-US (default)") for \(Locale.preferredLanguages.prefix(3).joined(separator: ","))")let useChromeStyle = ProcessInfo.processInfo.environment["CRA_CHROME_STYLE"] == "1"let started = CraCEFRuntime.initialize(withCachePath: AppPaths.chromiumCache.path,userAgentProduct: "",logPath: AppPaths.log.path,+ locale: locale,useChromeStyle: useChromeStyle,useMockKeychain: !SafeStorage.usesKeychain)if !started && CraCEFRuntime.anotherInstanceWasNotified() {diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mmindex 077faac..20cc8f7 100644--- a/Sources/CraCEF/CraCEF.mm+++ b/Sources/CraCEF/CraCEF.mm@@ -2536,6 +2536,7 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {+ (BOOL)initializeWithCachePath:(NSString*)cachePathuserAgentProduct:(NSString*)productlogPath:(NSString*)logPath+ locale:(NSString*)localeuseChromeStyle:(BOOL)useChromeStyleuseMockKeychain:(BOOL)useMockKeychain {if (g_libraryLoader) return YES;@@ -2565,6 +2566,8 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {settings.persist_session_cookies = true;CefString(&settings.user_agent_product) = CefStringFromNS(product);CefString(&settings.log_file) = CefStringFromNS(logPath);+ // Without it CEF passes --lang=en-US whatever macOS is set to (#167).+ if (locale.length) CefString(&settings.locale) = CefStringFromNS(locale);settings.log_severity = LOGSEVERITY_WARNING;settings.background_color = CefColorSetARGB(255, 255, 255, 255);diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.hindex cc0389c..a99a7e0 100644--- a/Sources/CraCEF/include/CraCEF.h+++ b/Sources/CraCEF/include/CraCEF.h@@ -276,9 +276,11 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {/// for each in the same order the profile folders that load it ("Default|Profile <id>", "*"/// for every profile), comma-separated; nil when every one loads in every profile.+ (void)setExtensionPaths:(NSArray<NSString *> *)paths profiles:(nullable NSString *)profiles;+/// `locale` is Chromium's application locale ("zh-CN"); nil leaves CEF's en-US.+ (BOOL)initializeWithCachePath:(NSString *)cachePathuserAgentProduct:(NSString *)productlogPath:(NSString *)logPath+ locale:(nullable NSString *)localeuseChromeStyle:(BOOL)useChromeStyleuseMockKeychain:(BOOL)useMockKeychain;/// Runs the Chromium-integrated AppKit run loop. Returns after -quitMessageLoop.