Skip to content

Commit ba5b157

Browse files
GustedGusted
authored andcommitted
feat(build): uniform ini parsing (go-gitea#7429)
- Use the existing ini parser for the `lint-locale` and `lint-locale-usage` tooling. - This discovered that the previous ini parser was not correctly parsing certain types of string, specifically those with `;` as it's seen as a comment. It now properly 'unescapes' that and is not seen as a comment break. - Discovered-by: @fogti Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7429 Reviewed-by: Earl Warren <[email protected]> Co-authored-by: Gusted <[email protected]> Co-committed-by: Gusted <[email protected]>
1 parent 4ab40ed commit ba5b157

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

build/lint-locale/lint-locale_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestLocalizationPolicy(t *testing.T) {
6060
t.Run("Escaped HTML characters", func(t *testing.T) {
6161
assert.Empty(t, checkLocaleContent([]byte("activity.git_stats_push_to_branch = `إلى %s و\"`")))
6262

63-
assert.Equal(t, []string{"key: و\x1b[31m&nbsp\x1b[0m\x1b[32m\u00a0\x1b[0m"}, checkLocaleContent([]byte(`key = و&nbsp;`)))
63+
assert.Equal(t, []string{"key: و\x1b[31m&nbsp;\x1b[0m\x1b[32m\u00a0\x1b[0m"}, checkLocaleContent([]byte(`key = و&nbsp;`)))
6464
})
6565
}
6666

modules/translation/localeiter/utils.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ import (
1010
"encoding/json" //nolint:depguard
1111
"fmt"
1212

13-
"gopkg.in/ini.v1" //nolint:depguard
13+
"forgejo.org/modules/setting"
1414
)
1515

1616
func IterateMessagesContent(localeContent []byte, onMsgid func(string, string) error) error {
17-
// Same configuration as Forgejo uses.
18-
cfg := ini.Empty(ini.LoadOptions{
19-
IgnoreContinuation: true,
20-
})
21-
cfg.NameMapper = ini.SnackCase
22-
23-
if err := cfg.Append(localeContent); err != nil {
17+
cfg, err := setting.NewConfigProviderForLocale(localeContent)
18+
if err != nil {
2419
return err
2520
}
2621

0 commit comments

Comments
 (0)