mirror of
https://github.com/wassname/talk.git
synced 2026-07-19 11:28:50 +08:00
Change to declarative API for plugins
This commit is contained in:
@@ -88,3 +88,9 @@ export function getGraphQLExtensions() {
|
||||
.filter((o) => o);
|
||||
}
|
||||
|
||||
export function getTranslations() {
|
||||
return plugins
|
||||
.map((o) => o.module.translations)
|
||||
.filter((o) => o);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import merge from 'lodash/merge';
|
||||
import esTA from '../../../node_modules/timeago.js/locales/es';
|
||||
import en from '../../../locales/en.yml';
|
||||
import es from '../../../locales/es.yml';
|
||||
import * as plugins from '../helpers/plugins';
|
||||
|
||||
// Translations are happening at https://www.transifex.com/the-coral-project/talk-1/dashboard/.
|
||||
|
||||
@@ -14,6 +15,7 @@ const translations = {...en, ...es};
|
||||
|
||||
let lang;
|
||||
let timeagoInstance;
|
||||
let loadedPluginsTranslations = false;
|
||||
|
||||
function setLocale(locale) {
|
||||
try {
|
||||
@@ -43,6 +45,10 @@ function init() {
|
||||
timeagoInstance = ta();
|
||||
}
|
||||
|
||||
function loadPluginsTranslations() {
|
||||
plugins.getTranslations().forEach((t) => loadTranslations(t));
|
||||
}
|
||||
|
||||
export function loadTranslations(newTranslations) {
|
||||
merge(translations, newTranslations);
|
||||
}
|
||||
@@ -61,6 +67,10 @@ export function timeago(time) {
|
||||
* any extra parameters are optional and replace a variable marked by {0}, {1}, etc in the translation.
|
||||
*/
|
||||
export function t(key, ...replacements) {
|
||||
if (!loadedPluginsTranslations) {
|
||||
loadPluginsTranslations();
|
||||
loadedPluginsTranslations = true;
|
||||
}
|
||||
const fullKey = `${lang}.${key}`;
|
||||
if (has(translations, fullKey)) {
|
||||
let translation = get(translations, fullKey);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import LikeButton from './containers/LikeButton';
|
||||
|
||||
import translations from './translations.json';
|
||||
import {loadTranslations} from '/coral-framework/services/i18n';
|
||||
|
||||
loadTranslations(translations);
|
||||
|
||||
export default {
|
||||
translations,
|
||||
slots: {
|
||||
commentReactions: [LikeButton]
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import LoveButton from './LoveButton';
|
||||
|
||||
import translations from './translations.json';
|
||||
import {loadTranslations} from '/coral-framework/services/i18n';
|
||||
|
||||
loadTranslations(translations);
|
||||
|
||||
export default {
|
||||
translations,
|
||||
slots: {
|
||||
commentReactions: [LoveButton]
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import OffTopicCheckbox from './components/OffTopicCheckbox';
|
||||
import OffTopicTag from './components/OffTopicTag';
|
||||
import translations from './translations.json';
|
||||
import {loadTranslations} from 'coral-framework/services/i18n';
|
||||
|
||||
loadTranslations(translations);
|
||||
|
||||
export default {
|
||||
translations,
|
||||
slots: {
|
||||
commentInputDetailArea: [OffTopicCheckbox],
|
||||
commentInfoBar: [OffTopicTag]
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import RespectButton from './containers/RespectButton';
|
||||
|
||||
import translations from './translations.json';
|
||||
import {loadTranslations} from 'coral-framework/services/i18n';
|
||||
|
||||
loadTranslations(translations);
|
||||
|
||||
export default {
|
||||
translations,
|
||||
slots: {
|
||||
commentActions: [RespectButton],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user