feat(build): uniform ini parsing

- 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
This commit is contained in:
Gusted 2025-04-02 16:53:48 +02:00
parent 4ab40ed6af
commit cac702bc14
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 4 additions and 9 deletions

View file

@ -60,7 +60,7 @@ func TestLocalizationPolicy(t *testing.T) {
t.Run("Escaped HTML characters", func(t *testing.T) {
assert.Empty(t, checkLocaleContent([]byte("activity.git_stats_push_to_branch = `إلى %s و\"`")))
assert.Equal(t, []string{"key: و\x1b[31m&nbsp\x1b[0m\x1b[32m\u00a0\x1b[0m"}, checkLocaleContent([]byte(`key = و `)))
assert.Equal(t, []string{"key: و\x1b[31m \x1b[0m\x1b[32m\u00a0\x1b[0m"}, checkLocaleContent([]byte(`key = و `)))
})
}

View file

@ -10,17 +10,12 @@ import (
"encoding/json" //nolint:depguard
"fmt"
"gopkg.in/ini.v1" //nolint:depguard
"forgejo.org/modules/setting"
)
func IterateMessagesContent(localeContent []byte, onMsgid func(string, string) error) error {
// Same configuration as Forgejo uses.
cfg := ini.Empty(ini.LoadOptions{
IgnoreContinuation: true,
})
cfg.NameMapper = ini.SnackCase
if err := cfg.Append(localeContent); err != nil {
cfg, err := setting.NewConfigProviderForLocale(localeContent)
if err != nil {
return err
}