mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-02 08:40:08 +01:00
load loacles for safari app
This commit is contained in:
parent
9ee25156bd
commit
e5e04b8fa9
@ -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") {
|
||||
let bundleURL = Bundle.main.resourceURL!.absoluteURL
|
||||
let messagesUrl = bundleURL.appendingPathComponent("app/_locales/en/messages.json")
|
||||
do {
|
||||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
|
||||
let json = String(data: data, encoding: .utf8)
|
||||
m!.data = json
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
</app-root>
|
||||
<script type="text/javascript">
|
||||
window.safariAppExtension = true;
|
||||
window.bitwardenLocaleStrings = null;
|
||||
</script>
|
||||
<script type="text/javascript" src="../vendor.js"></script>
|
||||
<script type="text/javascript" src="../background.js"></script>
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user