npm package: @tabuckner/doggo-translator-ts
Description: A typescript doggo translator based on DoggoTranslatorCore
Author: tabuckner
Latest version: 0.0.3

# Doggo-Translator-TS
![Travis (.com)](https://img.shields.io/travis/com/tabuckner/doggo-translator-ts?style=plastic)
![Codecov](https://img.shields.io/codecov/c/github/tabuckner/doggo-translator-ts?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/tabuckner/doggo-translator-ts?style=plastic)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/tabuckner/doggo-translator-ts?style=plastic)
![GitHub contributors](https://img.shields.io/github/contributors/tabuckner/doggo-translator-ts?style=plastic)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://paypal.me/tabuckner)

A TypeScript library for translating words to 'Doggo' speak!

[StackBlitz Demo](https://stackblitz.com/edit/angular-a7eyjg)

### Usage
You can use the library defaults by creating an instance of the [DoggoTranslator](https://tabuckner.github.io/doggo-translator-ts/classes/doggotranslator.html) class, and using it's publicly available methods. [Read More](./examples/node/index.js)

Optionally you can pass in a [DoggoTranslatorConfig](https://tabuckner.github.io/doggo-translator-ts/interfaces/doggotranslatorconfig.html) object to configure the instance when created.

#### Basic Use Case
```javascript
const library = require('../dist/doggo-translator-ts.umd');
const DoggoTranslator = library.DoggoTranslator;

const myTranslator = new DoggoTranslator();
console.warn(myTranslator.translateSentence('Testing this, bark!'))
console.warn(myTranslator.translateSentence('Hello friend! I hope you have a great day!'))
```

#### User Defined Translations
```javascript
const library = require('../dist/doggo-translator-ts.umd');
const DoggoTranslator = library.DoggoTranslator;
const myTranslations ={
  words: {
    hey: 'hi',
    friend: 'frenn',
    run: 'floop'
  },
  suffixes: {
    ing: 'in'
  }
}

const myTranslator = new DoggoTranslator({ userDefinedTranslations: myTranslations });
const text = 'Hey Friend! Do you want to go run around? I love running!';
const translated = myTranslator.translateSentence(text)
console.warn(translated); // Hi frenn! Do you want to go floop around? I love runnin.
```

#### Browser
To use in Browser, check out the [this example](./examples/browser/index.html)

#### Node
To use in Node, check out the [this example](./examples/node/index.js)


### Features
#### User Supplied Translation Definitions
You can pass a `TranslationMapInterface` compliant object to the `DoggoTranslatorConfig` when instantiating to supply new translations on the fly.

#### Word Swaps
Entire words can be swapped, as expected.

#### Suffix Swaps
Optionally you can supply 'suffixes' to be swapped at the end of words.

### Importing library
You can import the generated bundle to use the whole library generated by this starter:

```typescript
import myLib from 'mylib'
```

Additionally, you can import the transpiled modules from `dist/lib` in case you have a modular library:

```typescript
import something from 'mylib/dist/lib/something'
```

### Public API
[TypeDoc Documentation](https://tabuckner.github.io/doggo-translator-ts/)

[translateSentence](https://tabuckner.github.io/doggo-translator-ts/classes/doggotranslator.html#translatesentence)

[getAllLanguageTokens](https://tabuckner.github.io/doggo-translator-ts/classes/doggotranslator.html#getalllanguagetokens)

[setLanguage](https://tabuckner.github.io/doggo-translator-ts/classes/doggotranslator.html#setlanguage)

<!-- ### Excluding peerDependencies

On library development, one might want to set some peer dependencies, and thus remove those from the final bundle. You can see in [Rollup docs](https://rollupjs.org/#peer-dependencies) how to do that.

Good news: the setup is here for you, you must only include the dependency name in `external` property within `rollup.config.js`. For example, if you want to exclude `lodash`, just write there `external: ['lodash']`.

### Automatic releases

_**Prerequisites**: you need to create/login accounts and add your project to:_
 - [npm](https://www.npmjs.com/)
 - [Travis CI](https://travis-ci.org)
 - [Coveralls](https://coveralls.io)

_**Prerequisite for Windows**: Semantic-release uses
**[node-gyp](https://github.com/nodejs/node-gyp)** so you will need to
install
[Microsoft's windows-build-tools](https://github.com/felixrieseberg/windows-build-tools)
using this command:_

```bash
npm install --global --production windows-build-tools
```

#### Setup steps

Follow the console instructions to install semantic release and run it (answer NO to "Do you want a `.travis.yml` file with semantic-release setup?").

_Note: make sure you've setup `repository.url` in your `package.json` file_

```bash
npm install -g semantic-release-cli
semantic-release-cli setup
# IMPORTANT!! Answer NO to "Do you want a `.travis.yml` file with semantic-release setup?" question. It is already prepared for you :P
```

From now on, you'll need to use `npm run commit`, which is a convenient way to create conventional commits.

Automatic releases are possible thanks to [semantic release](https://github.com/semantic-release/semantic-release), which publishes your code automatically on [github](https://github.com/) and [npm](https://www.npmjs.com/), plus generates automatically a changelog. This setup is highly influenced by [Kent C. Dodds course on egghead.io](https://egghead.io/courses/how-to-write-an-open-source-javascript-library)

### Git Hooks

There is already set a `precommit` hook for formatting your code with Prettier :nail_care:

By default, there are two disabled git hooks. They're set up when you run the `npm run semantic-release-prepare` script. They make sure:
 - You follow a [conventional commit message](https://github.com/conventional-changelog/conventional-changelog)
 - Your build is not going to fail in [Travis](https://travis-ci.org) (or your CI server), since it's runned locally before `git push`

This makes more sense in combination with [automatic releases](#automatic-releases) -->

<!-- ### FAQ

#### `Array.prototype.from`, `Promise`, `Map`... is undefined?

TypeScript or Babel only provides down-emits on syntactical features (`class`, `let`, `async/await`...), but not on functional features (`Array.prototype.find`, `Set`, `Promise`...), . For that, you need Polyfills, such as [`core-js`](https://github.com/zloirock/core-js) or [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill/) (which extends `core-js`).

For a library, `core-js` plays very nicely, since you can import just the polyfills you need:

```javascript
import "core-js/fn/array/find"
import "core-js/fn/string/includes"
import "core-js/fn/promise"
...
``` -->

<!-- #### What if I don't want git-hooks, automatic releases or semantic-release?

Then you may want to:
 - Remove `commitmsg`, `postinstall` scripts from `package.json`. That will not use those git hooks to make sure you make a conventional commit
 - Remove `npm run semantic-release` from `.travis.yml`

#### What if I don't want to use coveralls or report my coverage?

Remove `npm run report-coverage` from `.travis.yml` -->

## License
This application is released under the [MIT license](https://github.com/Gabbersaurus/DoggoTranslatorCore/blob/master/LICENSE).

## Inspired By
[DoggoTranslator (core) :dog:](https://gabbersaurus.github.io/DoggoTranslator/)