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.
Settings shows extensions' translated descriptions, not __MSG_ keys (#200)
Daddio1647eb612f85
diff --git a/Sources/Cra/Services/ExtensionStore.swift b/Sources/Cra/Services/ExtensionStore.swiftindex 980e155..37d6e33 100644--- a/Sources/Cra/Services/ExtensionStore.swift+++ b/Sources/Cra/Services/ExtensionStore.swift@@ -246,7 +246,8 @@ final class ExtensionStore {let options = (m["options_ui"] as? [String: Any])?["page"] as? String ?? m["options_page"] as? String// A path or {size: path} (React DevTools' grey "disabled" icon until a page uses React).let actionIcons = action?["default_icon"] as? [String: String] ?? (action?["default_icon"] as? String).map { ["16": $0] }- return Entry(id: id, name: title.isEmpty ? id : title, version: str("version"), description: str("description"), url: dir,+ let description = ExtensionImporter.localizedDescription(manifest: m, folder: dir)+ return Entry(id: id, name: title.isEmpty ? id : title, version: str("version"), description: description, url: dir,extensionID: extensionID ?? chromiumID(key: m["key"] as? String, folder: dir),icon: actionIcons.flatMap { ExtensionImporter.icon(manifest: ["icons": $0], folder: dir, minPixels: 16) }?? ExtensionImporter.icon(manifest: m, folder: dir, minPixels: 16),diff --git a/Sources/Cra/Services/Import/ExtensionImporter.swift b/Sources/Cra/Services/Import/ExtensionImporter.swiftindex a80be1c..b59b78f 100644--- a/Sources/Cra/Services/Import/ExtensionImporter.swift+++ b/Sources/Cra/Services/Import/ExtensionImporter.swift@@ -105,6 +105,12 @@ enum ExtensionImporter {}}+ /// Descriptions are optional: Settings omits an unresolved message key instead of displaying it.+ static func localizedDescription(manifest: [String: Any], folder: URL) -> String {+ let value = localized(manifest["description"] as? String ?? "", manifest: manifest, folder: folder)+ return value.hasPrefix("__MSG_") && value.hasSuffix("__") ? "" : value+ }+/// Resolves `__MSG_key__` from the extension's default locale.static func localized(_ value: String, manifest: [String: Any], folder: URL) -> String {guard value.hasPrefix("__MSG_"), value.hasSuffix("__") else { return value }diff --git a/Tests/ExtensionStateTests.swift b/Tests/ExtensionStateTests.swiftindex 0ad9d9c..8b6bad8 100644--- a/Tests/ExtensionStateTests.swift+++ b/Tests/ExtensionStateTests.swift@@ -56,6 +56,48 @@ enum ExtensionStateTests {"a just-loaded unpacked extension: on, localized name, its own folder")check(fromLive.first { $0.id == "store" }?.folder.path == store.path, "a relative path sits in the profile's Extensions")check(ExtensionImporter.disabledIDs(settings: live) == off, "live disabled IDs match the files'")++ // Settings must show extension descriptions, not manifest message keys (1Password and+ // LanguageTool). An unavailable optional description is hidden; names retain their fallback.+ let fixture = URL(fileURLWithPath: #filePath).deletingLastPathComponent()+ .appendingPathComponent("Fixtures/LocalizedExtension")+ let localizedFolder = profile.appendingPathComponent("localized")+ try fm.copyItem(at: fixture, to: localizedFolder)+ let manifestData = try Data(contentsOf: localizedFolder.appendingPathComponent("manifest.json"))+ let manifest = try JSONSerialization.jsonObject(with: manifestData) as! [String: Any]+ check(ExtensionImporter.localizedDescription(manifest: manifest, folder: localizedFolder) == "Passwörter sicher verwalten.",+ "the actual fixture manifest resolves its description for Settings")+ func messages(_ locale: String, _ contents: String) throws {+ let dir = localizedFolder.appendingPathComponent("_locales/\(locale)")+ try fm.createDirectory(at: dir, withIntermediateDirectories: true)+ try Data(contents.utf8).write(to: dir.appendingPathComponent("messages.json"))+ }+ func description(_ value: String, folder: URL? = nil) -> String {+ var input = manifest+ input["description"] = value+ return ExtensionImporter.localizedDescription(manifest: input, folder: folder ?? localizedFolder)+ }+ check(description("__MSG_extDescription__") == "Passwörter sicher verwalten.", "default locale before English")+ check(description("__MSG_appDesc__") == "Texte prüfen – überall.", "LanguageTool key and Unicode")+ check(description("__MSG_EXTDESCRIPTION__") == "Passwörter sicher verwalten.", "case-insensitive message keys")+ check(description("A plain description") == "A plain description", "literal descriptions stay unchanged")+ check(description("").isEmpty, "empty descriptions stay empty")+ check(ExtensionImporter.localizedDescription(manifest: [:], folder: localizedFolder).isEmpty,+ "absent descriptions stay empty")+ check(ExtensionImporter.localizedDescription(manifest: ["description": 42], folder: localizedFolder).isEmpty,+ "invalid description type stays empty")+ check(description("__MSG_englishOnly__") == "English fallback", "missing default key falls back to English")+ check(description("__MSG_usOnly__") == "US fallback", "en_US fallback")+ check(description("__MSG_missing__").isEmpty, "missing key never appears in settings")+ try messages("en_US", #"{"invalid":{"message":42}}"#)+ check(description("__MSG_invalid__").isEmpty, "non-string translation is hidden")+ check(description("__MSG_extDescription__", folder: profile.appendingPathComponent("missing")).isEmpty,+ "missing locale files do not expose the key")+ check(ExtensionImporter.localized("__MSG_missing__", manifest: manifest, folder: unpacked) == "__MSG_missing__",+ "existing name fallback remains unchanged")+ try messages("de", "not JSON")+ check(description("__MSG_extDescription__") == "Manage passwords.", "invalid catalog falls back to English")+ check(description("__MSG_appDesc__").isEmpty, "invalid catalog without a fallback message hides the key")print("ExtensionStateTests: \(checks) checks passed")}}diff --git a/Tests/Fixtures/LocalizedExtension/_locales/de/messages.json b/Tests/Fixtures/LocalizedExtension/_locales/de/messages.jsonnew file mode 100644index 0000000..4602340--- /dev/null+++ b/Tests/Fixtures/LocalizedExtension/_locales/de/messages.json@@ -0,0 +1,4 @@+{+ "extDescription": { "message": "Passwörter sicher verwalten." },+ "appDesc": { "message": "Texte prüfen – überall." }+}diff --git a/Tests/Fixtures/LocalizedExtension/_locales/en/messages.json b/Tests/Fixtures/LocalizedExtension/_locales/en/messages.jsonnew file mode 100644index 0000000..3cc17c9--- /dev/null+++ b/Tests/Fixtures/LocalizedExtension/_locales/en/messages.json@@ -0,0 +1,4 @@+{+ "extDescription": { "message": "Manage passwords." },+ "englishOnly": { "message": "English fallback" }+}diff --git a/Tests/Fixtures/LocalizedExtension/_locales/en_US/messages.json b/Tests/Fixtures/LocalizedExtension/_locales/en_US/messages.jsonnew file mode 100644index 0000000..97a406f--- /dev/null+++ b/Tests/Fixtures/LocalizedExtension/_locales/en_US/messages.json@@ -0,0 +1,3 @@+{+ "usOnly": { "message": "US fallback" }+}diff --git a/Tests/Fixtures/LocalizedExtension/manifest.json b/Tests/Fixtures/LocalizedExtension/manifest.jsonnew file mode 100644index 0000000..0d0e4ce--- /dev/null+++ b/Tests/Fixtures/LocalizedExtension/manifest.json@@ -0,0 +1,7 @@+{+ "manifest_version": 3,+ "name": "Cra Localized Description Fixture",+ "version": "1.0",+ "default_locale": "de",+ "description": "__MSG_extDescription__"+}