Skip to content

Commit

Permalink
Use natural sort order for ARB keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert221 committed Apr 3, 2024
1 parent 27c44a3 commit d39f10b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions convert/poe2arb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package poe2arb

import (
"cmp"
"encoding/json"
"errors"
"fmt"
Expand All @@ -11,6 +10,7 @@ import (
"slices"
"strings"

"facette.io/natsort"
"github.com/leancodepl/poe2arb/convert"
"github.com/leancodepl/poe2arb/flutter"
orderedmap "github.com/wk8/go-ordered-map/v2"
Expand Down Expand Up @@ -63,7 +63,14 @@ func (c *Converter) Convert(output io.Writer) error {
slices.SortStableFunc(jsonContents, func(a, b *convert.POETerm) int {
aKey := prefixedRegexp.FindStringSubmatch(a.Term)[2]
bKey := prefixedRegexp.FindStringSubmatch(b.Term)[2]
return cmp.Compare(aKey, bKey)

if aKey == bKey {
return 0
} else if natsort.Compare(aKey, bKey) {
return -1
} else {
return 1
}
})

for _, term := range jsonContents {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
)

require (
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:1pSweJFeR3Pqx7uoelppkzeegfUBXL6I2FFAbfXw570=
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:npRYmtaITVom7rcSo+pRURltHSG2r4TQM1cdqJ2dUB0=
github.com/TwiN/go-color v1.4.0 h1:fNbOwOrvup5oj934UragnW0B1WKaAkkB85q19Y7h4ng=
github.com/TwiN/go-color v1.4.0/go.mod h1:0QTVEPlu+AoCyTrho7bXbVkrCkVpdQr7YF7PYWEtSxM=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
Expand Down

0 comments on commit d39f10b

Please sign in to comment.