diff --git a/client/coral-configure/containers/ConfigureStreamContainer.js b/client/coral-configure/containers/ConfigureStreamContainer.js index aef7093f2..9c53fdf28 100644 --- a/client/coral-configure/containers/ConfigureStreamContainer.js +++ b/client/coral-configure/containers/ConfigureStreamContainer.js @@ -5,6 +5,8 @@ import {compose} from 'react-apollo'; import {I18n} from 'coral-framework'; import {updateOpenStatus, updateConfiguration} from 'coral-framework/actions/asset'; +import timeago from 'timeago.js'; + import CloseCommentsInfo from '../components/CloseCommentsInfo'; import ConfigureCommentStream from '../components/ConfigureCommentStream'; @@ -87,7 +89,7 @@ class ConfigureStreamContainer extends Component { const {closedTimeout} = this.props.asset.settings; const {created_at} = this.props.asset; - return lang.timeago(new Date(created_at).getTime() + (1000 * closedTimeout)); + return timeago().format(new Date(created_at).getTime() + (1000 * closedTimeout), lang.getLocale().replace('-', '_')); } render () { diff --git a/client/coral-i18n/modules/i18n/i18n.js b/client/coral-i18n/modules/i18n/i18n.js index 749e06a5e..ac447c313 100644 --- a/client/coral-i18n/modules/i18n/i18n.js +++ b/client/coral-i18n/modules/i18n/i18n.js @@ -1,9 +1,7 @@ -import timeago from 'timeago.js'; -import esTA from '../../../../node_modules/timeago.js/locales/es'; import has from 'lodash/has'; import get from 'lodash/get'; -const yaml = require('node-yaml'); +import YAML from 'yamljs'; /** * Default locales, this should be overriden by config file @@ -15,8 +13,6 @@ class i18n { /** * Register locales */ - timeago.register('es_ES', esTA); - this.timeagoInstance = new timeago(); try { const locale = this.getLocale(); @@ -34,18 +30,16 @@ class i18n { loadTranslations = (translations) => { const localesFiles = {'en': 'locales/en.yml', 'es': 'locales/es.yml'}; - yaml.readPromise(localesFiles[this.language]) - .then((data) => { + try { - // Translations need to be loaded from translations or localesFiles. - this.translations = translations[this.language] || data; + // Translations need to be loaded from translations or localesFiles. + this.translations = translations[this.language] || YAML.load(localesFiles[this.language]); + } + catch(err) { - }) - .catch(() => { - - // To Do: get configuration for default translation - this.translations = translations['en']; - }); + // To Do: get configuration for default translation + this.translations = translations['en']; + } } setLocale = (locale) => { @@ -84,11 +78,6 @@ class i18n { return key; } }; - - timeago = (time) => { - return this.timeagoInstance.format(new Date(time)); - }; - } export default i18n; diff --git a/client/coral-plugin-pubdate/PubDate.js b/client/coral-plugin-pubdate/PubDate.js index 81c8495a4..202d2131c 100644 --- a/client/coral-plugin-pubdate/PubDate.js +++ b/client/coral-plugin-pubdate/PubDate.js @@ -1,11 +1,14 @@ import React from 'react'; import {I18n} from '../coral-framework'; +import timeago from 'timeago.js'; + const lang = new I18n(); const name = 'coral-plugin-pubdate'; const PubDate = ({created_at}) =>