Skip to content

Commit

Permalink
feat: Japanese DAISY Knowledge Base
Browse files Browse the repository at this point in the history
  • Loading branch information
danielweck committed Dec 2, 2024
1 parent b194b74 commit 3a942c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
9 changes: 6 additions & 3 deletions README_KB.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Source GitHub repository (master branch):
https://github.com/daisy/kb

Git submodule revision:
6df0f67cbd06706809366b088732c93c06212a2a
https://github.com/daisy/kb/commits/6df0f67cbd06706809366b088732c93c06212a2a
https://github.com/daisy/kb/compare/6df0f67cbd06706809366b088732c93c06212a2a...main
6b5d5d42fd7608f8a5387b51b0c0dea46d1fc1ea
https://github.com/daisy/kb/commits/6b5d5d42fd7608f8a5387b51b0c0dea46d1fc1ea
https://github.com/daisy/kb/compare/6b5d5d42fd7608f8a5387b51b0c0dea46d1fc1ea...main

PREVIOUS WAS:
https://github.com/daisy/kb/compare/6df0f67cbd06706809366b088732c93c06212a2a...6b5d5d42fd7608f8a5387b51b0c0dea46d1fc1ea
18 changes: 11 additions & 7 deletions src/main/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { BrowserWindow, webContents } = require('electron');
import { app, shell, session, ipcMain, Menu } from 'electron';

import { localizer } from './../shared/l10n/localize';
const { localize } = localizer;
const { localize, getCurrentLanguage } = localizer;

import * as AboutBoxHelper from './about';

Expand Down Expand Up @@ -471,9 +471,13 @@ export function startKnowledgeBaseServer(kbRootPath) {
// fileSystemPath = pn;
// if (LOG_DEBUG) console.log(`${KB_LOG_PREFIX} --filepath to read (corrected): ${fileSystemPath}`);
// if (!fs.existsSync(fileSystemPath)) {
if (LOG_DEBUG) console.log(`${KB_LOG_PREFIX} --FILE DOES NOT EXIST!! ${kbRootPath} + ${req.url} => ${fileSystemPath}`);
const html = `<h1><a href="javascript:window.history.back()">&lt;&lt;</a></h1><h2>${pn} (404 missing file?)</h2>`;
const buff = Buffer.from(html);
if (LOG_DEBUG) console.log(`${KB_LOG_PREFIX} --FILE DOES NOT EXIST!! ${kbRootPath} + ${req.url} => ${fileSystemPath} (${localize("kbgoonline")})`);
const html = `<html><head><meta charset="UTF-8" /></head><body><h1><a href="javascript:window.history.back()">&lt;&lt;</a></h1><h2> !! ${pn}</h2>
<div style="border-radius: 4px !important; border: 4px solid black !important; box-sizing: border-box; z-index: 9999999; position: fixed; left: 1em; width: auto; background: transparent; margin: 0; padding: 0; margin-top: 0.5em; font-size: 100%; font-weight: bold; font-family: sans-serif; border: 0">
<a style="user-select: none; color: red; background-color: white; padding: 0.2em;" target="_BLANK" href="${req.url.replace(`${rootUrl}/`, 'http://kb.daisy.org/')}">${localize("kbgoonline")}</a>
</div></body></html>
`;
const buff = Buffer.from(html, "utf-8");
headers["Content-Length"] = buff.length.toString();
headers["Content-Type"] = "text/html";
callback({
Expand Down Expand Up @@ -1008,7 +1012,7 @@ export class KnowledgeBase {
return { action: 'deny' };
}

if (obj.url.replace(/\/\/+/g, "/").indexOf("publishing/docs/search") >= 0) {
if (obj.url.replace(/\/\/+/g, "/").indexOf("publishing/docs/search") >= 0 || obj.url.replace(/\/\/+/g, "/").indexOf("publishing/ja/search") >= 0) {
shell.openExternal(obj.url.replace(rootUrl, "http://kb.daisy.org"));

// preventDefault()
Expand All @@ -1028,7 +1032,7 @@ export class KnowledgeBase {
event.preventDefault();
shell.openExternal(url);
}
if (url.replace(/\/\/+/g, "/").indexOf("publishing/docs/search") >= 0) {
if (url.replace(/\/\/+/g, "/").indexOf("publishing/docs/search") >= 0 || url.replace(/\/\/+/g, "/").indexOf("publishing/ja/search") >= 0) {
event.preventDefault();
shell.openExternal(url.replace(rootUrl, "http://kb.daisy.org"));
}
Expand All @@ -1038,7 +1042,7 @@ export class KnowledgeBase {
if (this.urlPath) {
this.win.loadURL(`${rootUrl}${this.urlPath}`);
} else {
this.win.loadURL(`${rootUrl}/publishing/docs/index.html`);
this.win.loadURL(`${rootUrl}/publishing/${getCurrentLanguage() === "ja" ? "ja" : "docs"}/index.html`);
}

this.win.on('closed', function () {
Expand Down
6 changes: 3 additions & 3 deletions src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class MenuBuilder {
runAceInRendererProcess(filepath) {
this.mainWindow.webContents.send('RUN_ACE', filepath);
}

buildTemplate() {

const defaultTemplate = {
Expand All @@ -103,7 +103,7 @@ export default class MenuBuilder {
await showEpubFileOrFolderBrowseDialog((filepath) => {
this.store.dispatch(closeReport());
this.store.dispatch(resetInitialReportView());

this.runAceInRendererProcess(filepath);
});
} else {
Expand Down Expand Up @@ -346,7 +346,7 @@ export default class MenuBuilder {
{
label: localize('menu.knowledgeBaseOnline'),
click: () => {
shell.openExternal('http://kb.daisy.org/publishing/docs/index.html');
shell.openExternal(`http://kb.daisy.org/publishing/${getCurrentLanguage() === "ja" ? "ja" : "docs"}/index.html`);
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/MetaDataEditorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {openFile} from './../../shared/actions/app';
import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';
import { localizer } from './../../shared/l10n/localize';
const { localize } = localizer; // setCurrentLanguage, getCurrentLanguage,
const { localize, getCurrentLanguage } = localizer; // setCurrentLanguage
import classNames from 'classnames';
import { ipcRenderer } from 'electron';
import {
Expand Down Expand Up @@ -191,12 +191,12 @@ class MetaDataEditorModal extends React.Component {
packageOpfXPathSelect = undefined;

onKBSchemaOrg = () => {
const url = `${KB_BASE}docs/metadata/schema.org/index.html`;
const url = `${KB_BASE}${getCurrentLanguage() === "ja" ? "ja" : "docs"}/metadata/schema.org/index.html`;
ipcRenderer.send('KB_URL', url);
// shell.openExternal(url);
}
onKBEvaluation = () => {
const url = `${KB_BASE}docs/metadata/evaluation.html`;
const url = `${KB_BASE}${getCurrentLanguage() === "ja" ? "ja" : "docs"}/metadata/evaluation.html`;
ipcRenderer.send('KB_URL', url);
// shell.openExternal(url);
}
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/components/ReportSections/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {selectTab} from './../../../shared/actions/reportView';
import {zipEpub} from './../../../shared/actions/app';

import { localizer } from './../../../shared/l10n/localize';
const { localize } = localizer;
const { localize, getCurrentLanguage } = localizer;

import a11yMetadata from '@daisy/ace-core/lib/core/a11y-metadata';

Expand Down Expand Up @@ -80,12 +80,12 @@ class Metadata extends React.Component {
};

onKBSchemaOrg = () => {
const url = `${KB_BASE}docs/metadata/schema.org/index.html`;
const url = `${KB_BASE}${getCurrentLanguage() === "ja" ? "ja" : "docs"}/metadata/schema.org/index.html`;
ipcRenderer.send('KB_URL', url);
// shell.openExternal(url);
}
onKBEvaluation = () => {
const url = `${KB_BASE}docs/metadata/evaluation.html`;
const url = `${KB_BASE}${getCurrentLanguage() === "ja" ? "ja" : "docs"}/metadata/evaluation.html`;
ipcRenderer.send('KB_URL', url);
// shell.openExternal(url);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ class Metadata extends React.Component {
suffix = ` (${A11Y_META[data].required ? localize("report.summarySection.serious") : localize("report.summarySection.moderate")})`
}
}

return (<li key={idx}>{data}{suffix}</li>);
})}
{a11ymetadata.empty && a11ymetadata.empty.sort().map((data, idx) => {
Expand All @@ -239,7 +239,7 @@ class Metadata extends React.Component {
suffix = ` (${A11Y_META[data].required ? localize("report.summarySection.serious") : localize("report.summarySection.moderate")})`
}
}

return (<li key={idx}>{data}{suffix}</li>);
})}
</ul>
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/ReportSections/Violations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TableCell from '@material-ui/core/TableCell';
const {ipcRenderer} = require('electron');

import { localizer } from './../../../shared/l10n/localize';
const { localize } = localizer;
const { localize, getCurrentLanguage } = localizer;

// the violations page of the report
export default class Violations extends React.Component {
Expand Down Expand Up @@ -115,8 +115,8 @@ export default class Violations extends React.Component {
href="#"
tabIndex={0}
className="external-link"
onKeyPress={(e) => { if (e.key === "Enter") { this.onExternalLinkClick(row.details.kburl); }}}
onClick={() => this.onExternalLinkClick(row.details.kburl)}
onKeyPress={(e) => { if (e.key === "Enter") { this.onExternalLinkClick(getCurrentLanguage() === "ja" ? row.details.kburl.replace(/\/docs\//, "/ja/") : row.details.kburl); }}}
onClick={() => this.onExternalLinkClick(getCurrentLanguage() === "ja" ? row.details.kburl.replace(/\/docs\//, "/ja/") : row.details.kburl)}
>{localize("report.violationsSection.learnAbout")} {row.details.kbtitle}</a></p>
</TableCell>
}
Expand Down

0 comments on commit 3a942c8

Please sign in to comment.