Skip to content

Commit

Permalink
NEW: Support language property on Utterance
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Jul 30, 2024
1 parent 5de1184 commit bcd0eb6
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<p class=ex-source>{speaker} ({source})</p>`.
- Notes fields (`\n`) are not added to the HTML by default.
- Individual glosses receive the `.gl` class.
Expand Down
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/utterance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/utterance/phonetic.js
Original file line number Diff line number Diff line change
@@ -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 `<p class=phon ${ lang }>${ addEmphasis(phonetic) }</p>`

}
4 changes: 2 additions & 2 deletions src/utterance/transcript.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import addEmphasis from '../utilities/addEmphasis.js'

export default function createTranscript(data, { targetLang }) {
export default function createTranscript(data, { language, targetLang }) {

if (!data) return ``

let html = ``

for (const ortho in data) {
const transcript = data[ortho]
const lang = targetLang ? `lang='${ targetLang }'` : ``
const lang = (language ?? targetLang) ? `lang='${ language ?? targetLang }'` : ``
html += `<p class=trs data-ortho='${ ortho }' ${ lang }>${ addEmphasis(transcript) }</p>`
}

Expand Down
4 changes: 2 additions & 2 deletions src/utterance/transcription.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/words/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/words/morphemes.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/words/transcription.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions test/utterance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit bcd0eb6

Please sign in to comment.