diff --git a/convert/poe2arb/converter.go b/convert/poe2arb/converter.go index 0a86716..d3937a1 100644 --- a/convert/poe2arb/converter.go +++ b/convert/poe2arb/converter.go @@ -2,7 +2,6 @@ package poe2arb import ( - "cmp" "encoding/json" "errors" "fmt" @@ -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" @@ -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 { diff --git a/go.mod b/go.mod index bce6a7b..5d54794 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 298564a..3798500 100644 --- a/go.sum +++ b/go.sum @@ -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=