2017-06-03 130 views
0

我有以下的科爾多瓦項目在我的index.html的代碼在科爾多瓦的WebView應用程序的操作系統語言的特定語言網址:重定向用戶根據

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Security-Policy" content="img-src * 'self' data:; default-src * 'self' gap: wss: ws: ; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval';"> 
     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <title>MyBilli</title> 
    </head> 
    <body> 
    <script type="text/javascript"> 
     document.addEventListener('deviceready', function() { 
      var url = 'http://sub.domain.com/app/nl/login/' // change to whatever you want 
      cordova.InAppBrowser.open(url, '_blank', 'location=no,zoom=no'); 
     }, false) 
    </script> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
    </body> 
</html> 

當前科爾多瓦插件列表:

cordova-plugin-camera 2.4.1 "Camera" 
cordova-plugin-compat 1.1.0 "Compat" 
cordova-plugin-device 1.1.6 "Device" 
cordova-plugin-file 4.3.3 "File" 
cordova-plugin-file-transfer 1.6.3 "File Transfer" 
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser" 
cordova-plugin-media 3.0.1 "Media" 
cordova-plugin-media-capture 1.4.3 "Capture" 
cordova-plugin-network-information 1.3.3 "Network Information" 
cordova-plugin-splashscreen 4.0.3 "Splashscreen" 
cordova-plugin-statusbar 2.2.3 "StatusBar" 
cordova-plugin-whitelist 1.3.2 "Whitelist" 

是否有可能根據自己的操作系統語言的用戶重定向(僅3種語言允許:ENFRNL)到不同的U RL:sub.domain.com/app/ [EN | | NL] /登錄/

如果ENFRNL不是用戶的操作系統語言,默認爲EN

回答

1

貌似可以用https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-globalization/

獲得設備的語言你會那麼只需要更換URL部分,什麼是拿起

+0

你能解釋一下我的代碼中我應該使用這個嗎?在index.html或其他地方?謝謝! – andyderuyter

+0

你會在你定義你的url的地方使用它,你會用navigator.globalization.getPreferredLanguage(successCallback,errorCallback)的結果替換你的url的/ nl /部分; https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-globalization/#navigatorglobalizationgetpreferredlanguage – user2098856