diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift
index 28a92a560a..98ed941062 100644
--- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift
+++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift
@@ -77,17 +77,15 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
m!.data = nil
replyMessage(message: m!)
} else if(command == "getLocaleStrings") {
- let language = String(describing: m!.data)
+ let language = m!.data
m!.data = nil
- if let path = Bundle.main.path(forResource: "app/_locales/\(language)/messages", ofType: "json") {
- do {
- let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
- let json = String(data: data, encoding: .utf8)
- m!.data = json
- } catch {
-
- }
- }
+ let bundleURL = Bundle.main.resourceURL!.absoluteURL
+ let messagesUrl = bundleURL.appendingPathComponent("app/_locales/en/messages.json")
+ do {
+ let json = try String(contentsOf: messagesUrl, encoding: .utf8)
+ webView.evaluateJavaScript("window.bitwardenLocaleStrings = \(json);", completionHandler: nil)
+ m!.data = nil
+ } catch { }
replyMessage(message: m!)
}
}
@@ -95,8 +93,8 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
}
func replyMessage(message: AppMessage) {
- let json = jsonSerialize(obj: message) ?? "\"null\""
- webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver('\(json)');", completionHandler: nil)
+ let json = (jsonSerialize(obj: message) ?? "\"null\"").replacingOccurrences(of: "`", with: "\\`")
+ webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver(`\(json)`);", completionHandler: nil)
}
}
diff --git a/src/safari/app/desktop/safari/app/popup/index.html b/src/safari/app/desktop/safari/app/popup/index.html
index a433ef40e8..8f088a5db9 100644
--- a/src/safari/app/desktop/safari/app/popup/index.html
+++ b/src/safari/app/desktop/safari/app/popup/index.html
@@ -13,6 +13,7 @@
diff --git a/src/services/i18n.service.ts b/src/services/i18n.service.ts
index 5d820fbd68..eae7f61849 100644
--- a/src/services/i18n.service.ts
+++ b/src/services/i18n.service.ts
@@ -7,8 +7,8 @@ export default class I18nService extends BaseI18nService {
constructor(systemLanguage: string) {
super(systemLanguage, BrowserApi.isSafariApi ? 'safari' : null, async (formattedLocale: string) => {
if (BrowserApi.isSafariApi) {
- const localeJson = await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
- return JSON.parse(localeJson);
+ await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
+ return (window as any).bitwardenLocaleStrings;
} else {
// Deprecated
const file = await fetch(this.localesDirectory + formattedLocale + '/messages.json');