Skip to content

Commit

Permalink
Expose instance - (made for Webpack external)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan authored Sep 25, 2017
1 parent 8c9f6fb commit 1a8f54f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
12 changes: 12 additions & 0 deletions instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @module @fiverr/i18n/instance
* @since 1.5.0
*/

const I18n = require('./');

/**
* Shortcut to an empty I18n instance
* @type {I18n}
*/
module.exports = new I18n();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fiverr/i18n",
"version": "1.4.0",
"version": "1.5.0",
"description": "Translation helper",
"author": "Fiverr dev team",
"license": "MIT",
Expand Down
29 changes: 28 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,34 @@ usersI18n.t('introduction', {username: 'Martin'}); // Hi, my name is Martin
i18n.t('users.get.introduction', {username: 'Martin'}); // Hi, my name is Martin
```

### Singleton
### Instance
Exposes an empty instance of i18n
```javascript
const i18n = require('@fiverr/i18n/instance');

i18n.add({...});
```

Made especially for use as a webpack external
```javascript
externals: {
'@fiverr/i18n/instance': 'i18n'
}
```

> Name can alternate:
> ```javascript
> import phraser from '@fiverr/i18n/instance';
> ```
>
> ```javascript
> externals: {
> '@fiverr/i18n/instance': 'phraser'
> }
> ```
### Singleton (i18n)
Make sure you only have one instance of I18n in your global scope
```javascript
const i18n = I18n.singleton;
Expand Down
5 changes: 5 additions & 0 deletions singleton.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @module @fiverr/i18n/singleton
* @since 1.2.0
*/

const I18n = require('./');

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {expect} = require('chai');
const instance = require('../instance');

describe('Instance', () => {
it('exports an I18n instance', () => {
expect(instance.constructor.name).to.equal('I18n');
});
});

0 comments on commit 1a8f54f

Please sign in to comment.