Skip to content

Commit

Permalink
Update README and set defaults for importing
Browse files Browse the repository at this point in the history
  • Loading branch information
knor-el-snor committed Apr 27, 2018
1 parent a6dddf2 commit f4e7264
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ throw new ApiError(400, errors.BAD_REQUEST);

## Error parsing

### parseErrors(error)
### parseErrors(error, i18nOptions (optional))

Parse any data into an error object with all properties needed for jsonade parser. Also parses `express-validation` errors.

Expand All @@ -143,16 +143,40 @@ const parsedError = parseErrors(error);
serializer.serialize([parsedError]);
```

With i18n support (optional):

```javascript
const error = new BadRequestError(...);
const parsedError = parseErrors(error, {
defaultLocale: 'en', // Optional (defaults to 'en')
language: 'nl', // Optional (defaults to 'en')
path: __dirname = '/locales',
});

// jsonade serializer afterwards (optional)
serializer.serialize([parsedError]);
```

> The `parseErrors` function will load the i18n configuration once, and reuse the same instance afterwards. It is not possible to overwrite the configuration after the first call. This has to do with performance and caching of translations.
## Import translations

Import new or updated translations from the iCapps translation portal

```javascript
import { importTranslations } from 'tree-house-errors';

await importTranslations('applicationToken');
await importTranslations('applicationToken', {
destination: __dirname + '/locales'
clean: false, // Optional (default to true)
verbose: true, // Optional (defaults to false)
seperateCategories: false, // Optional (defaults to true)
exportType: 'plist', // Optional (defaults to 'json')
});
```

- [more info about the icapps translations module used to import translations](https://github.com/icapps/js-translations)

## Tests

- You can run `yarn test` to run all tests
Expand Down
3 changes: 3 additions & 0 deletions src/lib/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { existsSync, mkdirSync } from 'fs';
const url = '';
const defaultOptions = {
destination: process.cwd() + '/locales',
clean: true,
seperateCategories: false,
exportType: 'json',
};

export async function importTranslations(token: string, options?: TranslationOptions) {
Expand Down

0 comments on commit f4e7264

Please sign in to comment.