Menggunakan Perpustakaan Penutupan pada aplikasi Phonegap (Android) (Using Closure Library on Phonegap(Android) application)


問題描述

Menggunakan Perpustakaan Penutupan pada aplikasi Phonegap (Android) (Using Closure Library on Phonegap(Android) application)

Hi has any one used google's Closure Library https://developers.google.com/closure/ in building Phonegap applications on Android. I have read that Closure has good support for internationalization of applications. So if anyone could provide material they referred or sample snippets to get an idea of how to implement it. 

‑‑‑‑‑

參考解法

方法 1:

There is no difference as to how you use PhoneGap. Framing a web view inside a native app background, doesn't change.

The Closure Library, unlike any other library, will compile your javascript to raw heavily minified code with semantic features. otherwise yes, use it as you please, PhoneGap included.

When you build something with Closure, you can render the DOM in JavaScript. It is super fast and much much better than the conventional way.

so you create your pages with goog.dom.createDom. Below you will find an example.

var menuButton = goog.dom.createDom('a', {
    'class': 'menu‑button',
    'otherAttributes': 'otherValues etc'
}, myproject.translations.menuButton.currentLanguage);

//Now you have a file like this:
goog.provide('myproject.translations');

// Language variations corresponding to that element.
myproject.translations.menuButton = {
    'EN': 'go',
    'FR': 'aller',
    'DE': 'gehen'//etc...

};

Do the above wherever translations are needed. Then simply set the current language on load with something very easy like.

myproject.boot = function(parameters) {
    myproject.translations.currentLanguage = parameters['currentLanguage'];
};
goog.exportSymbol('myproject.boot', myproject.boot);

and then call the boot method inside the index.php or whatever on window.load and echo a JSON string with the boot parameters from the server. Beware, everything that comes from the server must be encapsulated within quotes when referenced. Otherwise the compiler will flatten the property name in ADVANCED_OPTIMIZATIONS mode.

(by shailbenqflavian)

參考文件

  1. Using Closure Library on Phonegap(Android) application (CC BY‑SA 3.0/4.0)

#internationalization #javascript #Android #cordova #google-closure-library






相關問題

志願者翻譯對 Delphi 2009 應用程序進行本地化的過程? (Process for localization of Delphi 2009 app by volunteer translators?)

Netbeans 菜單和 i18n (Netbeans menu and i18n)

Menggunakan Perpustakaan Penutupan pada aplikasi Phonegap (Android) (Using Closure Library on Phonegap(Android) application)

支持 SDK 但不支持 PhoneGap 的印度語語言 (Indic Language Support for SDK but not PhoneGap)

翻譯 symfony2 路由錯誤 (translation symfony2 routing error)

Django 沒有正確翻譯網站 (Django not translating the site properly)

django模型翻譯404 (django modeltranslation 404)

您是否知道用於編輯/翻譯資源(.rc)文件的好的程序? (Do you know of a good program for editing/translating resource (.rc) files?)

Struts 2 動作調用丟失 xwork i18n 語言設置 (Struts 2 action call loses the xwork i18n language setting)

移動應用測試 (Mobile application testing)

nuxt-i18n 的延遲加載語言環境 (Lazy load locales for nuxt-i18n)

你能在 next.config 中獲取數據嗎 (Can you fetch data in next.config)







留言討論