Explorar o código

allow local help specified by language+region

B. Petersen %!s(int64=4) %!d(string=hai) anos
pai
achega
091208fb20

+ 4 - 2
deltachat-ios/Controller/HelpViewController.swift

@@ -22,10 +22,12 @@ class HelpViewController: WebViewViewController {
     private func loadHtmlContent(completionHandler: ((URL) -> Void)?) {
         // execute in background thread because file loading would blockui for a few milliseconds
         DispatchQueue.global(qos: .background).async {
-            let lang = Utils.getDeviceLanguage() ?? "en" // en is backup
+            let langAndRegion = Locale.preferredLanguages.first ?? "en"
+            let langOnly = String(langAndRegion.split(separator: "-").first ?? Substring("ErrLang"))
             var fileURL: URL?
 
-            fileURL = Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/\(lang)") ??
+            fileURL = Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/\(langAndRegion)") ??
+                Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/\(langOnly)") ??
                 Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/en")
 
             guard let url = fileURL else {

+ 0 - 8
deltachat-ios/Helper/Utils.swift

@@ -56,12 +56,4 @@ struct Utils {
         ///TODO: add more file suffixes
         return url.absoluteString.hasSuffix("wav")
     }
-
-    static func getDeviceLanguage() -> String? {
-        // some device languages have suffixes (like en-aus etc.) so we want to cut suffixes off
-        guard let lang = Locale.preferredLanguages.first?.split(separator: "-").first else {
-            return nil
-        }
-        return String(lang)
-    }
 }