Skip to content

Commit

Permalink
fix for windows path problem
Browse files Browse the repository at this point in the history
  • Loading branch information
danielc-n committed Oct 25, 2024
1 parent e4ad641 commit 9496789
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
54 changes: 32 additions & 22 deletions renderer/src/components/EditorPage/Reference/TranslationHelps.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const TranslationHelps = ({

const [resourceLinkPath, setResourceLinkPath] = useState('');
const [imagesPath, setImagesPath] = useState('');
const [metadata, setMetadata] = useState(null);

useEffect(() => {
async function getLinkedFolderPath() {
Expand All @@ -45,19 +46,24 @@ const TranslationHelps = ({
const newpath = localStorage.getItem('userPath');
const userProfile = await localforage.getItem('userProfile');
const resourceDirPath = path.join(newpath, packageInfo.name, 'users', userProfile?.username, 'resources');
const pathToIngredients = path.resolve(resourceDirPath, offlineResource.data.projectDir, 'ingredients');
const pathToIngredients = path.join(resourceDirPath, offlineResource.data.projectDir, 'ingredients');
const metadataPath = path.join(resourceDirPath, offlineResource.data.projectDir, 'metadata.json');
if (pathToIngredients) {
const pathRelationFile = path.resolve(pathToIngredients, 'relation.txt');
const pathRelationFile = path.join(pathToIngredients, 'relation.txt');
if (fs.existsSync(pathRelationFile)) {
setImagesPath(pathToIngredients);
const relationFileContent = fs.readFileSync(pathRelationFile, 'utf8');
const fileName = findFileByPartialName(fs, path.resolve(resourceDirPath), relationFileContent.trim());
setResourceLinkPath(path.resolve(resourceDirPath, fileName, 'ingredients'));
const fileName = findFileByPartialName(fs, path.join(resourceDirPath), relationFileContent.trim());
setResourceLinkPath(path.join(resourceDirPath, fileName, 'ingredients'));
} else {
setImagesPath('');
setResourceLinkPath(pathToIngredients);
debug('TranslationHelps.js', `pathRelationFile : ${pathRelationFile} - Not found!`);
}
if (fs.existsSync(metadataPath)) {
const metadataContent = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
setMetadata(metadataContent);
}
}
} catch (e) {
debug('TranslationHelps.js', `Error : ${e}`);
Expand Down Expand Up @@ -90,24 +96,28 @@ const TranslationHelps = ({
/>
);
case 'tir':
return (
<TranslationHelpsMultimediaCard
title={t('label-resource-tir')}
verse={verse}
chapter={chapter}
projectId={bookId.toUpperCase() || 'mat'.toUpperCase()}
branch={branch}
languageId={languageId}
resourceId="tir"
owner={owner}
server="https://git.door43.org"
offlineResource={offlineResource}
font={font}
fontSize={fontSize}
folderPath={resourceLinkPath}
linkedFolderPath={imagesPath}
/>
);
if (resourceLinkPath !== '' && metadata !== null) {
return (
<TranslationHelpsMultimediaCard
title={t('label-resource-tir')}
verse={verse}
chapter={chapter}
projectId={bookId.toUpperCase() || 'mat'.toUpperCase()}
branch={branch}
languageId={languageId}
resourceId="tir"
owner={owner}
server="https://git.door43.org"
offlineResource={offlineResource}
font={font}
fontSize={fontSize}
folderPath={resourceLinkPath}
linkedFolderPath={imagesPath}
metadata={metadata}
/>
);
}
break;
// case 'twl':
// return (
// <TranslationHelpsCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function TranslationHelpsMultimediaCard({
projectId,
folderPath,
linkedFolderPath,
metadata,
}) {
const [imagePaths, setImagePaths] = useState([]);

Expand Down Expand Up @@ -63,28 +64,24 @@ export default function TranslationHelpsMultimediaCard({
// Split the content into lines
const lines = fileContent.trim().split('\n');

let metadataJson;
let columns;
let realPath;
let dashedName;
let dashedNameSplited;
let localizedNameTmp;
if (linkedFolderPath === '') {
metadataJson = JSON.parse(fs.readFileSync(path.join(folderPath, '..', 'metadata.json')));
// Loop through each line, starting from 1 to skip the header
for (let i = 1; i < lines.length; i++) {
columns = lines[i].split('\t');
// Check if the reference matches
if (columns[0] === reference) {
// Add the last column (image path) to the list
dashedName = columns[columns.length - 1].split('/').at(-1).split('.')[0];
localizedNameTmp = metadataJson.localizedNames[dashedName]?.short[i18n.language] ?? '';
localizedNameTmp = metadata.localizedNames[dashedName]?.short[i18n.language] ?? '';
finalImagePaths.push([localizedNameTmp, columns[columns.length - 1]]);
}
}
} else {
metadataJson = JSON.parse(fs.readFileSync(path.join(linkedFolderPath, '..', 'metadata.json')));

let tabName
// Loop through each line, starting from 1 to skip the header
for (let i = 1; i < lines.length; i++) {
Expand All @@ -95,7 +92,7 @@ export default function TranslationHelpsMultimediaCard({
// Add the last column (image path) to the list
dashedName = columns[columns.length - 1].split('images/')[1];
dashedNameSplited = dashedName.split('/').at(-1);
localizedNameTmp = metadataJson.localizedNames[dashedNameSplited];
localizedNameTmp = metadata.localizedNames[dashedNameSplited];
realPath = convertToFileUrl(path.join(linkedFolderPath, `${dashedName}.jpg`));
if(dashedName.split('.').at(-1) !== 'jpg') {
realPath = convertToFileUrl(path.join(linkedFolderPath, `${dashedName}.jpg`));
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/components/EditorPage/TextEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default function TextEditor() {
const {
state: {
bookId: defaultBookId, selectedFont, editorFontSize, projectScriptureDir,
chapter,
verse,
// chapter,
// verse,
},
actions: {
handleSelectedFont, onChangeChapter, onChangeVerse, handleEditorFontSize,
Expand Down

0 comments on commit 9496789

Please sign in to comment.