mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-02 02:41:34 +08:00
electron: Solve server translation loading on macOS
This commit is contained in:
parent
e7378306a2
commit
849a6a3aef
@ -10,7 +10,13 @@ module.exports = {
|
|||||||
overwrite: true,
|
overwrite: true,
|
||||||
asar: true,
|
asar: true,
|
||||||
icon: "./images/app-icons/icon",
|
icon: "./images/app-icons/icon",
|
||||||
extraResource: getExtraResourcesForPlatform(),
|
extraResource: [
|
||||||
|
// Moved to root
|
||||||
|
...getExtraResourcesForPlatform(),
|
||||||
|
|
||||||
|
// Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS)
|
||||||
|
"translations/"
|
||||||
|
],
|
||||||
afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => {
|
afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => {
|
||||||
const extraResources = getExtraResourcesForPlatform();
|
const extraResources = getExtraResourcesForPlatform();
|
||||||
for (const resource of extraResources) {
|
for (const resource of extraResources) {
|
||||||
@ -77,8 +83,7 @@ module.exports = {
|
|||||||
function getExtraResourcesForPlatform() {
|
function getExtraResourcesForPlatform() {
|
||||||
let resources = [
|
let resources = [
|
||||||
'dump-db/',
|
'dump-db/',
|
||||||
'./bin/tpl/anonymize-database.sql',
|
'./bin/tpl/anonymize-database.sql'
|
||||||
'translations/'
|
|
||||||
];
|
];
|
||||||
const scripts = ['trilium-portable', 'trilium-safe-mode', 'trilium-no-cert-check']
|
const scripts = ['trilium-portable', 'trilium-safe-mode', 'trilium-no-cert-check']
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
|
@ -2,19 +2,34 @@ import i18next from "i18next";
|
|||||||
import Backend from "i18next-fs-backend";
|
import Backend from "i18next-fs-backend";
|
||||||
import options from "./options.js";
|
import options from "./options.js";
|
||||||
import sql_init from "./sql_init.js";
|
import sql_init from "./sql_init.js";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { dirname, join } from "path";
|
||||||
|
import utils from "./utils.js";
|
||||||
|
import env from "./env.js";
|
||||||
|
|
||||||
export async function initializeTranslations() {
|
export async function initializeTranslations() {
|
||||||
|
const resourceDir = getResourceDir();
|
||||||
|
|
||||||
// Initialize translations
|
// Initialize translations
|
||||||
await i18next.use(Backend).init({
|
await i18next.use(Backend).init({
|
||||||
lng: getCurrentLanguage(),
|
lng: getCurrentLanguage(),
|
||||||
fallbackLng: "en",
|
fallbackLng: "en",
|
||||||
ns: "server",
|
ns: "server",
|
||||||
|
debug: true,
|
||||||
backend: {
|
backend: {
|
||||||
loadPath: "translations/{{lng}}/{{ns}}.json"
|
loadPath: join(resourceDir, "translations/{{lng}}/{{ns}}.json")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getResourceDir() {
|
||||||
|
if (utils.isElectron() && !env.isDev()) {
|
||||||
|
return process.resourcesPath;
|
||||||
|
} else {
|
||||||
|
return join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getCurrentLanguage() {
|
function getCurrentLanguage() {
|
||||||
let language;
|
let language;
|
||||||
if (sql_init.isDbInitialized()) {
|
if (sql_init.isDbInitialized()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user