UNPKG

@localazy/strapi-plugin

Version:

The official Strapi Plugin by Localazy.

61 lines (60 loc) 1.46 kB
"use strict"; const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g; const htmlEntities = { "&amp;": "&", "&#38;": "&", "&lt;": "<", "&#60;": "<", "&gt;": ">", "&#62;": ">", "&apos;": "'", "&#39;": "'", "&quot;": '"', "&#34;": '"', "&nbsp;": " ", "&#160;": " ", "&copy;": "©", "&#169;": "©", "&reg;": "®", "&#174;": "®", "&hellip;": "…", "&#8230;": "…", "&#x2F;": "/", "&#47;": "/" }; const unescapeHtmlEntity = (m) => htmlEntities[m]; const unescape = (text) => text.replace(matchHtmlEntity, unescapeHtmlEntity); let defaultOptions = { bindI18n: "languageChanged", bindI18nStore: "", transEmptyNodeValue: "", transSupportBasicHtmlNodes: true, transWrapTextNodes: "", transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"], useSuspense: true, unescape }; const setDefaults = (options = {}) => { defaultOptions = { ...defaultOptions, ...options }; }; const getDefaults = () => defaultOptions; let i18nInstance; const setI18n = (instance) => { i18nInstance = instance; }; const getI18n = () => i18nInstance; const initReactI18next = { type: "3rdParty", init(instance) { setDefaults(instance.options.react); setI18n(instance); } }; exports.getDefaults = getDefaults; exports.getI18n = getI18n; exports.initReactI18next = initReactI18next; exports.setDefaults = setDefaults; exports.setI18n = setI18n;