Skip to content

Commit

Permalink
locales supported, fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Oct 11, 2016
1 parent 873a9c4 commit da6082a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Realtime render. Automatic release the resources.
- Simple. Only 2kb.
- Efficient. When the time is `3 hour ago`, the interval will an hour (3600 * 1000 ms).
- Locales supported.

[![Build Status](https://travis-ci.org/hustcc/timeago-react.svg?branch=master)](https://travis-ci.org/hustcc/timeago-react) [![npm](https://img.shields.io/npm/v/timeago-react.svg?style=flat-square)](https://www.npmjs.com/package/timeago-react) [![npm](https://img.shields.io/npm/dt/timeago-react.svg?style=flat-square)](https://www.npmjs.com/package/timeago-react) [![npm](https://img.shields.io/npm/l/timeago-react.svg?style=flat-square)](https://www.npmjs.com/package/timeago-react)

Expand Down Expand Up @@ -45,7 +46,7 @@ The `class` of span. you can setting the css style of span by class name.

- **`locale`** (optional, string)

The `locale` language of statement, default is `en`. `zh_CN` and `en` are supported.
The `locale` language of statement, default is `en`. All supported locales [here](https://github.com/hustcc/timeago.js/tree/master/locales).


# 4. LICENSE
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ h4 a:hover {

a,
a:hover {
color: #ecf0f1;
color: red;
}

pre {
Expand Down
11 changes: 6 additions & 5 deletions demo/dist/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions demo/timeagoComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const TimeagoComponent = React.createClass({

<div className='examples'>
<div className='parent'>
<label> 2. Use `locale` parameter. Default is `en`.</label>
<label> 2. Use `locale` parameter. Default is `en`. Supported locales see <a href="https://github.com/hustcc/timeago.js/tree/master/locales">here</a></label>
Hustcc born in&nbsp;
<strong>
<TimeAgo datetime={'1992-08-01'}
locale={'zh_CN'} />
locale={'vi'} />
</strong>.
<pre>
<code>{"<TimeAgo datetime={'1992-08-01'} \n\tlocale={'zh_CN'} /> \n"}</code>
<code>{"<TimeAgo datetime={'1992-08-01'} \n\tlocale={'vi'} /> \n"}</code>
</pre>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion lib/timeago-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ var TimeAgo = _react2['default'].createClass({
propTypes: {
datetime: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.instanceOf(Date), _react2['default'].PropTypes.number]).isRequired, // date to be formated
live: _react2['default'].PropTypes.bool, // real time render.
locale: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.object]), // locale lang
locale: _react2['default'].PropTypes.string, // locale lang
className: _react2['default'].PropTypes.string // class name
},
getDefaultProps: function getDefaultProps() {
return { live: true, locale: 'en' };
},

// first add
componentDidMount: function componentDidMount() {
if (this.props.locale !== 'en' && this.props.locale !== 'zh_CN') _timeago2['default'].register(this.props.locale, require('timeago.js/locales/' + this.props.locale));

this.renderTimeAgo();
},

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "timeago-react",
"version": "1.0.6",
"version": "1.0.7",
"description": "timeago-react is a simple(only 2kb) react component used to format date with `*** time ago` statement. eg: '3 hours ago'.",
"main": "lib/timeago-react.js",
"scripts": {
"start": "webpack-dev-server --watch",
"lint": "eslint src",
"clean": "rimraf lib",
"test": "npm run lint",
"build": "npm run clean && cross-env NODE_ENV=production babel src -d lib",
"build": "npm run clean && cross-env NODE_ENV=production babel src -d lib && npm run build-demos",
"build-demos": "webpack",
"prepublish": "npm run build"
},
Expand Down
8 changes: 7 additions & 1 deletion src/timeago-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ const TimeAgo = React.createClass({
propTypes: {
datetime: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.instanceOf(Date), React.PropTypes.number]).isRequired, // date to be formated
live: React.PropTypes.bool, // real time render.
locale: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.object]), // locale lang
locale: React.PropTypes.string, // locale lang
className: React.PropTypes.string // class name
},
getDefaultProps() {
return {live: true, locale: 'en'};
},
// first add
componentDidMount() {
if (this.props.locale !== 'en' && this.props.locale !== 'zh_CN')
timeago.register(this.props.locale, require('timeago.js/locales/' + this.props.locale));

this.renderTimeAgo();
},
// init instance
Expand Down

0 comments on commit da6082a

Please sign in to comment.