Permalink
Browse files

Page creation

  • Loading branch information...
1 parent 9990923 commit 1ac82ebf60a251c6e24048af9fc480ab06182c0a @Belelros committed Apr 20, 2012
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
View
@@ -1,136 +0,0 @@
-/*
- Name: jqueryTranslator
- Author: Antonio Laguna
- Twitter: @Belelros
- Website: http://www.funcion13.com
- Version: 1.0
-*/
-(function($, window, document, undefined){
- var Translate = {
- initialize : function(pkg, options){
- var self = this, userLanguage = self.getUserLanguage();
- self.loaded = $.Deferred();
-
- self.translatable = true;
-
- self.options = $.extend({}, $.fn.jqTranslate.options, options);
-
- if (typeof pkg === 'string')
- self.packages.push(pkg);
- else
- self.packages = pkg;
-
- if (self.isTranslatable(userLanguage))
- self.loadLanguages();
- else
- self.translatable = false;
-
- return self.loaded.promise();
- },
- getUserLanguage : function(){
- var userLang = navigator.language || navigator.userLanguage;
- userLang = userLang.replace(/_/, '-').toLowerCase();
-
- if (userLang.length > 3){
- userLang = userLang.substring(0,3) + userLang.substring(3).toUpperCase();
- this.languages = [
- userLang.substring(0,2),
- userLang.substring(3).toUpperCase()
- ];
- }
- else
- this.languages = [
- userLang
- ];
-
- $.fn.jqTranslate.userLang = userLang;
- return userLang;
- },
- isTranslatable : function(language){
- if (this.options.defaultLang === language) return false;
- else return (this.options.skip.indexOf(language) === -1);
- },
- loadLanguages : function(){
- var loaded = 0, maxLoad = Translate.languages.length * Translate.packages.length;
- this.translatedStrings = {};
-
- $.each(Translate.packages,function(i, pkg){
- var ePkg = pkg;
-
- $.each(Translate.languages, function (i, lang){
- Translate.getLanguage(ePkg,lang)
- .done(Translate.storeLangFile)
- .always(function(){
- loaded++;
- if (loaded >= maxLoad) Translate.loaded.resolve();
- });
- });
- });
- },
- getLanguage : function(pkg, language){
- var self = this, url = '';
- if (self.options.path){
- url = self.options.path + '/';
- }
- url += [pkg, language].join('-') + '.json';
-
- return $.ajax ({
- url : url,
- dataType : "json",
- cache : self.options.cache
- });
- },
- storeLangFile : function(data){
- $.extend(Translate.translatedStrings, data);
- },
- translate : function() {
- var elem = $(this), key = elem.data('translate');
- if (Translate.translatable){
- if (Translate.translatedStrings[key]){
- if (Translate.translatedStrings[key].length === undefined){
- // The key have nested keys
- Translate.translateElement(elem,Translate.translatedStrings[key].text);
- delete Translate.translatedStrings[key].text;
- elem.attr(Translate.translatedStrings[key])
- }
- else
- Translate.translateElement(elem,Translate.translatedStrings[key]);
- }
- }
- if (typeof Translate.options.onComplete === 'function')
- Translate.options.onComplete.apply(this, arguments);
- return elem;
- },
- translateElement : function (elem, value){
- if (elem.is('input')) {
- if (elem.is('[placeholder]'))
- elem.attr('placeholder', value);
- else
- elem.val(value);
- }
- else if (elem.is('optgroup')){
- elem.attr('label', value);
- }
- else if (elem.is('img')) {
- elem.attr('alt',value);
- }
- else {
- elem.html(value);
- }
- }
- };
-
- $.fn.jqTranslate = function(pkg, options){
- var self = this;
- Translate.initialize(pkg, options).done(function(){
- return self.each(Translate.translate);
- });
- };
- $.fn.jqTranslate.options = {
- path : null,
- defaultLang : null,
- skip : [],
- cache : true,
- onComplete : null
- };
-})(jQuery, window, document);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
File renamed without changes.
File renamed without changes.
View
149 readme.md
@@ -1,149 +0,0 @@
-#jqueryTranslator
-
-jqueryTranslator is a jQuery plugin which allows developers to translate a static web site easily.
-
-1. It first loads asynchronously the translation files you supply to the plugin. It can be a string or an array of them.
-
-1. Then, it translates the element based on the user's browser language. The plugin is able to translate the text of the element or change attributes, or even both!
-
-1. Finally, if you supply a callback, it will be executed over every element to be translated.
-
-## Usage & Documentation
-
-Just include one of the plugin files in your file.
-
-### Use the "data-translate" attribute on DOM elements you want to be translated
-
-```html
- <h1 data-translate="hello"> Hello! </h1>
- <img data-translate="img" alt="This is an image!" src="someimage.jpg" />
-```
-
-The "hello" and "img" words serve as sort of key so it's easier to locate the translation.
-
-### Create a JSON language file with the translations:
-
-index-es.json:
-
-```javascript
- {
- "hello": "Hola!"
- "img" : "Esto es una imagen!"
- }
-```
-
-### Call the plugin!
-
- $("[data-translate]").jqTranslate('index');
-
-## In-depth explanation and Documentation
-
-The first argument the plugin receives, is the package that it has to load. You may have different packs for different parts of the website (header, dialogs, etc);
-
-You can load more than one package like this:
-
-```javascript
- $("[data-translate]").jqTranslate(['index', 'header', 'footer']);
-```
-
-If the language of the user's browser is "es", the plugin will try to load:
-
-* index-es.json
-* header-es.json
-* footer-es.json
-
-If the language also has a country code, like "es-MX", the plugin will ALSO try to load the following:
-
-* index-es-MX.json
-* header-es-MX.json
-* footer-es-MX.json
-
-This can provide you more customization for different regions. Unfortunately, most of current browsers (desktop) only have the language portion though mobile ones use to have both.
-
-### Options
-
-An object containing parameters. Please, note that all parameters are optional.
-
-> **path** (*string*): This is the default path of the translation files. Useful if you want to locate your files in a separated folder. **Default**: *null*
-
-> **defaultLang** (*string*): The default language of the Application, this language won't be loaded. **Default**: *null*
-
-> **skip** (*array of strings*): An array containing all the languages you want to avoid the translation. **Default**: *empty array*
-
-> **cache** (*boolean*): Whether if the language packages should be cached or not. **Default**: *true*
-
-> **onComplete** (*function*): Callback function triggered when a DOM element has been translated. *this* will point to the element.**Default**: *null*
-
-### Advanced
-
-Here are some advanced tricks you can use and some extra info.
-
-First, let's see how the plugin reacts to the elements:
-
-> **input** : It first checks if it's a **placeholder** and, if it is, it translates it. If it doesn't it will change the input value to one supplied.
-
-> **optgroup** : Get their **label** attribute translated
-
-> **img** : Get their **alt** attribute translated
-
-> *default* : Get their HTML replaced.
-
-#### Changing multiple attributes for each element
-
-If the key for a given value contains nested values, it will try change them all. Please, have in mind that **you** are responsible of supplying the correct attributes. For example:
-
-index-es.json:
-
-```javascript
- {
- "hello": "Hola!"
- "img" : {
- "text" : "Esto es una imagen!",
- "src" : "linktootherimage.jpg"
- }
- }
-```
-
-The *text* attribute will replace the normal behaviour and will follow the aforementioned rules to translate the element. The remaining attributes will be directly changed on the element.
-
-## FAQ
-
-### How can I translate my jQuery Mobile application?
-
-#### Using jQuery Mobile 1.1 and further
-
-```javascript
-$(document).on('pagecreate','#home',function(event){
- $("[data-translate]").jqTranslate('index');
-});
-```
-#### Pre jQM 1.1
-
-```javascript
-$('#home').live('pagecreate',function(event){
- $("[data-translate]").jqTranslate('index');
-});
-```
-
-Where #home is the ID of the page.
-
-### My page isn't being translated!
-
-The most common cause of this, is because the JSON package isn't valid. To check it, please use some kind of validation service such as JSONLint.
-
-## Contributing
-
-You are invited to contribute code and make suggestions to this project. If you're interested in contributing, please fork the repository, make your changes, and send a pull-request.
-
-Learn more about [how to fork](http://help.github.com/fork-a-repo/) and
-[pull-requests](http://help.github.com/pull-requests/).
-
-## Credits & Licensing
-
-Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
-
-Written by Antonio Laguna (@Belelros)
-Please use it, and contribute changes.
-
-Based on Jim Garvin's Localisation jQuery plugin.
-https://github.com/coderifous/jquery-localize

0 comments on commit 1ac82eb

Please sign in to comment.