Fix translation keys.

This commit is contained in:
gaba
2017-05-18 15:14:37 -07:00
parent 9e954f0ae3
commit 3ca22bd101
5 changed files with 24 additions and 11 deletions
@@ -7,8 +7,8 @@ const shortcuts = [
{
title: 'modqueue.navigation',
shortcuts: {
'j': 'modqueue.nextcomment',
'k': 'modqueue.prevcomment',
'j': 'modqueue.next_comment',
'k': 'modqueue.prev_comment',
's': 'modqueue.singleview',
'?': 'modqueue.thismenu'
}
@@ -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 () {
@@ -108,7 +108,7 @@ class ConfigureStreamContainer extends Component {
/>
<hr />
<h3>{closedAt === 'open' ? 'Close' : 'Open'} {t('configure.comment_stream')}</h3>
{(closedAt === 'open' && closedTimeout) ? <p>{t('configure.comment_stream_will_close')} {this.getClosedIn()}.</p> : ''}
{(closedAt === 'open' && closedTimeout) ? <p>{t('configure.comment_stream_will_close')} {this.getClosedIn()}.</p> : ''}
<CloseCommentsInfo
onClick={this.toggleStatus}
status={closedAt}
+16 -3
View File
@@ -8,6 +8,7 @@ const defaultLanguage = 'en';
let translations = {};
// ToDo: Get this into the load translations to not load everything the whole time ->>
// Add es timeago locale for the timeago registration.
time.register('es', esTA);
let timeagoInstance = time();
@@ -26,15 +27,26 @@ const setLocale = (locale) => {
const getLocale = () => (localStorage.getItem('locale') || navigator.language || defaultLanguage).split('-')[0];
export const loadTranslations = (translations) => {
const extend = (obj, src) => {
for (let key in src) {
if (src.hasOwnProperty(key)) {
obj[key] = src[key];
}
}
return obj;
};
export const loadTranslations = (new_translations) => {
try {
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];
if (new_translations !== undefined) {
translations = extend(translations, new_translations[locale]);
return translations;
}
@@ -60,6 +72,7 @@ export const timeago = (time) => {
* any extra parameters are optional and replace a variable marked by {0}, {1}, etc in the translation.
*/
const t = (key, ...replacements) => {
if (has(translations, key)) {
let translation = get(translations, key);
+1 -1
View File
@@ -3,7 +3,7 @@ import RespectButton from './containers/RespectButton';
import translations from './translations.json';
import {loadTranslations} from 'coral-i18n/services/i18n';
Promise.all([loadTranslations(translations)]);
loadTranslations(translations);
export default {
slots: {