Skip to content

Commit

Permalink
dict/bg: Smudge both msgId and msgStr
Browse files Browse the repository at this point in the history
We used to define a large smudge table for bg (Bulgarian) language,
because in git bg l10n translations, "<place-holder>" was translated
without the surrounding quotes "<>".

Add new field for smudge table, so we can smudge both msgID and msgStr
for bg translations, to suppress unnecessary warnings.

Signed-off-by: Jiang Xin <[email protected]>
  • Loading branch information
jiangxin committed Nov 28, 2023
1 parent 4cecf61 commit 26dd22c
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 94 deletions.
183 changes: 96 additions & 87 deletions dict/smudge-bg.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,42 @@
package dict

import "regexp"

func init() {
SmudgeMaps["bg"] = []SmudgeMap{
/*
* In bg translations, additional "git" command name is added before
* subcommand, revert these changes before checking typos.
*/
{
Pattern: "———",
Replace: "---",
},

// Not keep symbols "<" and ">", the reason is ?
{
Pattern: "РЕГУЛЯРЕН_ИЗРАЗ",
Replace: "<РЕГУЛЯРЕН_ИЗРАЗ>",
},
{
Pattern: "ДИРЕКТОРИЯ",
Replace: "<ДИРЕКТОРИЯ>",
},
{
Pattern: "ПАКЕТЕН_ФАЙЛ",
Replace: "<ПАКЕТЕН_ФАЙЛ>",
},
{
Pattern: "align:ШИРОЧИНА,ПОЗИЦИЯ",
Replace: "align:<ШИРОЧИНА>,<ПОЗИЦИЯ>",
},
{
Pattern: "color:ЦВЯТ",
Replace: "color:<ЦВЯТ>",
},
{
Pattern: "--config=НАСТРОЙКА",
Replace: "--config=<НАСТРОЙКА>",
},
{
Pattern: "--prefix=ПРЕФИКС",
Replace: "--prefix=<ПРЕФИКС>",
},
{
Pattern: "--index-output=ФАЙЛ",
Replace: "--index-output=<ФАЙЛ>",
},
{
Pattern: "--extcmd=КОМАНДА",
Replace: "--extcmd=<КОМАНДА>",
},
{
Pattern: "--tool=ПРОГРАМА",
Replace: "--tool=<ПРОГРАМА>",
},
{
Pattern: "--schedule=ЧЕСТОТА",
Replace: "--schedule=<ЧЕСТОТА>",
Pattern: "Командата „git pack-objects“",
Replace: "spawn pack-objects",
},
{
Pattern: "trailers:key=ЕПИЛОГ",
Replace: "trailers:key=<ЕПИЛОГ>",
Pattern: "„git-difftool“ изисква работно дърво или опцията „--no-index“",
Replace: "difftool requires worktree or --no-index",
},

// Upstream may need to add "<>" around "files"
{
Pattern: "--dirstat=ФАЙЛОВЕ",
Replace: "--dirstat=files",
Pattern: "командата „git index-pack“ не завърши успешно",
Replace: "index-pack died",
},
{
Pattern: "--dirstat=ФАЙЛ…,ПАРАМЕТЪР_1,ПАРАМЕТЪР_2,",
Replace: "--dirstat=files,param1,param2",
Pattern: "Командата „git pack-objects“ не завърши успешно",
Replace: "pack-objects died",
},

// Email address
{
Pattern: "ИМЕ@example.com",
Replace: "[email protected]",
Pattern: "указателят „%s“ не е бил включен поради опциите зададени на „git rev-list“",
Replace: "ref '%s' is excluded by the rev-list options",
},
{
Pattern: "пенчо@example.com",
Replace: "[email protected]",
Pattern: " git merge-base --fork-point",
Replace: " merge-base --fork-point",
},

// add or lost '--'
/*
* In bg translations, add additional "--" characters before command option,
* but the original msgid does not have.
*/
{
Pattern: "неправилен параметър към опцията „--update“",
Replace: "bad value for update parameter",
Expand All @@ -94,8 +53,10 @@ func init() {
Pattern: "„%s“ към опцията „--ancestry-path",
Replace: "ancestry-path argument %s",
},

// Upstream should add "--" ?
{
Pattern: "Неправилен режим за „--rebase-merges“: %s",
Replace: "Unknown rebase-merges mode: %s",
},
{
Pattern: "не поддържа опцията „--force“",
Replace: "does not support 'force'",
Expand All @@ -105,40 +66,88 @@ func init() {
Replace: "unknown mirror argument: %s",
},

// Add or lost "git" before subcommand
{
Pattern: "Командата „git pack-objects“",
Replace: "spawn pack-objects",
},
// Revert changes in bg, such as quotes and dashes.
{
Pattern: "„git-difftool“ изисква работно дърво или опцията „--no-index“",
Replace: "difftool requires worktree or --no-index",
Pattern: "„",
Replace: "\"",
},
{
Pattern: "командата „git index-pack“ не завърши успешно",
Replace: "index-pack died",
Pattern: "",
Replace: "\"",
},
{
Pattern: "Командата „git pack-objects“ не завърши успешно",
Replace: "pack-objects died",
Pattern: "———",
Replace: "---",
},

// Revert translated email address
{
Pattern: "указателят „%s“ не е бил включен поради опциите зададени на „git rev-list“",
Replace: "ref '%s' is excluded by the rev-list options",
Pattern: "ИМЕ@example.com",
Replace: "[email protected]",
},
{
Pattern: " git merge-base --fork-point",
Replace: " merge-base --fork-point",
Pattern: "пенчо@example.com",
Replace: "[email protected]",
},

// Quotes in bg
{
Pattern: "„",
Replace: "\"",
/*
* The <place-holder> in format string was translated without "<>", e.g.:
*
* msgid "expected format: %%(color:<color>)"
* msgstr "очакван формат: %%(color:ЦВЯТ)"
*
* msgid "expected format: %%(align:<width>,<position>)"
* msgstr "очакван формат: %%(align:ШИРОЧИНА,ПОЗИЦИЯ)"
*
* After replaced according to patterns defined in GlobalSkipPatterns,
* the result are follow:
*
* msgid "expected format: %%(color:<...>)"
* msgstr "очакван формат: %%(color:ЦВЯТ)"
*
* msgid "expected format: %%(align:<...>,<...>)"
* msgstr "очакван формат: %%(align:ШИРОЧИНА,ПОЗИЦИЯ)"
*
* In oder to check the format strings in above messages, we define
* several smudge maps as below.
*/
{
Pattern: regexp.MustCompile(`(%%\([^\s\)]+?:([^\s\)]*?=)?).*?\)`),
Replace: "$1)",
Reverse: true,
},
{
Pattern: regexp.MustCompile(`(%%\([^\s\)]+?:([^\s\)]*?=)?).*?\)`),
Replace: "$1)",
},
{
Pattern: "“",
Replace: "\"",

/*
* The <place-holder>s in command options were translated in bg without "<>", e.g.:
*
* msgid "git restore [<options>] [--source=<branch>] <file>..."
* msgstr "git restore [ОПЦИЯ…] [--source=КЛОН] ФАЙЛ…"
*
* After replaced according to patterns defined in GlobalSkipPatterns,
* the result are follow:
*
* msgid "git restore [<...>] [--source=<...>] <file>..."
* msgstr "git restore [ОПЦИЯ…] [--source=КЛОН] ФАЙЛ…"
*
* We will get the keep words as follows from patten defined in KeepWordsPattern.
*
* msgid: --source=
* msgstr: --source=K
*
* This will cause false positive report of typos. Hack as follows:
*/
{
Pattern: regexp.MustCompile(`(--[^\s]+=)<\.\.\.>`),
Replace: "$1 ...",
Reverse: true,
},
{
Pattern: regexp.MustCompile(`(--[^\s]+=)([a-zA-Z-]*[^a-zA-Z0-9\s-"]+[a-zA-Z0-9-]*)`),
Replace: "$1 $2",
},
}
}
2 changes: 2 additions & 0 deletions dict/smudge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dict
type SmudgeMap struct {
Pattern interface{}
Replace string
// If reverse is true, match and replace msgId instead.
Reverse bool
}

// SmudgeMaps defines replacement map locales
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test-repository
*.swp
test-results/
trash directory.*/
chainlinttmp/
6 changes: 5 additions & 1 deletion test/t0037-typos-in-bg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ level=warning msg="[po/bg.po] mismatch variable names: credential-cache--daem
level=warning msg="[po/bg.po] >> msgid: credential-cache--daemon unavailable; no unix socket support"
level=warning msg="[po/bg.po] >> msgstr: демонът за кеша с идентификациите е недостъпен — липсва поддръжка на гнезда на unix"
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] mismatch variable names: %%(trailers:key=<...>), %%(trailers:КЛЮЧ=СТОЙНОСТ)"
level=warning msg="[po/bg.po] mismatch variable names: %%(trailers:key=), %%(trailers:КЛЮЧ=)"
level=warning msg="[po/bg.po] >> msgid: expected %%(trailers:key=<value>)"
level=warning msg="[po/bg.po] >> msgstr: очаква се %%(trailers:КЛЮЧ=СТОЙНОСТ)"
level=warning msg="[po/bg.po]"
Expand Down Expand Up @@ -188,6 +188,10 @@ level=warning msg="[po/bg.po] mismatch variable names: --raw, --stat"
level=warning msg="[po/bg.po] >> msgid: synonym for '-p --raw'"
level=warning msg="[po/bg.po] >> msgstr: псевдоним на „-p --stat“"
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] mismatch variable names: --dirstat=, --dirstat=files"
level=warning msg="[po/bg.po] >> msgid: synonym for --dirstat=files,param1,param2..."
level=warning msg="[po/bg.po] >> msgstr: псевдоним на „--dirstat=ФАЙЛОВЕ,ПАРАМЕТЪР_1,ПАРАМЕТЪР_2,…“"
level=warning msg="[po/bg.po]"
level=warning msg="[po/bg.po] mismatch variable names: git cherry-pick"
level=warning msg="[po/bg.po] >> msgid: try \"git revert (--continue | %s--abort | --quit)\""
level=warning msg="[po/bg.po] >> msgstr: използвайте „git cherry-pick (--continue | %s--abort | --quit)“"
Expand Down
24 changes: 18 additions & 6 deletions util/check-po-typos.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,25 @@ func checkTyposInPoEntry(locale, msgID, msgStr string) ([]string, bool) {
if smudgeMaps, ok := dict.SmudgeMaps[locale]; ok {
for _, smudgeMap := range smudgeMaps {
if re, ok := smudgeMap.Pattern.(*regexp.Regexp); ok {
msgStr = re.ReplaceAllString(msgStr, smudgeMap.Replace)
if smudgeMap.Reverse {
msgID = re.ReplaceAllString(msgID, smudgeMap.Replace)
} else {
msgStr = re.ReplaceAllString(msgStr, smudgeMap.Replace)
}
} else {
msgStr = strings.Replace(
msgStr,
smudgeMap.Pattern.(string),
smudgeMap.Replace,
-1)
if smudgeMap.Reverse {
msgID = strings.Replace(
msgID,
smudgeMap.Pattern.(string),
smudgeMap.Replace,
-1)
} else {
msgStr = strings.Replace(
msgStr,
smudgeMap.Pattern.(string),
smudgeMap.Replace,
-1)
}
}
}
}
Expand Down

0 comments on commit 26dd22c

Please sign in to comment.