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
|
m!.data = nil
|
||||||
replyMessage(message: m!)
|
replyMessage(message: m!)
|
||||||
} else if(command == "getLocaleStrings") {
|
} else if(command == "getLocaleStrings") {
|
||||||
let language = String(describing: m!.data)
|
let language = m!.data
|
||||||
m!.data = nil
|
m!.data = nil
|
||||||
if let path = Bundle.main.path(forResource: "app/_locales/\(language)/messages", ofType: "json") {
|
let bundleURL = Bundle.main.resourceURL!.absoluteURL
|
||||||
do {
|
let messagesUrl = bundleURL.appendingPathComponent("app/_locales/en/messages.json")
|
||||||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
|
do {
|
||||||
let json = String(data: data, encoding: .utf8)
|
let json = try String(contentsOf: messagesUrl, encoding: .utf8)
|
||||||
m!.data = json
|
webView.evaluateJavaScript("window.bitwardenLocaleStrings = \(json);", completionHandler: nil)
|
||||||
} catch {
|
m!.data = nil
|
||||||
|
} catch { }
|
||||||
}
|
|
||||||
}
|
|
||||||
replyMessage(message: m!)
|
replyMessage(message: m!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,8 +93,8 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func replyMessage(message: AppMessage) {
|
func replyMessage(message: AppMessage) {
|
||||||
let json = jsonSerialize(obj: message) ?? "\"null\""
|
let json = (jsonSerialize(obj: message) ?? "\"null\"").replacingOccurrences(of: "`", with: "\\`")
|
||||||
webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver('\(json)');", completionHandler: nil)
|
webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver(`\(json)`);", completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
</app-root>
|
</app-root>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.safariAppExtension = true;
|
window.safariAppExtension = true;
|
||||||
|
window.bitwardenLocaleStrings = null;
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="../vendor.js"></script>
|
<script type="text/javascript" src="../vendor.js"></script>
|
||||||
<script type="text/javascript" src="../background.js"></script>
|
<script type="text/javascript" src="../background.js"></script>
|
||||||
|
@ -7,8 +7,8 @@ export default class I18nService extends BaseI18nService {
|
|||||||
constructor(systemLanguage: string) {
|
constructor(systemLanguage: string) {
|
||||||
super(systemLanguage, BrowserApi.isSafariApi ? 'safari' : null, async (formattedLocale: string) => {
|
super(systemLanguage, BrowserApi.isSafariApi ? 'safari' : null, async (formattedLocale: string) => {
|
||||||
if (BrowserApi.isSafariApi) {
|
if (BrowserApi.isSafariApi) {
|
||||||
const localeJson = await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
|
await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
|
||||||
return JSON.parse(localeJson);
|
return (window as any).bitwardenLocaleStrings;
|
||||||
} else {
|
} else {
|
||||||
// Deprecated
|
// Deprecated
|
||||||
const file = await fetch(this.localesDirectory + formattedLocale + '/messages.json');
|
const file = await fetch(this.localesDirectory + formattedLocale + '/messages.json');
|
||||||
|
Loading…
Reference in New Issue
Block a user