久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 javascript 和 PhoneGap 的 HTML5 移動應用本地化

HTML5 Mobile app localization using javascript and PhoneGap(使用 javascript 和 PhoneGap 的 HTML5 移動應用本地化)
本文介紹了使用 javascript 和 PhoneGap 的 HTML5 移動應用本地化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在創建一個可在所有 3 個移動平臺(Android、iOS a、d Windows Mobile 8)上運行的 HTML5 移動應用.我正在使用 javascript 進行本地化(https://github.com/eligrey/l10n.js/#自述文件).

I'm creating a HTML5 mobile app that runs on all 3 mobile platforms (Android, iOS a,d Windows Mobile 8). I'm using javascript for localization(https://github.com/eligrey/l10n.js/#readme).

該應用在瀏覽器上運行良好.但是當我在移動模擬器上部署它時,本地化不起作用.

The app works fine on the browser. But when I deploy it on the mobile emulator the localization is not working.

我認為問題在于 javascript 從瀏覽器獲取語言信息,但在移動設備中我們使用 PhoneGap 運行 HTML5.

I think the issue is that javascript gets language information from the browser, but in the mobile we run the HTML5 using PhoneGap.

有什么方法可以在 PhoeGap 中使用 javascript 啟用本地化.

Is there any way that I can enable localization using javascript in PhoeGap.

推薦答案

我剛剛通過為每個平臺創建一個只返回用戶當前語言環境的自定義 PhoneGap 插件解決了同樣的問題.

I've just solved same kind of problem by creating a custom PhoneGap plugins for each platforms that only returns the user's current locale.

例如,在 Android 上,插件只檢查:

for example, on Android, the plugin only checks:

var message = Locale.getDefault().getLanguage();

然后在 Javascript 方面,當您獲得該語言名稱時,例如.en,您將使用以該語言命名的 JSON 對象.JSON 對象的示例如下所示:

and then in Javascript side, when you've got that language name back, eg. en, you would use the JSON object that it named after that language. The example of JSON object would look like this:

MyApp.Language = en: {
    'Player'  : 'Player',
    'Players' : 'Players',
    'Not Set' : 'Not Set'
},
fi: {
    'Player'  : 'Pelaaja',
    'Players' : 'Pelaajat',
    'Not Set' : 'Ei m??ritetty'
}

Android 的插件就這么簡單:

The plugin for Android is simple as this:

JS 文件

window.localizeMe = {
    getDefaultLocale: function( callback ) {
        cordova.exec(
            callback,
            function(err) {
                callback( 'Error: ' + err.code );
            },
            "LocalizeMe",
            "getDefaultLocale",
            []);
    }
}

Java 文件

public class LocalizeMe extends CordovaPlugin {
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("getDefaultLocale")) {
            String message = Locale.getDefault().getLanguage();
            this.getDefaultLocale(message, callbackContext);
            return true;
        }
        return false;
    }

    private void getDefaultLocale(String message, CallbackContext callbackContext) {
        if (message != null && message.length() > 0) { 
            callbackContext.success(message);
        } else {
            callbackContext.error("Expected one non-empty string argument.");
        }
    }

}

最后,在您的主 JS 文件中,設置應用的語言:

window.localizeMe.getDefaultLocale( function( result ) {
    if ( result != null && result.length > 0 ) {
        if ( result.toLowerCase().indexOf( 'fi' ) !== -1 ) {
            MyApp.Lang = MyApp.Language.fi;
        } else {
            MyApp.Lang = MyApp.Language.en;
        }
    }
});

這篇關于使用 javascript 和 PhoneGap 的 HTML5 移動應用本地化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 黄色毛片免费看 | 男女性毛片 | 少妇特黄a一区二区三区88av | 91精品免费| 看亚洲a级一级毛片 | 国产激情综合五月久久 | 日韩久久久久 | 亚洲视频免费在线看 | 久久r免费视频 | 久产久精国产品 | 蜜桃日韩 | 国产 欧美 日韩 一区 | 在线成人一区 | 中国av在线免费观看 | 成年人视频在线免费观看 | 久久精品国产a三级三级三级 | 日韩免费视频 | 亚洲国产成人精品久久 | 你懂的国产 | 国产操操操 | xx性欧美肥妇精品久久久久久 | 2020国产在线 | 五月激情婷婷在线 | 亚洲精品免费在线观看 | 99精品欧美一区二区三区综合在线 | 成人国产精品久久 | 亚洲综合网站 | 男女激情网站免费 | 国产精品精品视频一区二区三区 | 午夜影院| 亚洲一区影院 | 欧美女优在线观看 | 久久av一区二区三区 | 精品伊人久久 | 亚洲精品免费视频 | 亚洲一区国产 | 国产美女一区二区 | 免费成人毛片 | 亚洲国产福利视频 | 丁香久久 | 毛片一区二区三区 |