Apply & drop LOCALIZATION NOTEs from comments
This commit is contained in:
Родитель
f44bf901fc
Коммит
ffbf7b1388
|
@ -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('.')
|
||||
|
|
Загрузка…
Ссылка в новой задаче