Skip to content

Commit a5e7d43

Browse files
committed
added documentation and fix typos
1 parent d238d72 commit a5e7d43

File tree

5 files changed

+198
-133
lines changed

5 files changed

+198
-133
lines changed

.travis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
language: node_js
2-
node_js: "0.10"
3-
before_script:
4-
- npm install -g grunt-cli
5-
script: "grunt jshint"
2+
node_js: '0.10'
3+
before_script:
4+
- npm install -g grunt-cli
5+
script: grunt travis
6+
env:
7+
global:
8+
- secure: DO5E2w6hfCCrh8dm7hwQfePiOXnHFnyDXg6IyZCCrkIuleLYAFP7B/atlgFPyPSmMEu42JynWN6nrGGZv4s9br2IZR7kIPA5clnU2SAYwTbLdARNE8WIo5bWQcROX90MyvxaZV3C3/THdLF8eB3LTD3GEXiOePYQcuAHMAQvPfk=
9+
- secure: cAQhsHCidIkL/ClxUOMGSNggytB0ugpjC8rlrQOu/fMp7he/BI/TqlgF78lA1Kzh55XXSOA8Sm25gb0r3wvzp2YZ1hx6U3qRrrHPymLvrD2pciVeXqd13tGWUhi+//uv1slL8pctneEkwqY+H31Wp5XPZkyY+kJbaJRxfHCrcek=

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# requirejs-dplugins
22

3-
AMD plugins for RequireJS.
3+
Set of AMD plugins for RequireJS. It contains the following plugins:
4+
5+
* [i18n](#i18n)
6+
* [maybe](#maybe)
47

58
## Status
69

@@ -16,17 +19,74 @@ All contributions require a [Dojo Foundation CLA](http://dojofoundation.org/abou
1619
## Dependencies
1720

1821
This project requires the following other project to run:
19-
* requirejs
22+
23+
* requirejs
2024

2125
## Installation
2226

2327
* Bower release installation: `bower install requirejs-dplugins`
2428

2529
* Manual master installation: go to the root Dojo installation directory and clone requirejs-dplugins from github:
2630

27-
$ git clone git://github.com/ibm-js/requirejs-dplugins.git
31+
`$ git clone git://github.com/ibm-js/requirejs-dplugins.git`
2832

2933
## Documentation
34+
### i18n
35+
This plugin is based on requirejs i18n but modified to support nls built layer.
36+
37+
#### When the application IS NOT optimized
38+
If an application is not built, this plugin will behave exactly like the i18n plugin from RequireJS.
39+
The appropriate documentation can be found on [RequireJS website](http://requirejs.org/docs/api.html#i18n).
40+
41+
#### When the application IS optimized
42+
Once the application is built, the plugin offer three new options:
43+
44+
```
45+
requirejs.config({
46+
config: {
47+
i18n: {
48+
layerOnly: bool, //default: false
49+
languagePack: bool, //default: false
50+
enhanceLayer: bool, //default: true
51+
}
52+
}
53+
54+
});
55+
```
56+
* `layerOnly` (default: false)
57+
58+
If `layerOnly = true`, the plugin is only looking for nls bundles in built nls layers. `layerOnly` must be true if only the built nls layers are deployed with the application.
59+
If the individual nls bundles are also deployed, `layerOnly` should be false.
60+
61+
* `languagePack` (default: false)
62+
63+
If true, this option give the possibility to add new locales to the application just by adding the corresponding built nls layer. However, this will result in more http requests (and some expected 404 in the console), so it should only be used in low latency environments (like cordova applications).
64+
* `enhanceLayer` (default: true)
65+
66+
This option is NOT used if `layerOnly = true`.
67+
68+
This option define the behaviour of the plugin when a bundle is retrieved from a layer with a less specific locale than requested (ie: bundle `en` from layer when `en-us` was requested).
69+
70+
* If `enhanceLayer = false`, the plugin only use the bundle from the layer. This is useful when a part of the application is an already built package distributed without the individual nls bundles.
71+
72+
* If `enhanceLayer = true`, the plugin will try to load a more specific individual bundle if one exist.
73+
74+
75+
76+
### maybe
77+
This plugin allows to require modules that may or may not exist. If the module is not found it will be `undefined`.
78+
79+
80+
#### Sample usage
81+
```
82+
require(["maybe!a/module/id"], function(module){
83+
if (module === undefined) {
84+
//do something when module IS NOT found
85+
} else {
86+
//do something else 2when module IS found
87+
}
88+
});
89+
```
3090

3191

3292
## Credits

i18n.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ define(['./i18n/common', "module"], function (common, module) {
160160
masterMid,
161161
layer;
162162

163+
moduleConfig.enhanceLayer = moduleConfig.enhanceLayer === undefined ? true : moduleConfig.enhanceLayer;
164+
163165
// Parse name and set the locale if a top level bundle is required
164166
name = parseName(name);
165-
name.requestedLocale = name.requestedLocale || common.getLocale(config);
167+
name.requestedLocale = name.requestedLocale || common.getLocale(moduleConfig.locale || config.locale);
166168
masterMid = getMasterMid(name);
167169

168170
// If there is no layer, classic AMD mode

i18n/common.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ define(["../maybe!./parentLocale"], function (parentLocale) {
22
parentLocale = parentLocale || {};
33

44
return {
5-
getLocale: function (config) {
6-
var locale = config.locale;
5+
getLocale: function (locale) {
76
if (!locale) {
87
locale = typeof navigator === "undefined" ? "root" :
98
(navigator.language ||

i18n/parentLocale.js

Lines changed: 123 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,125 @@
11
define({
2-
"en-AG": "en-001",
3-
"en-AI": "en-001",
4-
"en-BB": "en-001",
5-
"en-BM": "en-001",
6-
"en-BS": "en-001",
7-
"en-BW": "en-001",
8-
"en-BZ": "en-001",
9-
"en-CC": "en-001",
10-
"en-CK": "en-001",
11-
"en-CM": "en-001",
12-
"en-CX": "en-001",
13-
"en-DM": "en-001",
14-
"en-ER": "en-001",
15-
"en-FJ": "en-001",
16-
"en-FM": "en-001",
17-
"en-GB": "en-001",
18-
"en-GD": "en-001",
19-
"en-GH": "en-001",
20-
"en-GM": "en-001",
21-
"en-GY": "en-001",
22-
"en-JM": "en-001",
23-
"en-KE": "en-001",
24-
"en-KI": "en-001",
25-
"en-KN": "en-001",
26-
"en-KY": "en-001",
27-
"en-LC": "en-001",
28-
"en-LR": "en-001",
29-
"en-LS": "en-001",
30-
"en-MG": "en-001",
31-
"en-MS": "en-001",
32-
"en-MU": "en-001",
33-
"en-MW": "en-001",
34-
"en-NA": "en-001",
35-
"en-NF": "en-001",
36-
"en-NG": "en-001",
37-
"en-NR": "en-001",
38-
"en-NU": "en-001",
39-
"en-PG": "en-001",
40-
"en-PH": "en-001",
41-
"en-PN": "en-001",
42-
"en-PW": "en-001",
43-
"en-RW": "en-001",
44-
"en-SB": "en-001",
45-
"en-SC": "en-001",
46-
"en-SD": "en-001",
47-
"en-SL": "en-001",
48-
"en-SS": "en-001",
49-
"en-SX": "en-001",
50-
"en-SZ": "en-001",
51-
"en-TC": "en-001",
52-
"en-TK": "en-001",
53-
"en-TO": "en-001",
54-
"en-TT": "en-001",
55-
"en-TV": "en-001",
56-
"en-TZ": "en-001",
57-
"en-UG": "en-001",
58-
"en-VC": "en-001",
59-
"en-VU": "en-001",
60-
"en-WS": "en-001",
61-
"en-ZA": "en-001",
62-
"en-ZM": "en-001",
63-
"en-ZW": "en-001",
64-
"en-150": "en-GB",
65-
"en-AU": "en-GB",
66-
"en-BE": "en-GB",
67-
"en-DG": "en-GB",
68-
"en-FK": "en-GB",
69-
"en-GG": "en-GB",
70-
"en-GI": "en-GB",
71-
"en-HK": "en-GB",
72-
"en-IE": "en-GB",
73-
"en-IM": "en-GB",
74-
"en-IN": "en-GB",
75-
"en-IO": "en-GB",
76-
"en-JE": "en-GB",
77-
"en-MO": "en-GB",
78-
"en-MT": "en-GB",
79-
"en-NZ": "en-GB",
80-
"en-PK": "en-GB",
81-
"en-SG": "en-GB",
82-
"en-SH": "en-GB",
83-
"en-VG": "en-GB",
84-
"es-AR": "es-419",
85-
"es-BO": "es-419",
86-
"es-CL": "es-419",
87-
"es-CO": "es-419",
88-
"es-CR": "es-419",
89-
"es-CU": "es-419",
90-
"es-DO": "es-419",
91-
"es-EC": "es-419",
92-
"es-GT": "es-419",
93-
"es-HN": "es-419",
94-
"es-MX": "es-419",
95-
"es-NI": "es-419",
96-
"es-PA": "es-419",
97-
"es-PE": "es-419",
98-
"es-PR": "es-419",
99-
"es-PY": "es-419",
100-
"es-SV": "es-419",
101-
"es-US": "es-419",
102-
"es-UY": "es-419",
103-
"es-VE": "es-419",
104-
"pt-AO": "pt-PT",
105-
"pt-CV": "pt-PT",
106-
"pt-GW": "pt-PT",
107-
"pt-MO": "pt-PT",
108-
"pt-MZ": "pt-PT",
109-
"pt-ST": "pt-PT",
110-
"pt-TL": "pt-PT",
111-
"az-Cyrl": "root",
112-
"bs-Cyrl": "root",
113-
"en-Dsrt": "root",
114-
"ha-Arab": "root",
115-
"mn-Mong": "root",
116-
"ms-Arab": "root",
117-
"pa-Arab": "root",
118-
"shi-Latn": "root",
119-
"sr-Latn": "root",
120-
"uz-Arab": "root",
121-
"uz-Cyrl": "root",
122-
"vai-Latn": "root",
123-
"zh-Hant": "root",
124-
"zh-Hant-MO": "zh-Hant-HK"
2+
"en-ag": "en-001",
3+
"en-ai": "en-001",
4+
"en-bb": "en-001",
5+
"en-bm": "en-001",
6+
"en-bs": "en-001",
7+
"en-bw": "en-001",
8+
"en-bz": "en-001",
9+
"en-cc": "en-001",
10+
"en-ck": "en-001",
11+
"en-cm": "en-001",
12+
"en-cx": "en-001",
13+
"en-dm": "en-001",
14+
"en-er": "en-001",
15+
"en-fj": "en-001",
16+
"en-fm": "en-001",
17+
"en-gb": "en-001",
18+
"en-gd": "en-001",
19+
"en-gh": "en-001",
20+
"en-gm": "en-001",
21+
"en-gy": "en-001",
22+
"en-jm": "en-001",
23+
"en-ke": "en-001",
24+
"en-ki": "en-001",
25+
"en-kn": "en-001",
26+
"en-ky": "en-001",
27+
"en-lc": "en-001",
28+
"en-lr": "en-001",
29+
"en-ls": "en-001",
30+
"en-mg": "en-001",
31+
"en-ms": "en-001",
32+
"en-mu": "en-001",
33+
"en-mw": "en-001",
34+
"en-na": "en-001",
35+
"en-nf": "en-001",
36+
"en-ng": "en-001",
37+
"en-nr": "en-001",
38+
"en-nu": "en-001",
39+
"en-pg": "en-001",
40+
"en-ph": "en-001",
41+
"en-pn": "en-001",
42+
"en-pw": "en-001",
43+
"en-rw": "en-001",
44+
"en-sb": "en-001",
45+
"en-sc": "en-001",
46+
"en-sd": "en-001",
47+
"en-sl": "en-001",
48+
"en-ss": "en-001",
49+
"en-sx": "en-001",
50+
"en-sz": "en-001",
51+
"en-tc": "en-001",
52+
"en-tk": "en-001",
53+
"en-to": "en-001",
54+
"en-tt": "en-001",
55+
"en-tv": "en-001",
56+
"en-tz": "en-001",
57+
"en-ug": "en-001",
58+
"en-vc": "en-001",
59+
"en-vu": "en-001",
60+
"en-ws": "en-001",
61+
"en-za": "en-001",
62+
"en-zm": "en-001",
63+
"en-zw": "en-001",
64+
"en-150": "en-gb",
65+
"en-au": "en-gb",
66+
"en-be": "en-gb",
67+
"en-dg": "en-gb",
68+
"en-fk": "en-gb",
69+
"en-gg": "en-gb",
70+
"en-gi": "en-gb",
71+
"en-hk": "en-gb",
72+
"en-ie": "en-gb",
73+
"en-im": "en-gb",
74+
"en-in": "en-gb",
75+
"en-io": "en-gb",
76+
"en-je": "en-gb",
77+
"en-mo": "en-gb",
78+
"en-mt": "en-gb",
79+
"en-nz": "en-gb",
80+
"en-pk": "en-gb",
81+
"en-sg": "en-gb",
82+
"en-sh": "en-gb",
83+
"en-vg": "en-gb",
84+
"es-ar": "es-419",
85+
"es-bo": "es-419",
86+
"es-cl": "es-419",
87+
"es-co": "es-419",
88+
"es-cr": "es-419",
89+
"es-cu": "es-419",
90+
"es-do": "es-419",
91+
"es-ec": "es-419",
92+
"es-gt": "es-419",
93+
"es-hn": "es-419",
94+
"es-mx": "es-419",
95+
"es-ni": "es-419",
96+
"es-pa": "es-419",
97+
"es-pe": "es-419",
98+
"es-pr": "es-419",
99+
"es-py": "es-419",
100+
"es-sv": "es-419",
101+
"es-us": "es-419",
102+
"es-uy": "es-419",
103+
"es-ve": "es-419",
104+
"pt-ao": "pt-pt",
105+
"pt-cv": "pt-pt",
106+
"pt-gw": "pt-pt",
107+
"pt-mo": "pt-pt",
108+
"pt-mz": "pt-pt",
109+
"pt-st": "pt-pt",
110+
"pt-tl": "pt-pt",
111+
"az-cyrl": "root",
112+
"bs-cyrl": "root",
113+
"en-dsrt": "root",
114+
"ha-arab": "root",
115+
"mn-mong": "root",
116+
"ms-arab": "root",
117+
"pa-arab": "root",
118+
"shi-latn": "root",
119+
"sr-latn": "root",
120+
"uz-arab": "root",
121+
"uz-cyrl": "root",
122+
"vai-latn": "root",
123+
"zh-hant": "root",
124+
"zh-hant-mo": "zh-hant-hk"
125125
});

0 commit comments

Comments
 (0)