From b0d07b0ef8c3c90e91065f4352f6b9403081ff09 Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Thu, 30 Sep 2021 08:44:27 +0200 Subject: [PATCH] Added mechanism for widgets to use built-in I18N --- src/i18n/index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/i18n/index.js b/src/i18n/index.js index 776ba54..ecf8bf6 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -1,4 +1,5 @@ import Polyglot from 'node-polyglot'; +import TimeAgo from 'timeago-react'; import * as timeago from 'timeago.js'; import messages_ar from './messages_ar.json'; @@ -83,4 +84,32 @@ timeago.register('pt', pt); timeago.register('sv', sv); timeago.register('tr', tr); +/** + * Helper function that allows plugins to register their + * own I18N labels + */ +i18n.registerMessages = dict => { + const currentLocale = i18n.locale(); + const messages = dict[currentLocale]; + + if (messages) + i18n.extend(messages); + else + console.warn(`Locale ${currentLocale} not supported by plugin widget - falling back to defaults`); +} + export default i18n; + +/** + * For convenience: exposes a pre-localized TimeAgo widget, + * for use in plugins + */ +export const LocalTimeAgo = props => { + + return ( + + ) + +} \ No newline at end of file