diff --git a/README.md b/README.md index cc3d759..430ee36 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ You can apply three different types of emphasis to the data: ### Additional Notes +- The language code (`\lg`) is not displayed. It is merely used to set the `lang` attribute on elements where appropriate. To display the language of an utterance, use the metadata field (`\#`). - The speaker (`\sp`) and source (`\s`) data are combined into a single element strutured as follows: `
{speaker} ({source})
`. - Notes fields (`\n`) are not added to the HTML by default. - Individual glosses receive the `.gl` class. diff --git a/package-lock.json b/package-lock.json index da5adda..1602749 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "devDependencies": { "@digitallinguistics/eslint-config": "^0.3.0", - "@digitallinguistics/scription2dlx": "^0.13.2", + "@digitallinguistics/scription2dlx": "^0.14.0", "@digitallinguistics/styles": "^2.0.3", "@web/parse5-utils": "^2.0.2", "chai": "^4.3.10", @@ -46,10 +46,11 @@ } }, "node_modules/@digitallinguistics/scription2dlx": { - "version": "0.13.2", - "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.13.2.tgz", - "integrity": "sha512-2oXYgHGjkjOhmZ07jF5J3bPweUobvP7PDruGH4Fr0eUTDQAZBE0hVRKOMW3SuUMFrtbQmL9wUPd53aF4jDdLcQ==", - "dev": true + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.14.0.tgz", + "integrity": "sha512-9/S6LBJ/7e0sVDrpFj5JFDRy8/nJ24HkW0Tdfg8V7UfvN9qcc2/qS0x0Klhfr/MO+c7C4ksg37YFwWHTXOgl7w==", + "dev": true, + "license": "MIT" }, "node_modules/@digitallinguistics/styles": { "version": "2.0.3", @@ -2514,9 +2515,9 @@ "requires": {} }, "@digitallinguistics/scription2dlx": { - "version": "0.13.2", - "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.13.2.tgz", - "integrity": "sha512-2oXYgHGjkjOhmZ07jF5J3bPweUobvP7PDruGH4Fr0eUTDQAZBE0hVRKOMW3SuUMFrtbQmL9wUPd53aF4jDdLcQ==", + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.14.0.tgz", + "integrity": "sha512-9/S6LBJ/7e0sVDrpFj5JFDRy8/nJ24HkW0Tdfg8V7UfvN9qcc2/qS0x0Klhfr/MO+c7C4ksg37YFwWHTXOgl7w==", "dev": true }, "@digitallinguistics/styles": { diff --git a/package.json b/package.json index d18ce76..2965a39 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "devDependencies": { "@digitallinguistics/eslint-config": "^0.3.0", - "@digitallinguistics/scription2dlx": "^0.13.2", + "@digitallinguistics/scription2dlx": "^0.14.0", "@digitallinguistics/styles": "^2.0.3", "@web/parse5-utils": "^2.0.2", "chai": "^4.3.10", diff --git a/src/utterance/index.js b/src/utterance/index.js index 7ae9cb0..cfa2550 100644 --- a/src/utterance/index.js +++ b/src/utterance/index.js @@ -10,8 +10,11 @@ import createWords from '../words/index.js' export default function convertUtterance(u, options) { + const { id, language } = u + + options.language = language + const header = createHeader(u.metadata, options) - const { id } = u const literal = createLiteral(u.literal, options) const phonetic = createPhonetic(u.phonetic, options) const source = createSource(u.speaker, u.source) diff --git a/src/utterance/phonetic.js b/src/utterance/phonetic.js index cd7c136..a271bec 100644 --- a/src/utterance/phonetic.js +++ b/src/utterance/phonetic.js @@ -1,8 +1,14 @@ import addEmphasis from '../utilities/addEmphasis.js' -export default function createPhonetic(phonetic, { targetLang }) { +export default function createPhonetic(phonetic, { language, targetLang }) { + if (!phonetic) return `` - const lang = targetLang ? `lang='${ targetLang }-fonipa'` : `` + + let lang = `` + + if (language || targetLang) lang = `lang='${language || targetLang }-fonipa'` + // NB: Don't add phonetic brackets. These can be added with CSS. return `${ addEmphasis(phonetic) }
` + } diff --git a/src/utterance/transcript.js b/src/utterance/transcript.js index 11a2763..3809e56 100644 --- a/src/utterance/transcript.js +++ b/src/utterance/transcript.js @@ -1,6 +1,6 @@ import addEmphasis from '../utilities/addEmphasis.js' -export default function createTranscript(data, { targetLang }) { +export default function createTranscript(data, { language, targetLang }) { if (!data) return `` @@ -8,7 +8,7 @@ export default function createTranscript(data, { targetLang }) { for (const ortho in data) { const transcript = data[ortho] - const lang = targetLang ? `lang='${ targetLang }'` : `` + const lang = (language ?? targetLang) ? `lang='${ language ?? targetLang }'` : `` html += `${ addEmphasis(transcript) }
` } diff --git a/src/utterance/transcription.js b/src/utterance/transcription.js index 4f6459e..e136dfd 100644 --- a/src/utterance/transcription.js +++ b/src/utterance/transcription.js @@ -1,10 +1,10 @@ import addEmphasis from '../utilities/addEmphasis.js' -export default function createTranscription(data, { targetLang }) { +export default function createTranscription(data, { language, targetLang }) { if (!data) return `` - const lang = targetLang ? `lang='${ targetLang }'` : `` + const lang = (language ?? targetLang) ? `lang='${ language ?? targetLang }'` : `` let html = `` for (const ortho in data) { diff --git a/src/words/index.js b/src/words/index.js index 7fe850f..d38e9c3 100644 --- a/src/words/index.js +++ b/src/words/index.js @@ -11,7 +11,6 @@ export default function createWords(words, options) { for (const word of words) { - const glosses = createGlosses(word.gloss, options) const literal = createLiteral(word.literal, options) const morphemes = createMorphemes(word.analysis, options) diff --git a/src/words/morphemes.js b/src/words/morphemes.js index 70d31ec..b15c04d 100644 --- a/src/words/morphemes.js +++ b/src/words/morphemes.js @@ -1,9 +1,9 @@ import addEmphasis from '../utilities/addEmphasis.js' import replaceHyphens from '../utilities/replaceHyphens.js' -export default function createMorphemes(data, { targetLang }) { +export default function createMorphemes(data, { language, targetLang }) { - const lang = targetLang ? `lang='${ targetLang }'` : `` + const lang = (language ?? targetLang) ? `lang='${ language ?? targetLang }'` : `` let html = `` for (const ortho in data) { diff --git a/src/words/transcription.js b/src/words/transcription.js index 9750132..787359c 100644 --- a/src/words/transcription.js +++ b/src/words/transcription.js @@ -1,8 +1,8 @@ import addEmphasis from '../utilities/addEmphasis.js' -export default function createTranscription(data, { targetLang }) { +export default function createTranscription(data, { language, targetLang }) { - const lang = targetLang ? `lang='${ targetLang }'` : `` + const lang = (language ?? targetLang) ? `lang='${ language ?? targetLang }'` : `` let html = `` for (const ortho in data) { diff --git a/test/utterance.test.js b/test/utterance.test.js index cd5bb53..f09da50 100644 --- a/test/utterance.test.js +++ b/test/utterance.test.js @@ -85,6 +85,31 @@ describe(`utterance`, function() { }) + describe(`language`, function() { + + it(`renders`, async function() { + + const language = `swa` + + const scription = ` + \\lg ${ language } + \\txn ninakupenda + \\m ni-na-ku-pend-a + \\gl 1SG.SUBJ-PRES-1SG.OBJ-love-IND + \\tln I love you` + + const { dom, html } = await parse(scription) + + const txn = findElementByClass(dom, `txn`) + const morphemes = findElementByClass(dom, `m`) + + expect(getAttribute(txn, `lang`)).to.equal(language) + expect(getAttribute(morphemes, `lang`)).to.equal(language) + + }) + + }) + describe(`literal translation`, function() { it(`renders`, async function() {