mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 23:26:19 +08:00
Fix timeago with lang.
This commit is contained in:
@@ -14,7 +14,7 @@ import BanUserButton from 'coral-admin/src/components/BanUserButton';
|
||||
|
||||
const linkify = new Linkify();
|
||||
|
||||
import {t, timeago} from 'coral-i18n/services/i18n';
|
||||
import {t, timeAgo} from 'coral-i18n/services/i18n';
|
||||
|
||||
const Comment = ({
|
||||
actions = [],
|
||||
@@ -57,7 +57,7 @@ const Comment = ({
|
||||
{comment.user.name}
|
||||
</span>
|
||||
<span className={styles.created}>
|
||||
{timeago(comment.created_at || Date.now() - props.index * 60 * 1000)}
|
||||
{timeAgo(comment.created_at || Date.now() - props.index * 60 * 1000)}
|
||||
</span>
|
||||
<BanUserButton
|
||||
user={comment.user}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {updateOpenStatus, updateConfiguration} from 'coral-framework/actions/ass
|
||||
import CloseCommentsInfo from '../components/CloseCommentsInfo';
|
||||
import ConfigureCommentStream from '../components/ConfigureCommentStream';
|
||||
|
||||
import {t, timeago} from 'coral-i18n/services/i18n';
|
||||
import {t, timeAgo} from 'coral-i18n/services/i18n';
|
||||
|
||||
class ConfigureStreamContainer extends Component {
|
||||
constructor (props) {
|
||||
@@ -86,7 +86,7 @@ class ConfigureStreamContainer extends Component {
|
||||
const {closedTimeout} = this.props.asset.settings;
|
||||
const {created_at} = this.props.asset;
|
||||
|
||||
return timeago(new Date(created_at).getTime() + (1000 * closedTimeout));
|
||||
return timeAgo(new Date(created_at).getTime() + (1000 * closedTimeout));
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
const time = require('timeago.js');
|
||||
const has = require('lodash/has');
|
||||
const get = require('lodash/get');
|
||||
|
||||
const esTA = require('../../../node_modules/timeago.js/locales/es');
|
||||
|
||||
const defaultLanguage = 'en';
|
||||
|
||||
let translations = {};
|
||||
|
||||
// Add es timeago locale for the timeago registration.
|
||||
time.register('es', esTA);
|
||||
let timeagoInstance = time();
|
||||
|
||||
const fetchTranslations = (locale) => {
|
||||
translations = require(`json-loader!yaml-loader!../locales/${locale}.yml`)[locale];
|
||||
};
|
||||
@@ -24,8 +31,11 @@ export const loadTranslations = (translations) => {
|
||||
const locale = getLocale();
|
||||
setLocale(locale);
|
||||
|
||||
// If we have a translations file, let's use that one.
|
||||
// Otherwise get the core translations.
|
||||
if (translations !== undefined) {
|
||||
translations = translations[locale];
|
||||
return translations;
|
||||
}
|
||||
|
||||
return fetchTranslations(locale);
|
||||
@@ -36,7 +46,9 @@ export const loadTranslations = (translations) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const timeago = (date) => timeago().format(date, getLocale().replace('-', '_'));
|
||||
export const timeago = (time) => {
|
||||
return timeagoInstance.format(new Date(time), getLocale());
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose the translation function
|
||||
|
||||
@@ -98,7 +98,7 @@ export class BestButton extends Component {
|
||||
<button onClick={isBest ? this.onClickRemoveBest : this.onClickAddBest}
|
||||
disabled={disabled}
|
||||
className={classnames(`${name}-button`, `e2e__${isBest ? 'unset' : 'set'}-best-comment`)}
|
||||
aria-label={t(isBest ? 'unsetBest' : 'setBest')}>
|
||||
aria-label={t(isBest ? 'unset_best' : 'set_best')}>
|
||||
<Icon name={ isBest ? 'star' : 'star_border' } />
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import timeago from 'coral-i18n/services/i18n';
|
||||
import {timeago} from 'coral-i18n/services/i18n';
|
||||
|
||||
const name = 'coral-plugin-pubdate';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"respected": "Respected"
|
||||
},
|
||||
"es": {
|
||||
"respect": "Respeto",
|
||||
"respect": "Respetar",
|
||||
"respected": "Respetado"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user