Skip to content

Commit

Permalink
working out a poc with the contextBridge to expose fs to the i18n bac…
Browse files Browse the repository at this point in the history
…kend module
  • Loading branch information
reZach committed Jan 5, 2020
1 parent 31d235e commit f9472df
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Expand Up @@ -9,7 +9,8 @@
"Components": "./app/src/components",
"Core": "./app/src/core",
"Pages": "./app/src/pages",
"Redux": "./app/src/redux"
"Redux": "./app/src/redux",
"I18n": "./app/localization"
}
}
]
Expand Down
12 changes: 12 additions & 0 deletions app/electron/preload.js
@@ -0,0 +1,12 @@
const { contextBridge } = require("electron");
const fs = require("fs");

console.log("ABC");
console.log(fs);

contextBridge.exposeInMainWorld(
"test",
{
fs: fs
}
);
36 changes: 36 additions & 0 deletions app/localization/i18n.config.js
@@ -0,0 +1,36 @@
import i18n from "i18next";
import {
initReactI18next
} from "react-i18next";
import i18nBackend from "i18next-node-fs-backend";

i18n
.use(i18nBackend)
.use(initReactI18next)
.init({
backend: {
loadPath: "./app/localization/locales/{{lng}}/{{ns}}.json",
addPath: "./app/localization/locales/{{lng}}/{{ns}}.missing.json",
jsonIndent: 2
},
debug: true,
namespace: "translation",
saveMissing: true,
saveMissingTo: "current",
fallbackLng: "en", // set to false when generating translation files locally
});

export default i18n;

// if (!i18n.isInitialized) {
// i18n.use(i18nextBackend).init(i18nextOptions).then(function () {
// i18n.changeLanguage(config.fallbackLng, (err) => {
// if (err) {
// return console.log("couldn't change language");
// }
// });
// return true;
// }).catch(function (err) {
// console.error(err);
// });
// }
4 changes: 3 additions & 1 deletion app/src/components/detail/detail.jsx
@@ -1,9 +1,11 @@
import React from "react";
import { useTranslation } from "react-i18next";

class Detail extends React.Component {
render() {
const { t } = useTranslation();
return <div>
(A sample of rendering a component)
{t("Detail.SampleText")}
</div>;
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/index.jsx
@@ -1,9 +1,13 @@
import React from "react";
import ReactDOM from "react-dom";
//import "I18n/i18n.config";
import Root from "Core/root";
import store, { history } from "Redux/store/store";

console.error(window);
console.error(window.test);

ReactDOM.render(
<Root store={store} history={history}></Root>,
document.getElementById("target")
);
);

0 comments on commit f9472df

Please sign in to comment.