Skip to content

Commit

Permalink
Merge 026ead2 into 11d89da
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyTrotin committed Jan 11, 2017
2 parents 11d89da + 026ead2 commit 1e205d3
Show file tree
Hide file tree
Showing 10 changed files with 1,145 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage/
defaultlocales
localestowrite
localesmakeplural
secondLocales
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test:
mocha
mocha test/i18n.*
mocha test/multiDirectories.js

cover:
istanbul cover ./node_modules/mocha/bin/_mocha
Expand All @@ -12,6 +13,9 @@ examples:
mocha $$example; \
done

all: test examples hint
clean:
rm -rf locales/custom* testlocales customlocales secondlocalestowrite testlocalesauto testlocalesautocustomextension testlocalesautoprefixed testlocalesautoprefixedext locales_temp

.PHONY: test examples
all: clean test examples hint clean

.PHONY: clean test examples clean
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,47 @@ app.use(express.static(__dirname + '/www'));
app.use('/en', express.static(__dirname + '/www'));
app.use('/de', express.static(__dirname + '/www'));
```
##Multiple Directories support

i18n-node support a multiple directory usage. This option let you register different directories to provide translations. Just add "multiDirectories : true" in your configuration then use the configure method to provide new directory and a name for it. Finally call translations methods with directory name as last argument.
Please note that in case you do not use the updateFiles you may ommit directory name and juste call translations method as usual.

###Exemple
####In core/index.js
Configure i18n as usual, just add multiDirectories :

i18n.configure({
directory: __dirname + '/locales',
multiDirectories: true
});
####In myAwesomeModule/index.js
Specify a new directory and a name :

i18n.extendLocales({
directory: __dirname + '/locales',
dirName: 'myAwesomeModule'
});

Then translate anything as usual if translation come from default directory, or just pass the directory name if translation come from another directory

__('core sentence to translate');
//Same as __('core sentence to translate', 'default');

__('myAwesomeModule sentence', 'myAwesomeModule');

###Details
When you set multiDirectories at true in the configure method, a "directories" object is initialized. Then every time you register a new source directory with configure method you extend this object with a new directory path and a name for this path. Finally you can call translations methods and provide as last argument the name of the directory path you set earlier.

Note that when you activate the multiDirectories option you cannot reset every option for every directory. It means you must have the same directory configuration (eg : indentation, object notation, prefixes ...).

The available option are :

- directory : path to sources
- dirName : directory name / module name
- locales
- fallbacks

__If you want to reset your i18n configuration__, call configure() with multiDirectories at false and every option will be reseted

## API

Expand Down
Loading

0 comments on commit 1e205d3

Please sign in to comment.