Apply & drop LOCALIZATION NOTEs from comments

This commit is contained in:
Eemeli Aro 2021-09-23 13:55:37 -04:00
Родитель f44bf901fc
Коммит ffbf7b1388
1 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -15,10 +15,20 @@ import kebabCase from 'lodash.kebabcase'
* @param {import('dot-properties').Node[]} props * @param {import('dot-properties').Node[]} props
*/ */
export function buildFluentMessage(msgName, props, propNames) { export function buildFluentMessage(msgName, props, propNames) {
let comments = [] let commentLines = []
const getComment = () => { const commentNotes = {}
const content = comments.join('\n').trim() const getComment = (key) => {
comments = [] let content = commentLines.join('\n').trim()
commentLines = []
const ln = content.match(/^LOCALIZATION NOTE\s*(\([^)]*\))?:?\s*(.*)/)
if (ln) {
content = ln[2]
for (const tgt of ln[1].slice(1, -1).split(/[,\s]+/))
if (tgt && tgt !== key) commentNotes[tgt] = content
} else {
const cn = commentNotes[key]
if (cn) content = content ? cn + '\n' + content : cn
}
return content ? new Comment(content) : null return content ? new Comment(content) : null
} }
@ -31,12 +41,12 @@ export function buildFluentMessage(msgName, props, propNames) {
case 'COMMENT': { case 'COMMENT': {
const line = node.comment.replace(/^[!#]\s*/, '') const line = node.comment.replace(/^[!#]\s*/, '')
if (!line.startsWith('-*-')) comments.push(line) // ignore mode lines if (!line.startsWith('-*-')) commentLines.push(line) // ignore mode lines
break break
} }
case 'PAIR': { case 'PAIR': {
const comment = getComment() const comment = getComment(node.key)
const pattern = parseMsgPattern(node.value, propNames) const pattern = parseMsgPattern(node.value, propNames)
const dot = node.key.indexOf('.') const dot = node.key.indexOf('.')