Skip to content

Commit

Permalink
dict: add pattern to find typos of refspecs
Browse files Browse the repository at this point in the history
Patrick reported that there are typos of refspecs in l10n translations,
such as "ref/" should be "refs/".

Add new pattern to KeepWordsPattern to help l10n team leaders discover
and resolve these issues.

Reported-by: Patrick Steinhardt <[email protected]>
Signed-off-by: Jiang Xin <[email protected]>
  • Loading branch information
jiangxin committed Jan 2, 2024
1 parent 3a7eb7b commit 06053ee
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dict/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var KeepWordsPattern = regexp.MustCompile(`(` +
`--[a-zA-Z0-9-=]+` + // match git options: --option, --option=value, ...
`|` +
`%%\(.*?\)` + // match %(fieldname) in format argument of git-for-each-ref, ...
`|` +
`\brefs/[a-zA-Z0-9{}<>_.,/-]+` + // match refspec like: refs/remotes/<name>/HEAD, refs/{heads,tags}/...
`)`)

// GlobalSkipPatterns defines words we want to ignore for check globally.
Expand Down
24 changes: 24 additions & 0 deletions dict/smudge-bg.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,29 @@ func init() {
Pattern: regexp.MustCompile(`(--[^\s]+=)([a-zA-Z-]*[^a-zA-Z0-9\s-"]+[a-zA-Z0-9-]*)`),
Replace: "$1 $2",
},

/*
* The <place-holder>s in refspecs were translated in bg without "<>", e.g.:
*
* msgid: "set refs/remotes/<name>/HEAD according to remote"
* msgstr: "задаване на refs/remotes/ИМЕ/HEAD според отдалеченото хранилище"
*
* After replaced according to patterns defined in GlobalSkipPatterns,
* the result are follow:
*
* msgid: "set refs/remotes/<...>/HEAD according to remote"
* msgstr: "задаване на refs/remotes/ИМЕ/HEAD според отдалеченото хранилище"
*
* We will get the keep words as follows from patten defined in KeepWordsPattern.
*
* msgid: refs/remotes/<...>/HEAD
* msgstr: refs/remotes/
*
* This will cause false positive report of typos. Hack as follows:
*/
{
Pattern: regexp.MustCompile(`/ИМЕ/`),
Replace: "/<name>/",
},
}
}
23 changes: 22 additions & 1 deletion test/t0032-typos-in-zh_CN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ level=warning msg="[po/zh_CN.po] mismatched patterns: git-am"
level=warning msg="[po/zh_CN.po] >> msgid: It looks like 'git am' is in progress. Cannot rebase."
level=warning msg="[po/zh_CN.po] >> msgstr: 看起来 'git-am' 正在执行中。无法变基。"
level=warning msg="[po/zh_CN.po]"
level=warning msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=warning msg="[po/zh_CN.po] >> msgid: Note: A branch outside the refs/remotes/ hierarchy was not removed;"
level=warning msg="[po/zh_CN.po] to delete it, use:"
level=warning msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一个分支未被移除。要删除它,使用:"
level=warning msg="[po/zh_CN.po]"
level=warning msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=warning msg="[po/zh_CN.po] >> msgid: Note: Some branches outside the refs/remotes/ hierarchy were not removed;"
level=warning msg="[po/zh_CN.po] to delete them, use:"
level=warning msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一些分支未被移除。要删除它们,使用:"
level=warning msg="[po/zh_CN.po]"
level=warning msg="[po/zh_CN.po] mismatched patterns: submodule.alternateLocaion, submodule.alternateLocation"
level=warning msg="[po/zh_CN.po] >> msgid: Value '%s' for submodule.alternateLocation is not recognized"
level=warning msg="[po/zh_CN.po] >> msgstr: 不能识别 submodule.alternateLocaion 的取值 '%s'"
Expand Down Expand Up @@ -88,12 +98,23 @@ level=info msg="[po/zh_CN.po]"
level=info msg="[po/zh_CN.po] As how to commit a location-less \"po/XX.po\" file, See:"
level=info msg="[po/zh_CN.po]"
level=info msg="[po/zh_CN.po] the [Updating a \"XX.po\" file] section in \"po/README.md\""
------------------------------------------------------------------------------
level=warning msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=warning msg="[po/zh_CN.po] >> msgid: Note: A branch outside the refs/remotes/ hierarchy was not removed;"
level=warning msg="[po/zh_CN.po] to delete it, use:"
level=warning msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一个分支未被移除。要删除它,使用:"
level=warning msg="[po/zh_CN.po]"
level=warning msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=warning msg="[po/zh_CN.po] >> msgid: Note: Some branches outside the refs/remotes/ hierarchy were not removed;"
level=warning msg="[po/zh_CN.po] to delete them, use:"
level=warning msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一些分支未被移除。要删除它们,使用:"
level=warning msg="[po/zh_CN.po]"
EOF
test_expect_success "check typos in master branch" '
git -C workdir checkout master &&
git -C workdir $HELPER \
check-po --report-typos=error --report-file-locations=warn zh_CN >out 2>&1 &&
check-po --report-typos=warn --report-file-locations=warn zh_CN >out 2>&1 &&
make_user_friendly_and_stable_output <out >actual &&
test_cmp expect actual
'
Expand Down
33 changes: 31 additions & 2 deletions test/t0034-typos-in-es.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ level=warning msg="[po/es.po] mismatched patterns: --shallow-since, --shalow-
level=warning msg="[po/es.po] >> msgid: Server does not support --shallow-since"
level=warning msg="[po/es.po] >> msgstr: El servidor no soporta --shalow-since"
level=warning msg="[po/es.po]"
level=warning msg="[po/es.po] mismatched patterns: refs/heads/, refs/tags/"
level=warning msg="[po/es.po] >> msgid: The <src> part of the refspec is a blob object."
level=warning msg="[po/es.po] Did you mean to tag a new blob by pushing to"
level=warning msg="[po/es.po] '%s:refs/tags/%s'?"
level=warning msg="[po/es.po] >> msgstr: La parte <src> del refspec es un objeto blob."
level=warning msg="[po/es.po] ¿Quisiste crear un tag nuevo mediante un push a"
level=warning msg="[po/es.po] '%s:refs/heads/%s'?"
level=warning msg="[po/es.po]"
level=warning msg="[po/es.po] mismatched patterns: refs/heads/, refs/tags/"
level=warning msg="[po/es.po] >> msgid: The <src> part of the refspec is a tree object."
level=warning msg="[po/es.po] Did you mean to tag a new tree by pushing to"
level=warning msg="[po/es.po] '%s:refs/tags/%s'?"
level=warning msg="[po/es.po] >> msgstr: La parte <src> del refspec es un objeto tree."
level=warning msg="[po/es.po] ¿Quisiste crear un tag nuevo mediante un push a"
level=warning msg="[po/es.po] '%s:refs/heads/%s'?"
level=warning msg="[po/es.po]"
level=warning msg="[po/es.po] mismatched patterns: ---smtp-debug, --smtp-debug"
level=warning msg="[po/es.po] >> msgid: Unable to initialize SMTP properly. Check config and use --smtp-debug."
level=warning msg="[po/es.po] >> msgstr: No es posible inicializar SMTP adecuadamente. Verificar config y usar ---smtp-debug."
Expand All @@ -72,6 +88,10 @@ level=warning msg="[po/es.po] mismatched patterns: dimmed_zebra"
level=warning msg="[po/es.po] >> msgid: color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'"
level=warning msg="[po/es.po] >> msgstr: opción de color tiene que ser una de 'no', 'default', 'blocks', 'zebra', 'dimmed_zebra', 'plain'"
level=warning msg="[po/es.po]"
level=warning msg="[po/es.po] mismatched patterns: refs/remotes/<...>/HEAD, refs/remotos/<...>/HEAD"
level=warning msg="[po/es.po] >> msgid: delete refs/remotes/<name>/HEAD"
level=warning msg="[po/es.po] >> msgstr: borrar refs/remotos/<nombre>/HEAD"
level=warning msg="[po/es.po]"
level=warning msg="[po/es.po] mismatched patterns: gc.logexpirity, gc.logexpiry"
level=warning msg="[po/es.po] >> msgid: failed to parse gc.logexpiry value %s"
level=warning msg="[po/es.po] >> msgstr: falló al analizar valor %s de gc.logexpirity"
Expand Down Expand Up @@ -136,7 +156,7 @@ level=warning msg="[po/es.po]"
ERROR: fail to execute "git-po-helper check-po"
EOF

test_expect_success "check typos in es.po" '
test_expect_success "check typos in es.po of git 2.31.1" '
test_must_fail git -C workdir $HELPER check-po es >out 2>&1 &&
make_user_friendly_and_stable_output <out >actual &&
test_cmp expect actual
Expand All @@ -146,11 +166,20 @@ cat >expect <<-\EOF
------------------------------------------------------------------------------
level=error msg="[po/es.po] 5210 translated messages."
level=error msg="[po/es.po] too many obsolete entries (125) in comments, please remove them"
------------------------------------------------------------------------------
level=error msg="[po/es.po] mismatched patterns: refs/remotes/<...>/HEAD, refs/remotos/<...>/HEAD"
level=error msg="[po/es.po] >> msgid: delete refs/remotes/<name>/HEAD"
level=error msg="[po/es.po] >> msgstr: borrar refs/remotos/<nombre>/HEAD"
level=error msg="[po/es.po]"
level=error msg="[po/es.po] mismatched patterns: refs/preferch/, refs/prefetch/"
level=error msg="[po/es.po] >> msgid: modify the refspec to place all refs within refs/prefetch/"
level=error msg="[po/es.po] >> msgstr: modificar el refspec para colocar todas las referencias en refs/preferch/"
level=error msg="[po/es.po]"
ERROR: fail to execute "git-po-helper check-po"
EOF

test_expect_success "no typos in master branch" '
test_expect_success "typos in master branch" '
git -C workdir checkout master &&
test_must_fail git -C workdir $HELPER \
check-po --report-typos=error es >out 2>&1 &&
Expand Down
43 changes: 42 additions & 1 deletion test/t0036-typos-in-sv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ level=warning msg="[po/sv.po] Du kan inspektera det som checkades ut med \"gi
level=warning msg="[po/sv.po] och försöka med \"git restore -source=HEAD :/\""
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] mismatched patterns: refs/{heads,tags}/-prefix"
level=warning msg="[po/sv.po] >> msgid: The destination you provided is not a full refname (i.e.,"
level=warning msg="[po/sv.po] starting with \"refs/\"). We tried to guess what you meant by:"
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] - Looking for a ref that matches '%s' on the remote side."
level=warning msg="[po/sv.po] - Checking if the <src> being pushed ('%s')"
level=warning msg="[po/sv.po] is a ref in \"refs/{heads,tags}/\". If so we add a corresponding"
level=warning msg="[po/sv.po] refs/{heads,tags}/ prefix on the remote side."
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] Neither worked, so we gave up. You must fully qualify the ref."
level=warning msg="[po/sv.po] >> msgstr: Målet du angav är inte ett komplett referensamn (dvs.,"
level=warning msg="[po/sv.po] startar med \"refs/\"). Vi försökte gissa vad du menade genom att:"
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] - Se efter en referens som motsvarar \"%s\" på fjärrsidan."
level=warning msg="[po/sv.po] - Se om <källan> som sänds (\"%s\")"
level=warning msg="[po/sv.po] är en referens i \"refs/{heads,tags}/\". Om så lägger vi till"
level=warning msg="[po/sv.po] motsvarande refs/{heads,tags}/-prefix på fjärrsidan."
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] Inget av dem fungerade, så vi gav upp. Ange fullständig referens."
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] mismatched patterns: add_cacheinfo, add_cahceinfo"
level=warning msg="[po/sv.po] >> msgid: add_cacheinfo failed for path '%s'; merge aborting."
level=warning msg="[po/sv.po] >> msgstr: add_cahceinfo misslyckades för sökvägen \"%s\"; avslutar sammanslagningen."
Expand Down Expand Up @@ -114,11 +134,32 @@ cat >expect <<-\EOF
------------------------------------------------------------------------------
level=error msg="[po/sv.po] 5282 translated messages."
level=error msg="[po/sv.po] too many obsolete entries (768) in comments, please remove them"
------------------------------------------------------------------------------
level=error msg="[po/sv.po] mismatched patterns: refs/{heads,tags}/-prefix"
level=error msg="[po/sv.po] >> msgid: The destination you provided is not a full refname (i.e.,"
level=error msg="[po/sv.po] starting with \"refs/\"). We tried to guess what you meant by:"
level=error msg="[po/sv.po]"
level=error msg="[po/sv.po] - Looking for a ref that matches '%s' on the remote side."
level=error msg="[po/sv.po] - Checking if the <src> being pushed ('%s')"
level=error msg="[po/sv.po] is a ref in \"refs/{heads,tags}/\". If so we add a corresponding"
level=error msg="[po/sv.po] refs/{heads,tags}/ prefix on the remote side."
level=error msg="[po/sv.po]"
level=error msg="[po/sv.po] Neither worked, so we gave up. You must fully qualify the ref."
level=error msg="[po/sv.po] >> msgstr: Målet du angav är inte ett komplett referensamn (dvs.,"
level=error msg="[po/sv.po] startar med \"refs/\"). Vi försökte gissa vad du menade genom att:"
level=error msg="[po/sv.po]"
level=error msg="[po/sv.po] - Se efter en referens som motsvarar \"%s\" på fjärrsidan."
level=error msg="[po/sv.po] - Se om <källan> som sänds (\"%s\")"
level=error msg="[po/sv.po] är en referens i \"refs/{heads,tags}/\". Om så lägger vi till"
level=error msg="[po/sv.po] motsvarande refs/{heads,tags}/-prefix på fjärrsidan."
level=error msg="[po/sv.po]"
level=error msg="[po/sv.po] Inget av dem fungerade, så vi gav upp. Ange fullständig referens."
level=error msg="[po/sv.po]"
ERROR: fail to execute "git-po-helper check-po"
EOF

test_expect_success "no typos in master branch" '
test_expect_success "typos in master branch" '
git -C workdir checkout master &&
test_must_fail git -C workdir $HELPER \
check-po --report-typos=error sv >out 2>&1 &&
Expand Down
4 changes: 4 additions & 0 deletions test/t0037-typos-in-bg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ level=warning msg="[po/bg.po] За да изключите това съоб
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] git config advice.objectNameWarning false"
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] mismatched patterns: refs/heads, refs/heads/"
level=warning msg="[po/bg.po] >> msgid: HEAD (%s) points outside of refs/heads/"
level=warning msg="[po/bg.po] >> msgstr: „HEAD“ (%s) сочи извън директорията „refs/heads“"
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] mismatched patterns: git-am"
level=warning msg="[po/bg.po] >> msgid: It looks like 'git am' is in progress. Cannot rebase."
level=warning msg="[po/bg.po] >> msgstr: Изглежда, че сега се прилагат кръпки чрез командата „git-am“. Не може да пребазирате в момента."
Expand Down
34 changes: 33 additions & 1 deletion test/t0081-cmp-pot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ test_expect_success "setup" '
cat >expect <<-\EOF
------------------------------------------------------------------------------
level=info msg="[po/zh_CN.po] 5282 translated messages."
------------------------------------------------------------------------------
level=error msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=error msg="[po/zh_CN.po] >> msgid: Note: A branch outside the refs/remotes/ hierarchy was not removed;"
level=error msg="[po/zh_CN.po] to delete it, use:"
level=error msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一个分支未被移除。要删除它,使用:"
level=error msg="[po/zh_CN.po]"
level=error msg="[po/zh_CN.po] mismatched patterns: refs/remotes/"
level=error msg="[po/zh_CN.po] >> msgid: Note: Some branches outside the refs/remotes/ hierarchy were not removed;"
level=error msg="[po/zh_CN.po] to delete them, use:"
level=error msg="[po/zh_CN.po] >> msgstr: 注意:ref/remotes 层级之外的一些分支未被移除。要删除它们,使用:"
level=error msg="[po/zh_CN.po]"
ERROR: fail to execute "git-po-helper check-po"
EOF

test_expect_success "zh_CN.po: all translated" '
git -C workdir $HELPER check-po --pot-file=po/git.pot \
test_must_fail git -C workdir $HELPER check-po --pot-file=po/git.pot \
--report-file-locations=none po/zh_CN.po >out 2>&1 &&
make_user_friendly_and_stable_output <out >actual &&
test_cmp expect actual
Expand All @@ -31,6 +44,25 @@ cat >expect <<-\EOF
------------------------------------------------------------------------------
level=info msg="[po/ko.po] 3608 translated messages."
------------------------------------------------------------------------------
level=error msg="[po/ko.po] mismatched patterns: refs/heads"
level=error msg="[po/ko.po] >> msgid: HEAD not found below refs/heads!"
level=error msg="[po/ko.po] >> msgstr: 레퍼런스/헤드 아래에 HEAD가 없습니다!"
level=error msg="[po/ko.po]"
level=error msg="[po/ko.po] mismatched patterns: refs/remotes/"
level=error msg="[po/ko.po] >> msgid: Note: A branch outside the refs/remotes/ hierarchy was not removed;"
level=error msg="[po/ko.po] to delete it, use:"
level=error msg="[po/ko.po] >> msgstr: 알림: 레퍼런스/리모트/ 계층 구조 밖에 있는 일부 브랜치가 제거되지 않았습니다."
level=error msg="[po/ko.po] 삭제하려면 다음을 사용하십시오:"
level=error msg="[po/ko.po]"
level=error msg="[po/ko.po] mismatched patterns: refs/remotes/<...>/HEAD"
level=error msg="[po/ko.po] >> msgid: delete refs/remotes/<name>/HEAD"
level=error msg="[po/ko.po] >> msgstr: 레퍼런스/리모트/<이름>/HEAD 값을 삭제합니다"
level=error msg="[po/ko.po]"
level=error msg="[po/ko.po] mismatched patterns: refs/remotes/<...>/HEAD"
level=error msg="[po/ko.po] >> msgid: set refs/remotes/<name>/HEAD according to remote"
level=error msg="[po/ko.po] >> msgstr: 레퍼런스/리모트/<이름>/HEAD 값을 리모트에 맞게 설정합니다"
level=error msg="[po/ko.po]"
------------------------------------------------------------------------------
level=error msg="[po/ko.po] 2242 new string(s) in 'po/git.pot', but not in your 'po/XX.po'"
level=error msg="[po/ko.po]"
level=error msg="[po/ko.po] > po/git.pot:24: this message is used but not defined in po/ko.po"
Expand Down
Loading

0 comments on commit 06053ee

Please sign in to comment.