Skip to content

Commit

Permalink
upd(translation): 优化处理翻译歌词自带圆括号的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonish committed Jun 6, 2024
1 parent e53169b commit 1afcf8d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/qqTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ private function processLrcLine($lrc) {
return $result;
}

private function checkBrackets($str) {
$firstChar = mb_substr($str, 0, 1);
$lastChar = mb_substr($str, -1, 1);

if ($firstChar == '' && $lastChar == '') {
return true;
} else {
return false;
}
}

public function getChineseTranslationLrc() {
$resultLrc = '';
$orgLines = $this->processLrcLine($this->orgLrc);
Expand Down Expand Up @@ -124,7 +135,11 @@ public function getChineseTranslationLrc() {
}

if ($this->isValidLrcText($trans)) {
$resultLrc .= "{$trans}";
if ($this->checkBrackets($trans)) {
$resultLrc .= " {$trans}";
} else {
$resultLrc .= "{$trans}";
}
}
$resultLrc .= "\n";
}
Expand Down

0 comments on commit 1afcf8d

Please sign in to comment.