Skip to content

Commit

Permalink
NEW: Support emphasis in free translation
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Dec 18, 2023
1 parent 7e3b239 commit b6d0e6f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 26 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"stop-only": "stop-only --folder src",
"test": "mocha test/*.test.js"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@digitallinguistics/scription2dlx": "^0.13.1"
},
"devDependencies": {
"@digitallinguistics/eslint-config": "^0.3.0",
"@web/parse5-utils": "^2.0.2",
Expand All @@ -40,11 +46,5 @@
"mocha": "^10.2.0",
"parse5": "^7.1.2",
"stop-only": "^3.3.1"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@digitallinguistics/scription2dlx": "^0.12.3"
}
}
6 changes: 4 additions & 2 deletions src/lines/translation.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import addEmphasis from '../utilities/addEmphasis.js'

export default function createTranslation(data) {

if (typeof data === `string`) {
return `<p class=tln lang=en>${ data }</p>`
return `<p class=tln lang=en>${ addEmphasis(data) }</p>`
}

let html = ``

for (const lang in data) {
const tln = data[lang]
html += `<p class=tln lang='${ lang }'>${ tln }</p>`
html += `<p class=tln lang='${ lang }'>${ addEmphasis(tln) }</p>`
}

return html
Expand Down
5 changes: 5 additions & 0 deletions src/utilities/addEmphasis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const emRegExp = /\*(?<text>.*)\*/gsu

export default function addEmphasis(text) {
return text.replaceAll(emRegExp, `<b>$<text></b>`)
}
56 changes: 45 additions & 11 deletions test/lines.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,65 @@
import { expect } from 'chai'
import findElementByClass from './utilities/findElementByClass.js'
import findElementsByClass from './utilities/findElementsByClass.js'
import { getAttribute } from '@web/parse5-utils'
import { getTextContent } from '../node_modules/@web/parse5-utils/src/index.js'
import parse from './utilities/convertAndParse.js'
import parseClassString from './utilities/parseClassString.js'

import {
findElement,
getAttribute,
getTagName,
} from '@web/parse5-utils'

import { ChitimachaText, OldLatin, Swahili } from '../samples/data/data.js'

describe(`lines`, function() {

it(`free translation`, function() {
describe(`free translation`, function() {

it(`renders`, function() {

const { dom } = parse(OldLatin)
const tln = findElementsByClass(dom, `tln`)

expect(tln).to.have.length(2)

const [lat, eng] = tln

expect(getAttribute(lat, `lang`)).to.equal(`lat`)
expect(getAttribute(eng, `lang`)).to.equal(`eng`)
expect(getTextContent(lat)).to.include(`mittit`)
expect(getTextContent(eng)).to.include(`sends`)

})

const { dom } = parse(OldLatin)
const tln = findElementsByClass(dom, `tln`)
it(`renders with emphasis`, function() {

expect(tln).to.have.length(2)
// Mandinka, from ex. 2 of your dissertation
const scription = `
\\txn *Kuuráŋ*o mâŋ díyaa.
\\m *kuuráŋ*-o mâŋ díyaa
\\gl *sick*-def pfv.neg pleasant
\\tln *Sickness* is not pleasant.
\\s Creissels 2017: 46
\\txn Díndíŋo máŋ *kuraŋ*.
\\m díndíŋ-o máŋ *kuraŋ*
\\gl child-def pfv.neg *sick*
\\tln The child is not *sick*.
\\s Creissels 2017: 46
`

const [lat, eng] = tln
const { dom } = parse(scription)
const tln = findElementByClass(dom, `tln`)
const b = findElement(tln, el => getTagName(el) === `b`)

expect(getAttribute(lat, `lang`)).to.equal(`lat`)
expect(getAttribute(eng, `lang`)).to.equal(`eng`)
expect(getTextContent(lat)).to.include(`mittit`)
expect(getTextContent(eng)).to.include(`sends`)
expect(getTextContent(b)).to.equal(`Sickness`)

})

})


it(`literal translation`, function() {

const scription = `
Expand Down

0 comments on commit b6d0e6f

Please sign in to comment.