Permalink
Browse files

Updated README with examples of how to use node-localize in the brows…

…er, using the new Localize.source property, and therefore bumping the revision again.
  • Loading branch information...
David Ellis
David Ellis committed Feb 10, 2012
1 parent 14bdc35 commit 162166164227fcf8c602ccdbbf72c11a724dd9ba
Showing with 26 additions and 1 deletion.
  1. +25 −0 README.md
  2. +1 −1 package.json
View
@@ -110,6 +110,12 @@ myLocalize.loadTranslations(translationsObjOrStr);
// object in memory (overwriting duplicate keys).
```
+```js
+myLocalize.getTranslations(translationsArrOrUndef);
+// translationsArrOrUndef: an array of untranslated text whose translations you want
+// to acquire, or leave it undefined for the entire internal translations object
+```
+
```js
myLocalize.clearTranslations();
// Wipes out the translations object entirely (if a clean reload is desired)
@@ -138,6 +144,11 @@ myLocalize.loadDateFormats(dateFormatObj);
// loadTranslations.
```
+```js
+myLocalize.getDateFormats();
+// Returns the internal date formats object.
+```
+
```js
myLocalize.clearDateFormats();
// Resets the date formats object to just the 'en' locale.
@@ -236,6 +247,20 @@ Your controllers shouldn't really even be aware of any localization issues; the
I'm using [jQuery Templates for Express](https://github.com/kof/node-jqtpl) here, but it should be easy to translate to whatever templating language you prefer.
+### Easy exporting of *node-localize* library to client without copying library into own source
+
+Since node-localize can also run inside of the browser, and so can jQuery Templates, it can be quite useful to be able to export the library to the client. But rather than manually copying the library code into your website (and keeping track of updates/bugfixes manually), you can get the source code of node-localize directly from the library and add an Express route for it:
+
+```js
+app.get('/js/localize.js', function(req, res) {
+ res.send(Localize.source);
+});
+```
+
+Where ``Localize`` is equivalent to ``require('localize')``, not an instantiated localize object.
+
+If you're using node-localize on the client in this fashion, it would be wise to add ``getTranslations`` and ``getDateFormats`` to the ``app.helpers`` object, so views can specify which translations and date formatting they need the client to have to function properly.
+
## Planned Features
* Browser compatibility (use same functions for client-side jQuery Templates, for instance)
View
@@ -9,7 +9,7 @@
"Clint Andrew Hall",
"Jerry Jalava"
],
- "version": "0.4.2",
+ "version": "0.4.3",
"main": "./lib/localize",
"dependencies": {},
"devDependencies": {

0 comments on commit 1621661

Please sign in to comment.