Skip to content
Permalink
Browse files
fix: remove comments in issue body before translating.
  • Loading branch information
plainheart committed Feb 23, 2021
1 parent a50de1b commit 0ae6f36ac246e178c16f7373a2f8eadc82e8d512
Showing 3 changed files with 9 additions and 3 deletions.
@@ -2,7 +2,7 @@ const Issue = require('./src/issue');
const text = require('./src/text');
const { isCommitter } = require('./src/coreCommitters');
const logger = require('./src/logger');
const { replaceAll } = require('./src/util');
const { replaceAll, removeHTMLComment } = require('./src/util');

module.exports = (app) => {
app.on(['issues.opened'], async context => {
@@ -238,7 +238,7 @@ async function translateIssue (context, createdIssue) {
} = createdIssue;

const titleNeedsTranslation = translatedTitle && translatedTitle[0] !== title;
const bodyNeedsTranslation = translatedBody && translatedBody[0] !== body;
const bodyNeedsTranslation = translatedBody && translatedBody[0] !== removeHTMLComment(body);
const needsTranslation = titleNeedsTranslation || bodyNeedsTranslation;

logger.info('issue needs translation: ' + needsTranslation);
@@ -1,6 +1,7 @@
const text = require('./text');
const { isCommitter } = require('./coreCommitters');
const { translate } = require('./translator');
const { removeHTMLComment } = require('./util');

class Issue {
constructor(context) {
@@ -61,7 +62,7 @@ class Issue {
if (res) {
this.translatedTitle = res.lang !== 'en' && [res.translated, res.lang];
}
res = await translate(this.body);
res = await translate(removeHTMLComment(this.body));
if (res) {
this.translatedBody = res.lang !== 'en' && [res.translated, res.lang];
}
@@ -6,11 +6,16 @@ function removeCodeAndComment(body) {
.replace(/-{3}\s?/g, '');
}

function removeHTMLComment (body) {
return body.replace(/<!--[\w\W\s]*?-->/gmi, '');
}

function replaceAll(str, search, replacement) {
return str.replace(new RegExp(search, 'g'), replacement);
}

module.exports = {
removeCodeAndComment,
removeHTMLComment,
replaceAll
}

0 comments on commit 0ae6f36

Please sign in to comment.