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

使用 javascript 和 PhoneGap 的 HTML5 移動應(yīng)用本地化

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

問題描述

我正在創(chuàng)建一個可在所有 3 個移動平臺(Android、iOS a、d Windows Mobile 8)上運(yùn)行的 HTML5 移動應(yīng)用.我正在使用 javascript 進(jìn)行本地化(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).

該應(yīng)用在瀏覽器上運(yùn)行良好.但是當(dāng)我在移動模擬器上部署它時,本地化不起作用.

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

我認(rèn)為問題在于 javascript 從瀏覽器獲取語言信息,但在移動設(shè)備中我們使用 PhoneGap 運(yùn)行 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.

推薦答案

我剛剛通過為每個平臺創(chuàng)建一個只返回用戶當(dāng)前語言環(huán)境的自定義 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 方面,當(dāng)您獲得該語言名稱時,例如.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 文件中,設(shè)置應(yīng)用的語言:

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;
        }
    }
});

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

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

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯誤) - IT屋-程序員軟件開發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機(jī)/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: www.色综合 | 在线一区视频 | 超碰在线观看97 | 免费网站在线 | 欧美日韩一区二区三区视频 | 91在线一区二区三区 | 国产999精品久久久久久 | 一级二级三级在线观看 | 久久久激情 | av 一区二区三区 | 欧美精品v国产精品v日韩精品 | 一区二区三区四区电影视频在线观看 | 亚洲高清在线免费观看 | 日本成人久久 | 国产精品国产a级 | 国产精品日韩欧美一区二区三区 | 欧美日韩大片 | 成人国产精品久久 | 免费能直接在线观看黄的视频 | 精品一区二区三区在线视频 | 欧美激情欧美激情在线五月 | 天堂免费 | 亚洲欧美在线观看 | 亚洲精品一区二区三区中文字幕 | 国产日韩在线观看一区 | 免费的网站www | 久久久久成人精品免费播放动漫 | 欧美xxxx色视频在线观看免费 | 国产精品久久久久久高潮 | 午夜男人天堂 | 久久精品手机视频 | 国产一区二区三区久久 | 91黄色片免费看 | 午夜爽爽爽男女免费观看影院 | 精品视频一区二区三区四区 | 日韩成人在线免费视频 | 久久精品国产99国产精品 | 欧美极品视频在线观看 | 久久一区二区三区四区 | 在线免费观看成年人视频 | 国产乱码精品1区2区3区 |