Removes timeago from i18n module.

This commit is contained in:
gaba
2017-04-25 11:43:04 -05:00
parent 59e23ffd60
commit 0f7b4ddaf6
5 changed files with 25 additions and 23 deletions
@@ -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 () {
+9 -20
View File
@@ -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;
+4 -1
View File
@@ -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}) => <div className={`${name }-text`}>
{lang.timeago(created_at)}
{timeago().format(created_at, lang.getLocale().replace('-', '_'))}
</div>;
export default PubDate;
+2 -1
View File
@@ -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",
+7
View File
@@ -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"