Skip to content

Commit

Permalink
Sort ARB keys alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert221 committed Apr 3, 2024
1 parent e306c96 commit 7faca3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions convert/poe2arb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"regexp"
"sort"
"strings"

"github.com/leancodepl/poe2arb/convert"
Expand Down Expand Up @@ -57,6 +58,15 @@ func (c *Converter) Convert(output io.Writer) error {
prefixedRegexp := regexp.MustCompile("(?:([a-zA-Z]+):)?(.*)")
var errs []error

// Sort terms by key alphabetically
sort.SliceStable(jsonContents, func(i, j int) bool {
a, b := jsonContents[i], jsonContents[j]
aKey := prefixedRegexp.FindStringSubmatch(a.Term)[2]
bKey := prefixedRegexp.FindStringSubmatch(b.Term)[2]

return aKey < bKey
})

for _, term := range jsonContents {
// Filter by term prefix
matches := prefixedRegexp.FindStringSubmatch(term.Term)
Expand Down
6 changes: 3 additions & 3 deletions convert/poe2arb/testdata/attributes-req-attrs.golden
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"@@locale": "en",
"noAttrs": "Foobar",
"@noAttrs": {},
"attrs": "Foo {bar}",
"@attrs": {
"placeholders": {
"bar": {
"type": "String"
}
}
}
},
"noAttrs": "Foobar",
"@noAttrs": {}
}
4 changes: 2 additions & 2 deletions convert/poe2arb/testdata/attributes.golden
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"@@locale": "en",
"noAttrs": "Foobar",
"attrs": "Foo {bar}",
"@attrs": {
"placeholders": {
"bar": {
"type": "String"
}
}
}
},
"noAttrs": "Foobar"
}

0 comments on commit 7faca3d

Please sign in to comment.