diff --git a/README.md b/README.md index 170f020..263f297 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,14 @@ export default Something; You can stop the countdown timer anytime by passing `true` (Boolean) with `stop` props. +You can change the language of the text to French by passing `FR` (String) with `format` props. + +``` + +``` ### Caution diff --git a/src/libs/countdown.js b/src/libs/countdown.js index 936a6b3..c4c872f 100644 --- a/src/libs/countdown.js +++ b/src/libs/countdown.js @@ -13,7 +13,8 @@ class CountDown extends React.Component { this.state = { now: Math.trunc((new Date()).getTime() / 1000), date: null, - diff: 0 + diff: 0, + format: 'ENG' } this.seconds = this.seconds.bind(this); @@ -59,6 +60,11 @@ class CountDown extends React.Component { } componentWillMount() { + if (this.props.format) { + this.setState({ + format: this.props.format + }) + } this.setDateAndInterVal() } @@ -129,11 +135,17 @@ class CountDown extends React.Component { } setDayString() { + if (this.state.format === "FR") { + return this.days() > 1 ? 'jours' : 'jour'; + } return this.days() > 1 ? 'days' : 'day'; } setHourString() { - return this.hours() > 1 ? 'hours' : 'hour'; + if (this.state.format === "FR") { + return this.hours() > 1 ? 'heures' : 'heure'; + } + return this.days() > 1 ? 'hours' : 'hour'; } // update show days