From 0f7b4ddaf620e4885761cb43da62e71e49ca8e70 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 25 Apr 2017 11:43:04 -0500 Subject: [PATCH] Removes timeago from i18n module. --- .../containers/ConfigureStreamContainer.js | 4 ++- client/coral-i18n/modules/i18n/i18n.js | 29 ++++++------------- client/coral-plugin-pubdate/PubDate.js | 5 +++- package.json | 3 +- yarn.lock | 7 +++++ 5 files changed, 25 insertions(+), 23 deletions(-) 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}) =>
- {lang.timeago(created_at)} + {timeago().format(created_at, lang.getLocale().replace('-', '_'))} +
; export default PubDate; diff --git a/package.json b/package.json index 6c725a852..25bbec92b 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,8 @@ "resolve": "^1.3.2", "semver": "^5.3.0", "simplemde": "^1.11.2", - "uuid": "^2.0.3" + "uuid": "^2.0.3", + "yamljs": "^0.2.10" }, "devDependencies": { "apollo-client": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index 378e5a6c0..29058ed72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8236,6 +8236,13 @@ yallist@^2.0.0: version "2.1.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" +yamljs@^0.2.10: + version "0.2.10" + resolved "https://registry.yarnpkg.com/yamljs/-/yamljs-0.2.10.tgz#481cc7c25ca73af59f591f0c96e3ce56c757a40f" + dependencies: + argparse "^1.0.7" + glob "^7.0.5" + yargs-parser@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-2.4.1.tgz#85568de3cf150ff49fa51825f03a8c880ddcc5c4"