Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 721
shailbenq Avatar asked Nov 06 '12 22:11

shailbenq


People also ask

Why use Google Closure compiler?

The Closure Compiler reduces the size of your JavaScript files and makes them more efficient, helping your application to load faster and reducing your bandwidth needs.

What is closure Google what is closure in JavaScript?

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript.


1 Answers

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.

like image 187
flavian Avatar answered Oct 22 '22 09:10

flavian