From d9358eb80b160f06d8dc3223cca08fe1f209f114 Mon Sep 17 00:00:00 2001 From: raffazizzi Date: Tue, 23 Jul 2024 09:48:43 -0400 Subject: [PATCH] better handling of language selection when interacting with TEIGarage API. Fixes #154 --- src/actions/index.js | 5 +++-- src/components/DownloadButton.js | 2 +- src/containers/Download.js | 4 ++-- src/containers/HomePage.js | 2 +- src/containers/SettingsPage.js | 4 ++-- src/reducers/index.js | 2 +- src/utils/teigarage.js | 28 +++++++++++++++------------- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index 7ff6ac6..0c7bc9e 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -91,10 +91,11 @@ export function exportOdd() { } } -export function exportSchema(format) { +export function exportSchema(format, lang) { return { type: EXPORT_SCHEMA, - format + format, + lang } } diff --git a/src/components/DownloadButton.js b/src/components/DownloadButton.js index 18e44f6..0d72a9d 100644 --- a/src/components/DownloadButton.js +++ b/src/components/DownloadButton.js @@ -34,7 +34,7 @@ export default class DownloadButton extends Component { infoHeader: i18n('Generating the Customization'), infoBody: i18n('geninfo') }) - this.props.downloadSchema(format) + this.props.downloadSchema(format, this.props.language) } } diff --git a/src/containers/Download.js b/src/containers/Download.js index 8838bb3..1073859 100644 --- a/src/containers/Download.js +++ b/src/containers/Download.js @@ -24,10 +24,10 @@ const mapDispatchToProps = (dispatch) => { // you don't want it to fire before the customization update is completed. dispatch(exportOdd()) }, - downloadSchema: (type) => { + downloadSchema: (type, lang) => { console.log(type) dispatch(updateCustomizationOdd()) - dispatch(exportSchema(type)) + dispatch(exportSchema(type, lang)) } } } diff --git a/src/containers/HomePage.js b/src/containers/HomePage.js index c6ec5cf..922f27d 100644 --- a/src/containers/HomePage.js +++ b/src/containers/HomePage.js @@ -24,7 +24,7 @@ const mapDispatchToProps = (dispatch) => { dispatch(fetchOdd(url)).then((odd) => { // 1. Convert to JSON via TEIGarage dispatch(setLoadingStatus(i18n('2/3 Importing customization ODD...'))) - dispatch(postToTEIGarage(odd.xml, teigarage.compile_json)).then(() => { + dispatch(postToTEIGarage(odd.xml, teigarage.compile_json(lang))).then(() => { dispatch(setLoadingStatus(i18n('3/3 Importing full specification source...'))) // 2. Get p5subset. dispatch(fetchLocalSource(`${datasource}/p5subset.json`)) diff --git a/src/containers/SettingsPage.js b/src/containers/SettingsPage.js index b621361..cf69161 100644 --- a/src/containers/SettingsPage.js +++ b/src/containers/SettingsPage.js @@ -79,8 +79,8 @@ const mapDispatchToProps = (dispatch) => { } }, getNewDocForLang: (data, lang) => { - dispatch(compileWithTEIGarage(data, teigarage['compiled.odd'])).then((compiledOdd) => { - dispatch(postToTEIGarage(compiledOdd, teigarage.json.replace('%3Een%3C', `%3E${lang}%3C`))) + dispatch(compileWithTEIGarage(data, teigarage['compiled.odd'](lang))).then((compiledOdd) => { + dispatch(postToTEIGarage(compiledOdd, teigarage.json(lang))) }) } } diff --git a/src/reducers/index.js b/src/reducers/index.js index db2011e..557e82d 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -202,7 +202,7 @@ function odd(state = {}, action) { try { filename = state.customization.settings.filename } catch (e) { e } - postToTEIGarage(state.customization.updatedXml, teigarage[action.format]) + postToTEIGarage(state.customization.updatedXml, teigarage[action.format](action.lang)) .then((res) => { const ext = action.format !== 'rnc' ? action.format : 'zip' fileSaver.saveAs(new Blob([res], {'type': 'text\/xml'}), `${filename}.${ext}`) diff --git a/src/utils/teigarage.js b/src/utils/teigarage.js index 7596626..30ebb30 100644 --- a/src/utils/teigarage.js +++ b/src/utils/teigarage.js @@ -1,17 +1,19 @@ import { TEIGARAGE_LOCATION, TEIGARAGE_PROTOCOL } from './urls' +const defaultLang = 'en' + export default { - compile_json: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/oddjson%3Aapplication%3Ajson/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - json: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODDC%3Atext%3Axml/oddjson%3Aapplication%3Ajson/conversion?properties=%3Cconversions%3E%3Cconversion%20index%3D%220%22%3E%3Cproperty%20id%3D%22oxgarage.getImages%22%3Efalse%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.getOnlineImages%22%3Efalse%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.lang%22%3Een%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.textOnly%22%3Etrue%3C%2Fproperty%3E%3Cproperty%20id%3D%22pl.psnc.dl.ege.tei.profileNames%22%3Edefault%3C%2Fproperty%3E%3C%2Fconversion%3E%3C%2Fconversions%3E%22`, - rng: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/relaxng%3Aapplication%3Axml-relaxng/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - rnc: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/rnc%3Aapplication%3Arelaxng-compact/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - w3c: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/xsd%3Aapplication%3Axml-xsd/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - dtd: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/dtd%3Aapplication%3Axml-dtd/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - isosch: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/isosch%3Atext%3Axml/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - 'compiled.odd': `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/conversion?properties=falsefalseentruedefault`, - html: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/xhtml%3Aapplication%3Axhtml%2Bxml/conversion?properties=falsefalseenfalsedefaultfalsefalseenfalsedefault`, - tei: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/conversion?properties=falsefalseentruedefaultfalsefalseentruedefault`, - docx: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/docx%3Aapplication%3Avnd.openxmlformats-officedocument.wordprocessingml.document/conversion?properties=falsefalseentruedefaultfalsefalseentruedefaultfalsefalseentruedefault`, - latex: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/latex%3Aapplication%3Ax-latex/conversion?properties=falsefalseentruedefaultfalsefalseentruedefaultfalsefalseentruedefault`, - pdf: `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/odt%3Aapplication%3Avnd.oasis.opendocument.text/pdf%3Aapplication%3Apdf/conversion?properties=truetrueenfalsedefaulttruetrueenfalsedefault` + compile_json: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/oddjson%3Aapplication%3Ajson/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + json: () => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODDC%3Atext%3Axml/oddjson%3Aapplication%3Ajson/conversion?properties=%3Cconversions%3E%3Cconversion%20index%3D%220%22%3E%3Cproperty%20id%3D%22oxgarage.getImages%22%3Efalse%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.getOnlineImages%22%3Efalse%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.lang%22%3Een%3C%2Fproperty%3E%3Cproperty%20id%3D%22oxgarage.textOnly%22%3Etrue%3C%2Fproperty%3E%3Cproperty%20id%3D%22pl.psnc.dl.ege.tei.profileNames%22%3Edefault%3C%2Fproperty%3E%3C%2Fconversion%3E%3C%2Fconversions%3E%22`, + rng: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/relaxng%3Aapplication%3Axml-relaxng/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + rnc: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/rnc%3Aapplication%3Arelaxng-compact/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + w3c: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/xsd%3Aapplication%3Axml-xsd/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + dtd: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/dtd%3Aapplication%3Axml-dtd/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + isosch: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/isosch%3Atext%3Axml/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + 'compiled.odd': (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/conversion?properties=falsefalse${lang}truedefault`, + html: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/xhtml%3Aapplication%3Axhtml%2Bxml/conversion?properties=falsefalse${lang}falsedefaultfalsefalse${lang}falsedefault`, + tei: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + docx: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/docx%3Aapplication%3Avnd.openxmlformats-officedocument.wordprocessingml.document/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + latex: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/latex%3Aapplication%3Ax-latex/conversion?properties=falsefalse${lang}truedefaultfalsefalse${lang}truedefaultfalsefalse${lang}truedefault`, + pdf: (lang = defaultLang) => `${TEIGARAGE_PROTOCOL}://${TEIGARAGE_LOCATION}/ege-webservice/Conversions/ODD%3Atext%3Axml/ODDC%3Atext%3Axml/TEI%3Atext%3Axml/odt%3Aapplication%3Avnd.oasis.opendocument.text/pdf%3Aapplication%3Apdf/conversion?properties=truetrue${lang}falsedefaulttruetrue${lang}falsedefault` }