license: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
獲取用戶端的當前語言的字串識別碼。
navigator.globalization.getPreferredLanguage(successCallback, errorCallback);
返回到的語言識別項字串 successCallback 與 properties 物件作為參數。 物件應具有 value 屬性與 String 的值。
如果有出錯的語言,然後 errorCallback 執行與 GlobalizationError 物件作為參數。 錯誤的期望的代碼GlobalizationError.UNKNOWN\_ERROR.
當瀏覽器設置為 en\_US 的地區設定,此時應顯示彈出式功能表對話方塊的文本與 language: English :
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
<!DOCTYPE HTML>
<html>
<head>
<title>getPreferredLanguage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function checkLanguage() {
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
}
</script>
</head>
<body>
<button onclick="checkLanguage()">Click for language</button>
</body>
</html>