프로젝트 (CiviCRM)에서 동일한 작업을 수행해야했습니다. 내가받은 한 가지 제안은 유사한 문자열을 찾을 수있는 몇 가지 도구가있는 OpenRefine을 확인하는 것이 었습니다. 그러나 간단한 스크립트로 프로세스를 자동화하고 싶었 기 때문에 간단한 스크립트를 작성했습니다.
이 경고는 가장 효율적이지 않으며 큰 프로젝트 (CiviCRM에서 약 16,000 개의 문자열이 있음)에서 실행하는 데 약간의 시간이 걸릴 수 있습니다.
참고로
: 여기 https://github.com/civicrm/l10n/blob/master/bin/find-similar-strings.php
그리고 SO 이후 이 답변으로 링크를 좋아하지 않는다 자세한 내용은 :
#!/usr/bin/php
<?php
/**
* Reads from STDIN and finds similar-looking strings.
*
* Usage:
* cat *.pot | ../bin/find-similar-strings.php
*
* Context:
* http://forum.civicrm.org/index.php/topic,34805.0.html
*/
// Default match threshold is 90% match.
$threshold = (! empty($argv[1]) ? $argv[1] : 90);
// Read all input from stdin.
$src = file_get_contents("php://stdin");
// http://stackoverflow.com/a/1070937/2387700
// Extract all "msgid" strings (they can be multi-line).
preg_match_all('/msgid\s+\"([^\"]*)\"/', $src, $matches);
$msgids = $matches[1];
// Sort the strings alphabetically, to make them easier to compare.
// sort($msgids);
foreach ($msgids as $key1 => $msgid1) {
foreach ($msgids as $key2 => $msgid2) {
$percent = 0;
if ($msgid1 && $msgid2 && $msgid1 != $msgid2) {
if (similar_text($msgid1, $msgid2, $percent)) {
if ($percent > $threshold) {
$percent = (int) $percent;
echo "$msgid1 [$percent %]\n";
echo "$msgid2 \n\n";
}
}
}
}
// To avoid going through the strings twice, we unset the string
// si that the inner-loop goes faster.
unset($msgids[$key1]);
}
이쪽 .POT 파일 (원본 문자열을로드,하지만 난 당신을 생각합니다 .po 파일에서도 실행 가능), 모든 문자열을 차례대로 반복합니다.
I는 알파벳 문자열을 정렬하는 데 주저했지만, 내가 더 문자열 등
그들 앞에 추가 잘못된 공간, 오타가 있었다 몇 가지 경우보다 또 다른 가능한 개선은 길이 먼저 확인하는 것입니다 발견 매우 다른 길이의 문자열을 건너 뜁니다.
출처
2014-11-14 15:21:29
bgm