Skip to content

Commit 950a66c

Browse files
committed
Merge remote-tracking branch 'jgolla/master'
2 parents c0781b4 + 0dc44ca commit 950a66c

35 files changed

+12933
-2041
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
test/localize_test.js
2-
test/qunit_setup.js
3-
1+
/node_modules/

.jshintrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"unused": true,
11+
"boss": true,
12+
"eqnull": true,
13+
"node": true
14+
}

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "0.11"
4+
before_script:
5+
- npm install -g grunt-cli

CONTRIBUTING.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Contributing
2+
3+
## Important notes
4+
Please don't edit files in the `dist` subdirectory as they are generated via Grunt. You'll find source code in the `src` subdirectory!
5+
6+
### Code style
7+
Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.**
8+
9+
### PhantomJS
10+
While Grunt can run the included unit tests via [PhantomJS](http://phantomjs.org/), this shouldn't be considered a substitute for the real thing. Please be sure to test the `test/*.html` unit test file(s) in _actual_ browsers.
11+
12+
## Modifying the code
13+
First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
14+
15+
Test that Grunt's CLI is installed by running `grunt --version`. If the command isn't found, run `npm install -g grunt-cli`. For more information about installing Grunt, see the [getting started guide](http://gruntjs.com/getting-started).
16+
17+
1. Fork and clone the repo.
18+
1. Run `npm install` to install all dependencies (including Grunt).
19+
1. Run `grunt` to grunt this project.
20+
21+
Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing is broken.
22+
23+
## Submitting pull requests
24+
25+
1. Create a new branch, please don't work in your `master` branch directly.
26+
1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
27+
1. Fix stuff.
28+
1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
29+
1. Open `test/*.html` unit test file(s) in actual browser to ensure tests pass everywhere.
30+
1. Update the documentation to reflect any changes.
31+
1. Push to your fork and submit a pull request.

Gruntfile.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict';
2+
3+
module.exports = function(grunt) {
4+
5+
// Project configuration.
6+
grunt.initConfig({
7+
// Metadata.
8+
pkg: grunt.file.readJSON('localize.jquery.json'),
9+
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
10+
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
11+
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
12+
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
13+
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
14+
// Task configuration.
15+
clean: {
16+
files: ['dist']
17+
},
18+
coffee: {
19+
compile: {
20+
files: {
21+
'dist/<%= pkg.name %>.js' : 'src/*.coffee',
22+
'test/localize_test.js' : 'test/localize_test.coffee',
23+
'test/qunit_setup.js' : 'test/qunit_setup.coffee'
24+
}
25+
}
26+
},
27+
uglify: {
28+
options: {
29+
banner: '<%= banner %>'
30+
},
31+
dist: {
32+
src: 'dist/<%= pkg.name %>.js',
33+
dest: 'dist/<%= pkg.name %>.min.js'
34+
},
35+
},
36+
qunit: {
37+
all: {
38+
options: {
39+
urls: ['1.7.2', '1.8.3', '1.9.1', '1.10.2', '1.11.0', '2.0.3', '2.1.0'].map(function(version) {
40+
return 'http://localhost:<%= connect.server.options.port %>/test/localize.html?jquery=' + version;
41+
})
42+
}
43+
}
44+
},
45+
connect: {
46+
server: {
47+
options: {
48+
port: 8085 // This is a random port, feel free to change it.
49+
}
50+
}
51+
},
52+
});
53+
54+
// These plugins provide necessary tasks.
55+
grunt.loadNpmTasks('grunt-contrib-clean');
56+
grunt.loadNpmTasks('grunt-contrib-uglify');
57+
grunt.loadNpmTasks('grunt-contrib-qunit');
58+
grunt.loadNpmTasks('grunt-contrib-coffee');
59+
grunt.loadNpmTasks('grunt-contrib-connect');
60+
61+
// Default task.
62+
grunt.registerTask('default', ['connect', 'clean', 'coffee', 'uglify', 'qunit']);
63+
grunt.registerTask('test', ['connect', 'qunit']);
64+
};

LICENSE-MIT

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 jgolla
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
+75-47
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,68 @@
11
# jquery.localize.js
22

3-
## a jQuery plugin that makes it easy to i18n your static web site.
3+
[![Build Status](https://travis-ci.org/jgolla/jquery-localize.png?branch=master)](https://travis-ci.org/jgolla/jquery-localize)
44

5-
## Synopsis
5+
A jQuery plugin that makes it easy to i18n your static web site.
66

7+
## Synopsis
78
* Lazily loads JSON translation files based on a simple naming convention.
89
* By default, applies the translations to your document based on simple attribute convention.
9-
* Tested with jQuery versions 1.7.2, 1.8.3, 1.9.1, 1.10.2, and 2.0.3
10+
* Tested with jQuery versions 1.7.2, 1.8.3, 1.9.1, 1.10.2, 1.11.0, 2.0.3, 2.1.0
11+
12+
## Getting Started
13+
Download the [production version][min] or the [development version][max].
1014

11-
## Basic Usage
15+
[min]: https://raw.github.com/jgolla/jquery-localize/master/dist/jquery.localize.min.js
16+
[max]: https://raw.github.com/jgolla/jquery-localize/master/dist/jquery.localize.js
1217

13-
## Step 0. Load the jquery-localize plugin on your page.
18+
### Load the jquery-localize plugin on your page.
1419

15-
It's the file located at `build/jquery.localize.js`
20+
It's the file located at `dist/jquery.localize.js`
1621

17-
## Step 1. Mark up tags whose content you want to be translated
22+
### Mark up tags whose content you want to be translated
1823

1924
Somewhere in your html:
2025

21-
<h1 data-localize="greeting"> Hello! </h1>
26+
```html
27+
<h1 data-localize="greeting"> Hello! </h1>
28+
```
2229

23-
## Step 2. Provide a JSON language file that has translations:
30+
### Provide a JSON language file that has translations:
2431

2532
example-fr.json:
2633

2734
{
2835
"greeting": "Bonjour!"
2936
}
3037

31-
## Step 3. Use the localize plugin.
38+
### Use the localize plugin.
3239

33-
// In a browser where the language is set to French
34-
$("[data-localize]").localize("example")
40+
```html
41+
<script>
42+
// In a browser where the language is set to French
43+
$("[data-localize]").localize("example")
3544
36-
// You can also override the language detection, and pass in a language code
37-
$("[data-localize]").localize("example", { language: "fr" })
45+
// You can also override the language detection, and pass in a language code
46+
$("[data-localize]").localize("example", { language: "fr" })
47+
</script>
48+
```
3849

39-
# Gory Details
50+
## Gory Details
4051

41-
## Language file loading
52+
### Language file loading
4253

4354
The first argument of the localize method is the name of the language pack. You might have a different language pack for different parts of your website.
4455

4556
Here's an example of loading several language packs:
4657

47-
$("[data-localize]")
48-
.localize("header")
49-
.localize("sidebar")
50-
.localize("footer")
51-
58+
```html
59+
<script>
60+
$("[data-localize]")
61+
.localize("header")
62+
.localize("sidebar")
63+
.localize("footer")
64+
</script>
65+
```
5266

5367
If the language of the browser were set to "fr", then the plugin would try to load:
5468

@@ -64,38 +78,44 @@ if the language of the browser also had a country code, like "fr-FR", then the p
6478

6579
This let's you define partial language refinements for different regions. For instance, you can have the base language translation file for a language that translates 100 different phrases, and for countries were maybe a some of those phrases would be out of place, you can just provide a country-specific file with _just those special phrases_ defined.
6680

67-
## Skipping Languages (aka Optimizing for My Language)
81+
### Skipping Languages (aka Optimizing for My Language)
6882

6983
This is useful if you've got a default language. For example, if all of your content is served in english, then you probably don't want the overhead of loading up unecessary (and probably non-existant) english langauge packs (foo-en.json)
7084

7185
You can tell the localize plugin to always skip certain languages using the skipLanguage option:
7286

73-
# using a string will skip ONLY if the language code matches exactly
74-
# this would prevent loading only if the language was "en-US"
75-
$("[data-localize]").localize("example", { skipLanguage: "en-US" })
87+
```html
88+
<script>
89+
//using a string will skip ONLY if the language code matches exactly
90+
//this would prevent loading only if the language was "en-US"
91+
$("[data-localize]").localize("example", { skipLanguage: "en-US" })
7692
77-
# using a regex will skip if the regex matches
78-
# this would prevent loading of any english language translations
79-
$("[data-localize]").localize("example", { skipLanguage: /^en/ })
93+
//using a regex will skip if the regex matches
94+
//this would prevent loading of any english language translations
95+
$("[data-localize]").localize("example", { skipLanguage: /^en/ })
8096
81-
# using an array of strings will skip if any of the strings matches exactly
82-
$("[data-localize]").localize("example", { skipLanguage: ["en", "en-US"] })
97+
//using an array of strings will skip if any of the strings matches exactly
98+
$("[data-localize]").localize("example", { skipLanguage: ["en", "en-US"] })
99+
</script>
100+
```
83101

84-
## Applying the language file
102+
### Applying the language file
85103

86104
If you rely on the default callback and use the "data-localize" attribute then the changes will be applied for you.
87105

88-
## Examples:
106+
### Examples:
89107

90108
**HTML:**
91109

92-
<p data-localize="title">Tracker Pro XT Deluxe</p>
93-
<p data-localize="search.placeholder">Search...</p>
94-
<p data-localize="search.button">Go!</p>
95-
<p data-localize="footer.disclaimer">Use at your own risk.</p>
96-
<p data-localize="menu.dashboard">Dashboard</p>
97-
<p data-localize="menu.list">Bug List</p>
98-
<p data-localize="menu.logout">Logout</p>
110+
```html
111+
<p data-localize="title">Tracker Pro XT Deluxe</p>
112+
<p data-localize="search.placeholder">Search...</p>
113+
<p data-localize="search.button">Go!</p>
114+
<p data-localize="footer.disclaimer">Use at your own risk.</p>
115+
<p data-localize="menu.dashboard">Dashboard</p>
116+
<p data-localize="menu.list">Bug List</p>
117+
<p data-localize="menu.logout">Logout</p>
118+
```
99119

100120
**application-es.json (fake spanish)**
101121

@@ -117,19 +137,27 @@ If you rely on the default callback and use the "data-localize" attribute then t
117137

118138
**Localize it!**
119139

120-
$("[data-localize]").localize("application", { language: "es" })
140+
```html
141+
<script>
142+
$("[data-localize]").localize("application", { language: "es" });
143+
</script>
144+
```
121145

122-
## Callbacks
146+
### Callbacks
123147

124148
You can provide a callback if you want to augment or replace the default callback provided by the plugin. Your callback should take at least 1 argument: the language data (contents of your json file). It can optionally accept a second argument, which is a reference to the default callback function. This is handy if you still want the default behavior, but also need to do something else with the language data.
125149

126-
$("[data-localize]").localize("application", {
127-
language: "es",
128-
callback: function(data, defaultCallback){
150+
```html
151+
<script>
152+
$("[data-localize]").localize("application", {
153+
language: "es",
154+
callback: function(data, defaultCallback){
129155
data.title = data.title + currentBugName();
130156
defaultCallback(data)
131-
}
132-
})
157+
}
158+
});
159+
</script>
160+
```
133161

134162
See the test/samples for working examples.
135163

@@ -162,4 +190,4 @@ Please use it, and contribute changes.
162190
http://github.com/coderifous/jquery-localize
163191

164192
Based off of Keith Wood's Localisation jQuery plugin.
165-
http://keith-wood.name/localisation.html
193+
http://keith-wood.name/localisation.html

build/README

-7
This file was deleted.

0 commit comments

Comments
 (0)