Skip to content

Added i18n to Support translate label #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/node_modules
package-lock.json
yarn.lock
pnpm-lock.yaml
pnpm-lock.yaml
.idea
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,33 @@ Returns:

### Properties

| Property | Type | Description | Default |
| -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- | ----------- |
| `nodes` | array | **Required**. Specifies the tree nodes and their children. | |
| `checkModel` | string | Specifies which checked nodes should be stored in the `checked` array. Accepts `'leaf'` or `'all'`. | `'leaf'` |
| `checked` | array | An array of checked node values. | `[]` |
| `direction` | string | A string that specify whether the direction of the component is left-to-right (`'ltr'`) or right-to-left (`'rtl'`). | `'ltr'` |
| `disabled` | bool | If true, the component will be disabled and nodes cannot be checked. | `false` |
| `expandDisabled` | bool | If true, the ability to expand nodes will be disabled. | `false` |
| `expandOnClick` | bool | If true, nodes will be expanded by clicking on labels. Requires a non-empty `onClick` function. | `false` |
| `expanded` | array | An array of expanded node values. | `[]` |
| `icons` | object | An object containing the mappings for the various icons and their components. See **Changing the Default Icons**. | `{ ... }` |
| `iconsClass` | string | A string that specifies which icons class to utilize. Currently, `'fa4'` and `'fa5'` are supported. | `'fa5'` |
| `id` | string | A string to be used for the HTML ID of the rendered tree and its nodes. | `null` |
| `lang` | object | An object containing the language mappings for the various text elements. | `{ ... }` |
| `name` | string | Optional name for the hidden `<input>` element. | `undefined` |
| `nameAsArray` | bool | If true, the hidden `<input>` will encode its values as an array rather than a joined string. | `false` |
| `nativeCheckboxes` | bool | If true, native browser checkboxes will be used instead of pseudo-checkbox icons. | `false` |
| `noCascade` | bool | If true, toggling a parent node will **not** cascade its check state to its children. | `false` |
| `onlyLeafCheckboxes` | bool | If true, checkboxes will only be shown for leaf nodes. | `false` |
| `optimisticToggle` | bool | If true, toggling a partially-checked node will select all children. If false, it will deselect. | `true` |
| `showExpandAll` | bool | If true, buttons for expanding and collapsing all parent nodes will appear in the tree. | `false` |
| `showNodeIcon` | bool | If true, each node will show a parent or leaf icon. | `true` |
| `showNodeTitle` | bool | If true, the `label` of each node will become the `title` of the resulting DOM node. Overridden by `node.title`. | `false` |
| `onCheck` | function | onCheck handler: `function(checked, targetNode) {}` | `() => {}` |
| `onClick` | function | onClick handler: `function(targetNode) {}`. If set, `onClick` will be called when a node's label has been clicked. | `() => {}` |
| `onExpand` | function | onExpand handler: `function(expanded, targetNode) {}` | `() => {}` |
| Property | Type | Description | Default |
|----------------------| -------- |---------------------------------------------------------------------------------------------------------------------|-------------|
| `nodes` | array | **Required**. Specifies the tree nodes and their children. | |
| `checkModel` | string | Specifies which checked nodes should be stored in the `checked` array. Accepts `'leaf'` or `'all'`. | `'leaf'` |
| `checked` | array | An array of checked node values. | `[]` |
| `direction` | string | A string that specify whether the direction of the component is left-to-right (`'ltr'`) or right-to-left (`'rtl'`). | `'ltr'` |
| `disabled` | bool | If true, the component will be disabled and nodes cannot be checked. | `false` |
| `expandDisabled` | bool | If true, the ability to expand nodes will be disabled. | `false` |
| `expandOnClick` | bool | If true, nodes will be expanded by clicking on labels. Requires a non-empty `onClick` function. | `false` |
| `expanded` | array | An array of expanded node values. | `[]` |
| `icons` | object | An object containing the mappings for the various icons and their components. See **Changing the Default Icons**. | `{ ... }` |
| `iconsClass` | string | A string that specifies which icons class to utilize. Currently, `'fa4'` and `'fa5'` are supported. | `'fa5'` |
| `id` | string | A string to be used for the HTML ID of the rendered tree and its nodes. | `null` |
| `lang` | object | An object containing the language mappings for the various text elements. | `{ ... }` |
| `name` | string | Optional name for the hidden `<input>` element. | `undefined` |
| `nameAsArray` | bool | If true, the hidden `<input>` will encode its values as an array rather than a joined string. | `false` |
| `nativeCheckboxes` | bool | If true, native browser checkboxes will be used instead of pseudo-checkbox icons. | `false` |
| `noCascade` | bool | If true, toggling a parent node will **not** cascade its check state to its children. | `false` |
| `onlyLeafCheckboxes` | bool | If true, checkboxes will only be shown for leaf nodes. | `false` |
| `optimisticToggle` | bool | If true, toggling a partially-checked node will select all children. If false, it will deselect. | `true` |
| `showExpandAll` | bool | If true, buttons for expanding and collapsing all parent nodes will appear in the tree. | `false` |
| `showNodeIcon` | bool | If true, each node will show a parent or leaf icon. | `true` |
| `showNodeTitle` | bool | If true, the `label` of each node will become the `title` of the resulting DOM node. Overridden by `node.title`. | `false` |
| `onCheck` | function | onCheck handler: `function(checked, targetNode) {}` | `() => {}` |
| `onClick` | function | onClick handler: `function(targetNode) {}`. If set, `onClick` will be called when a node's label has been clicked. | `() => {}` |
| `onExpand` | function | onExpand handler: `function(expanded, targetNode) {}` | `() => {}` |
| `i18n` | function | An i18n object to translate label | `null` |

#### `onCheck` and `onExpand`

Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ declare module "react-checkbox-tree" {
onCheck?: (checked: Array<string>, node: OnCheckNode) => void;
onClick?: (node: OnCheckNode) => void;
onExpand?: (expanded: Array<string>, node: OnExpandNode) => void;
i18n?: any;
}

export default class CheckboxTree extends React.Component<CheckboxProps> {}
Expand Down
5 changes: 4 additions & 1 deletion src/js/CheckboxTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CheckboxTree extends React.Component {
expandDisabled: PropTypes.bool,
expandOnClick: PropTypes.bool,
expanded: listShape,
i18n: PropTypes.func,
icons: iconsShape,
iconsClass: PropTypes.string,
id: PropTypes.string,
Expand All @@ -51,6 +52,7 @@ class CheckboxTree extends React.Component {
expandDisabled: false,
expandOnClick: false,
expanded: [],
i18n: null,
icons: {
check: <span className="rct-icon rct-icon-check" />,
uncheck: <span className="rct-icon rct-icon-uncheck" />,
Expand Down Expand Up @@ -223,6 +225,7 @@ class CheckboxTree extends React.Component {
expandDisabled,
expandOnClick,
icons,
i18n,
lang,
noCascade,
onClick,
Expand Down Expand Up @@ -267,7 +270,7 @@ class CheckboxTree extends React.Component {
icons={this.combineMemorized(defaultIcons, icons)}
isLeaf={flatNode.isLeaf}
isParent={flatNode.isParent}
label={node.label}
label={i18n ? i18n.t(node.label) : node.label}
lang={lang}
optimisticToggle={optimisticToggle}
showCheckbox={showCheckbox}
Expand Down