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
*/
export function buildFluentMessage(msgName, props, propNames) {
let comments = []
const getComment = () => {
const content = comments.join('\n').trim()
comments = []
let commentLines = []
const commentNotes = {}
const getComment = (key) => {
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
}
@ -31,12 +41,12 @@ export function buildFluentMessage(msgName, props, propNames) {
case 'COMMENT': {
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
}
case 'PAIR': {
const comment = getComment()
const comment = getComment(node.key)
const pattern = parseMsgPattern(node.value, propNames)
const dot = node.key.indexOf('.')