Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 97f7ba9

Browse files
Merge pull request #13 from eugene-manuilov/release/0.4.0
Release/0.4.0
2 parents 79cd8c3 + cbf2a0f commit 97f7ba9

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.4.0 (2017-08-17)
4+
5+
**Implemented enhancements:**
6+
7+
- Implemented ability to get wrapped component.
8+
39
## v0.3.3 (2017-08-12)
410

511
**Implemented enhancements:**

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-gettext 0.3.3
1+
# react-gettext 0.4.0
22

33
[![Build Status](https://travis-ci.org/eugene-manuilov/react-gettext.svg?branch=master)](https://travis-ci.org/eugene-manuilov/react-gettext)
44

@@ -104,12 +104,14 @@ See an [example](https://github.com/eugene-manuilov/react-gettext/tree/master/ex
104104

105105
## Documentation
106106

107-
### withGettext(translations, pluralForms)
107+
### withGettext(translations, pluralForms, options)
108108

109109
Higher-order function which is exported by default from `react-gettext` package. It accepts two arguments and returns function to create higher-order component.
110110

111111
- **translations**: a hash object or a function which returns hash object where keys are original messages and values are translated messages.
112112
- **pluralForms**: a string to calculate plural form (used by [Gettext PO](http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms)) or a function which accepts a number and calculates a plural form number. Pay attentions that plural forms are zero-based what means to get 1st plural form it should return 0, to get 2nd - 1, and so on.
113+
- **options**: a hash object with options. Currently supports following options:
114+
- **withRef**: an optional boolean flag that determines whether or not to set `ref` property to a wrapped component what will allow you to get wrapped component instance by calling `getWrappedComponent()` function of the HOC. By default: `FALSE`.
113115

114116
Example:
115117

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"bugs": {
88
"url": "https://github.com/eugene-manuilov/react-gettext/issues"
99
},
10-
"version": "0.3.3",
10+
"version": "0.4.0",
1111
"main": "lib/index",
1212
"files": [
1313
"*.md",

src/index.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@ import React from 'react';
22
import hoistNonReactStatic from 'hoist-non-react-statics';
33
import Textdomain from './Textdomain';
44

5-
export { Textdomain };
5+
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
6+
const args = Object.assign({ withRef: false }, options);
7+
8+
class WithGettext extends Textdomain {
69

7-
export default function withGettext(translations = {}, pluralForm = 'n != 1') {
8-
return (WrappedComponent) => {
9-
class WithGettext extends Textdomain {
10+
getWrappedComponent() {
11+
return this.refs.wrappedComponent;
12+
}
1013

11-
render() {
12-
return React.createElement(WrappedComponent, this.props);
14+
render() {
15+
const newprops = Object.assign({}, this.props);
16+
if (args.withRef) {
17+
newprops.ref = 'wrappedComponent';
1318
}
1419

20+
return React.createElement(WrappedComponent, newprops);
1521
}
1622

17-
WithGettext.defaultProps = {
18-
translations,
19-
plural: pluralForm,
20-
};
21-
22-
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
23+
}
2324

24-
return hoistNonReactStatic(WithGettext, WrappedComponent);
25+
WithGettext.defaultProps = {
26+
translations,
27+
plural: pluralForm,
2528
};
26-
}
29+
30+
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
31+
32+
return hoistNonReactStatic(WithGettext, WrappedComponent);
33+
};
34+
35+
export { Textdomain };
36+
export default withGettext;

0 commit comments

Comments
 (0)