4.1.0 • Published 4 years ago

tc-tool v4.1.0

Weekly downloads
4
License
GPL-2.0
Repository
github
Last release
4 years ago

Build Status codecov

tC Tool

This module provides an interface for connecting custom apps/tools to translationCore.

Among other things, this module exposes a HOC that turns any React component into a tool.

installation

npm i tc-tool

Quick Start

To create a tool all you need is a component and a catchy name.

// index.js
import Container from './Container';
import {connectTool} from 'tc-tool';

export default connectTool('awesomeTool')(Container);

The above code should be placed in your module's main file (usually index.js).

Advanced Usage

Locale

Likely the most important feature you'll need to include in your tool is localization. Adding locale is optional but strongly encouraged.

Locale files are structured in Single Language Format and named as Name-locale_REGION.json e.g. English-en_US.json.

// index.js
import Container from './Container';
import {connectTool} from 'tc-tool';
import path from 'path';

export default connectTool('awesomeTool', {
    localeDir: path.join(__dirname, './locale')
})(Container);

Then in your component (or API) you'll have access to localization tools.

// Container.js
class Container extends React.Component {
    render() {
        const {translate, currentLanguage} = this.props;
        return translate('hello'); // returns "Hello" in the correct language
    }
}

NOTE: when using locale, if the selected langauge in tC core is not supported by the tool, it will first try the system locale as a fallback then finally English.

Reducer

If you would like to utilize Redux in your tool you can give it to connectTool. Then you can use the standard connect HOC from react-redux to subscribe to the store.

// index.js
import Container from './Container';
import {connectTool} from 'tc-tool';
import reducer from './reducers';

export default connectTool('awesomeTool', {
	reducer: reducer
})(Container);

Then your reducer state will be available under state.tool.

// Container.js
import connect from 'react-redux';
class Container extends React.Component {
  render() {
    const {myValue} = this.props;
    return myValue;
  }
}

const mapStateToProps = (state) => {
    const {tool: {myValue}} = state;
    return {
        myValue
    };
};
export default connect(mapStateToProps)(Container);

Middleware

The tool already comes configured with the following middleware:

If you need to add additional middleware you can give it to connectTool.

NOTE: middleware will be useless without a reducer for obvious reasons.

// index.js
import Container from './Container';
import {connectTool} from 'tc-tool';
import reducer from './reducers';
import {createLogicMiddleware} from 'redux-logic';

export default connectTool('awesomeTool', {
	reducer,
    middlewares: [createLogicMiddleware()]
})(Container);

Tool API

If other tools need access to functionality or data within this tool you can expose an API.

// index.js
import Container from './Container';
import {connectTool} from 'tc-tool';
import MyApi from './MyApi';

export default connectTool('awesomeTool', {
	api: new MyApi(),
})(Container);

For more information about APIs see Tool API.

Other Features

Error Boundary (Deprecated)

A semi-user-friendly error screen is displayed if an error occurs within the tool. This allows users to navigate to a safe part of the app.

4.1.0

4 years ago

4.0.3-beta

4 years ago

4.0.2-beta.12

4 years ago

4.0.2-beta.13

4 years ago

4.0.2-beta.10

4 years ago

4.0.2-beta.11

4 years ago

4.0.2-beta.8

4 years ago

4.0.2-beta.7

4 years ago

4.0.2-beta.9

4 years ago

4.0.2-beta.4

4 years ago

4.0.2-beta.3

4 years ago

4.0.2-beta.6

4 years ago

4.0.2-beta.5

4 years ago

4.0.2-beta.2

4 years ago

4.0.2-beta

4 years ago

4.0.1

4 years ago

4.0.1-beta.6

4 years ago

4.0.1-beta.2

4 years ago

4.0.1-beta.3

4 years ago

4.0.1-beta

4 years ago

4.0.0

4 years ago

3.0.4-beta

4 years ago

3.0.4-beta.2

4 years ago

3.0.3

4 years ago

3.0.3-beta.5

4 years ago

3.0.3-beta.4

4 years ago

3.0.3-beta.3

4 years ago

3.0.3-beta

4 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

2.0.0-rc.1

6 years ago

1.6.3

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.16

6 years ago

1.4.15

6 years ago

1.4.14

6 years ago

1.4.13

6 years ago

1.4.12

6 years ago

1.4.11

6 years ago

1.4.10

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago