0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/apps/sodo-search/src/index.js
Cathy Sarisky 2a2d7bb9ad
Added i18n support to search - ready for translator work! (#21055)
ref https://github.com/TryGhost/Ghost/issues/16628

This adds translation support to search, which should be the last missing piece of i18n support for Ghost's frontend  🎉
- Translation (t) helper added to sodo-search.
- Ghost head tweaked to include data-locale.
- All (I hope) strings in sodo-search wrapped in the t helper.
- Possibly poor-quality French translation strings added.

---------

Co-authored-by: Vikas Potluri <vikaspotluri123.github@gmail.com>
2024-09-24 12:39:32 +01:00

48 lines
1.2 KiB
JavaScript

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
const ROOT_DIV_ID = 'sodo-search-root';
function addRootDiv() {
const elem = document.createElement('div');
elem.id = ROOT_DIV_ID;
document.body.appendChild(elem);
}
function getSiteData() {
/**
* @type {HTMLElement}
*/
const scriptTag = document.querySelector('script[data-sodo-search]');
if (scriptTag) {
const adminUrl = scriptTag.dataset.sodoSearch;
const apiKey = scriptTag.dataset.key;
const stylesUrl = scriptTag.dataset.styles;
const locale = scriptTag.dataset.locale || 'en';
return {adminUrl, apiKey, stylesUrl, locale};
}
return {};
}
function setup() {
addRootDiv();
}
function init() {
const {adminUrl, apiKey, stylesUrl, locale} = getSiteData();
const adminBaseUrl = (adminUrl || window.location.origin)?.replace(/\/+$/, '');
setup();
ReactDOM.render(
<React.StrictMode>
<App
adminUrl={adminBaseUrl} apiKey={apiKey}
stylesUrl={stylesUrl} locale={locale}
/>
</React.StrictMode>,
document.getElementById(ROOT_DIV_ID)
);
}
init();