Web: Files: Added translation for EmbeddingPanel.

This commit is contained in:
TatianaLopaeva 2021-04-01 13:50:57 +03:00
parent 968e0009ee
commit 26fe94ae5f
2 changed files with 55 additions and 2 deletions

View File

@ -0,0 +1,44 @@
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { LANGUAGE } from "@appserver/common/constants";
import config from "../../../../package.json";
const homepage = config.homepage;
//import LanguageDetector from "i18next-browser-languagedetector";
// not like to use this?
// have a look at the Quick start guide
// for passing in lng and translations on init
const languages = ["en", "ru"];
const newInstance = i18n.createInstance();
newInstance.use(Backend).init({
lng: localStorage.getItem(LANGUAGE) || "en",
supportedLngs: languages,
whitelist: languages,
fallbackLng: "en",
load: "languageOnly",
//debug: true,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: function (value, format) {
if (format === "lowercase") return value.toLowerCase();
return value;
},
},
backend: {
loadPath: `${homepage}/locales/{{lng}}/EmbeddingPanel.json`,
},
ns: ["EmbeddingPanel"],
defaultNS: "EmbeddingPanel",
react: {
useSuspense: false,
},
});
export default newInstance;

View File

@ -9,7 +9,7 @@ import Link from "@appserver/components/link";
import TextInput from "@appserver/components/text-input"; import TextInput from "@appserver/components/text-input";
import Textarea from "@appserver/components/textarea"; import Textarea from "@appserver/components/textarea";
import toastr from "studio/toastr"; import toastr from "studio/toastr";
import { withTranslation } from "react-i18next"; import { withTranslation, I18nextProvider } from "react-i18next";
import { import {
StyledEmbeddingPanel, StyledEmbeddingPanel,
StyledContent, StyledContent,
@ -17,6 +17,7 @@ import {
StyledBody, StyledBody,
} from "../StyledPanels"; } from "../StyledPanels";
import copy from "copy-to-clipboard"; import copy from "copy-to-clipboard";
import i18n from "./i18n";
class EmbeddingPanelComponent extends React.Component { class EmbeddingPanelComponent extends React.Component {
constructor(props) { constructor(props) {
@ -215,4 +216,12 @@ EmbeddingPanelComponent.propTypes = {
onClose: PropTypes.func, onClose: PropTypes.func,
}; };
export default withTranslation("EmbeddingPanel")(EmbeddingPanelComponent); const EmbeddingPanel = withTranslation("EmbeddingPanel")(
EmbeddingPanelComponent
);
export default (props) => (
<I18nextProvider i18n={i18n}>
<EmbeddingPanel {...props} />
</I18nextProvider>
);