Permalink
Browse files

1.0.0

Core overhauled.
100% tested.
API simplified.
Removed JSON layer.
Memory cache only reindex on syncing.
Improved storages.
Added more examples.
  • Loading branch information...
1 parent cadeaec commit 71caac84f1d3dae54b6cfdb6a2fddea7b83d0085 @masylum committed Mar 19, 2011
Showing with 617 additions and 1,024 deletions.
  1. +47 −10 Readme.md
  2. +0 −43 benchmarks/app.js
  3. +48 −0 benchmarks/hello_world.js
  4. +20 −0 examples/contexts.js
  5. +8 −6 examples/hello_world.js
  6. +12 −11 examples/plurals.js
  7. +34 −30 lib/dialect.js
  8. +16 −12 lib/stores/mongodb.js
  9. +1 −1 lib/stores/sqlite.js
  10. +3 −3 package.json
  11. +22 −62 test/dialect.js
  12. +0 −385 test/integration_test.js
  13. +42 −50 test/io.js
  14. +42 −58 test/sqlizer.js
  15. +152 −166 test/stores/mongodb.js
  16. +170 −187 test/stores/sqlite.js
View
@@ -8,7 +8,7 @@
`Wbmd"MML..JMML.`Moo9^Yo..JMML.`Mbmmd' YMbmd' `Mbmo
-Dialect is the painless nodejs module that deals with i18n.
+Dialect is a painless nodejs module to manage your translations.
## Install
@@ -17,24 +17,45 @@ Dialect is the painless nodejs module that deals with i18n.
## Philosphy
* Scalable: The translations should be available to any number of machines.
-* Fast: Getting translations from memory if possible.
+* Fast: Getting translations from memory.
* Reliable: Translations should be always available on a central repository/database.
* Flexible: You should be able to use your favorite storage solution.
## Example
var dialect = require('dialect').dialect({current_locale: 'es', store: 'mongodb'});
- dialect.sync({interval:3600}, function (err, foo) {
- d.get('Hello World!'); // => Hola mundo
+ // connects to the store
+ dialect.connect(function () {
+
+ // syncs the memory dictionaries with the store
+ dialect.sync({interval:3600}, function (err, foo) {
+ d.get('Hello World!'); // => Hola mundo
+ });
});
+## Options
+
+* `current_locale`: Current locale used on your application.
+* `base_locale`: Base locale. Serves as keys on the dictionaries.
+* `locales`: Which locales are available on your application.
+* `store`: Object containing the store and their options
+ * `mongodb`: mongoDB storage.
+ * database
+ * host
+ * port
+ * collection
+ * `sqlite`: SQLite storage.
+ * database
+ * table
+
## API
* `config (key, value)`: Exposes configuration values.
* `get (query)`: Gets a translation cached in memory.
* `set (query, translation, callback)`: Sets a translation on the store.
* `sync (locale, repeat, callback)`: Syncs the store with the memory cache.
+* `connect (callback)`: Connects to the database store.
### Plurals
@@ -56,6 +77,8 @@ which plural form to use.
| Piva | Beers |
+---------------+-------------+
+You have an examle using plural forms in `examples/plurals.js`
+
### Contexts
@@ -76,6 +99,7 @@ diferent translations depending on the context.
| Mis amigas | My friends |
+---------------+-------------+
+You have an examle using contexts in `examples/contexts.js`
### String interpolation
@@ -102,6 +126,8 @@ meaning although they can also be used with interpolations.
| Tienes 2 amigos que se llaman Anna | You have 2 friends called Anna |
+---------------------------------------+-----------------------------------------+
+You have an examle using contexts in `examples/interpolation.js`
+
### Store translations
To store a new translation, use the method `set`.
@@ -111,12 +137,11 @@ To store a new translation, use the method `set`.
'Me encanta el gazpacho'
);
-## express-dialect
+## dialect-http
-Do you have an express application and you to deal with i18n? Do you want to see
-how dialect works in a real app?
+Do you need a nice environment for your translators?
-Try [express-dialect](http://www.github.com/masylum/express-dialect)
+Dialect http is an amazing web application to manage your translations.
## Test
@@ -129,6 +154,18 @@ Dialect is heavily tested using [testosterone](http://www.github.com/masylum/tes
Dialect should not add an overhead to your application on getting translations.
Please run/add benchmarks to ensure that this module performance rocks.
- node benchmakrs/app.js
+ node benchmakrs/hello_world.js
+
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2010-2011 Pau Ramon <masylum@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-Have fun!
View
@@ -1,43 +0,0 @@
-// benchmark
-require('./..').store({store: 'mongodb', database: 'bench'}, function (error, store) {
- var dialect = require('./..').dialect({
- base_locale: 'en_us',
- current_locale: 'es_es',
- locales: ['en_en', 'es_es'],
- store: store
- });
-
- store.collection.remove({}, function (err, data) {
-
- var options = {count: 1, context: 'females', name: 'Anna'},
- original = [
- 'You have {count} friend called {name}',
- 'You have {count} friends called {name}',
- options
- ],
- i = 0,
- tests = 100000,
- translation = 'Tienes {count} amiga llamada {name}',
- output = original[0],
- now = Date.now();
-
- dialect.get(original, function () {
- dialect.set({
- original: original[0],
- locale: dialect.config('current_locale'),
- context: 'female',
- count: 'singular'
- }, translation, function () {
- console.log('running...');
-
- for (;i < tests; i += 1) {
- dialect.get(original);
- }
-
- var time = Date.now() - now;
- console.log(time + 'ms');
- console.log(time / tests + 'ms per request');
- });
- });
- });
-});
View
@@ -0,0 +1,48 @@
+var dialect = require('..').dialect({
+ locales: ['es', 'en'],
+ current_locale: 'es',
+ store: {mongodb: {}} // test your store here
+ }),
+ funk = require('funk')(),
+ funk2 = require('funk')(),
+ times = 300,
+ _ = dialect.get,
+ original = 'Hello World!',
+ translation = 'Hola Mundo!';
+
+dialect.connect(function () {
+ var i = 0,
+ now = Date.now(),
+ time = null;
+
+ console.log('Setting ' + times + ' translations...');
+
+ for (i = 0; i < times; i ++) {
+ _(original);
+ dialect.set({original: original, locale: 'es'}, translation, funk.nothing());
+
+ //dialect.sync({}, function (err, foo) {
+ //_(original);
+ //_('Inexistant');
+ //});
+ }
+
+ funk.parallel(function () {
+ time = Date.now() - now;
+ console.log(time + 'ms');
+ console.log(parseInt(1000 / ( time / times)) + ' sets/sec');
+ });
+
+ dialect.sync({}, function (err, foo) {
+ now = Date.now();
+ time = null;
+
+ console.log('Getting ' + times + ' translations...');
+ for (i = 0; i < times; i ++) {
+ _(original);
+ }
+ time = Date.now() - now;
+ console.log(time + 'ms');
+ console.log(parseInt(1000 / (time / times)) + ' gets/sec');
+ });
+});
View
@@ -0,0 +1,20 @@
+var dialect = require('..').dialect({
+ locales: ['es', 'en'],
+ current_locale: 'es',
+ store: {mongodb: {}}
+ }),
+ _ = dialect.get;
+
+dialect.connect(function () {
+ console.log(_(['Fight', {context: 'name'}]));
+ console.log(_(['Fight', {context: 'verb'}]));
+
+ dialect.set({original: 'Fight', locale: 'es', context: 'name'}, 'Lucha');
+ dialect.set({original: 'Fight', locale: 'es', context: 'verb'}, 'Luchar');
+
+ dialect.sync({interval: 3600}, function (err, foo) {
+ console.log(_(['Fight', {context: 'name'}]));
+ console.log(_(['Fight', {context: 'verb'}]));
+ process.exit();
+ });
+});
View
@@ -7,11 +7,13 @@ var dialect = require('..').dialect({
original = 'Hello World!',
translation = 'Hola Mundo!';
-console.log(_(original));
-dialect.set({original: original, locale: 'es'}, translation);
-
-dialect.sync({interval: 3600}, function (err, foo) {
+dialect.connect(function () {
console.log(_(original));
- console.log(_('Inexistant'));
- process.exit();
+ dialect.set({original: original, locale: 'es'}, translation);
+
+ dialect.sync({interval: 3600}, function (err, foo) {
+ console.log(_(original));
+ console.log(_('Inexistant'));
+ process.exit();
+ });
});
View
@@ -5,18 +5,19 @@ var dialect = require('..').dialect({
}),
_ = dialect.get;
-[1, 2, 3].forEach(function (i) {
- console.log(_(['{count} Beer', '{count} Beers', {count: i}]));
-});
-
-dialect.set({original: '{count} Beer', locale: 'es', plural: 1}, '{count} pivo');
-dialect.set({original: '{count} Beer', locale: 'es', plural: 2}, '{count} pivi');
-dialect.set({original: '{count} Beer', locale: 'es', plural: 3}, '{count} piva');
-
-dialect.sync({interval: 3600}, function (err, foo) {
+dialect.connect(function () {
[1, 2, 3].forEach(function (i) {
console.log(_(['{count} Beer', '{count} Beers', {count: i}]));
});
- process.exit();
-});
+ dialect.set({original: '{count} Beer', locale: 'es', plural: 1}, '{count} pivo');
+ dialect.set({original: '{count} Beer', locale: 'es', plural: 2}, '{count} pivi');
+ dialect.set({original: '{count} Beer', locale: 'es', plural: 3}, '{count} piva');
+
+ dialect.sync({interval: 3600}, function (err, foo) {
+ [1, 2, 3].forEach(function (i) {
+ console.log(_(['{count} Beer', '{count} Beers', {count: i}]));
+ });
+ process.exit();
+ });
+});
Oops, something went wrong.

0 comments on commit 71caac8

Please sign in to comment.