Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort terms alphabetically in ARBs #86

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use natural sort order for ARB keys
Albert221 committed Apr 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d39f10bdd38113e0bc8f1d0d171aa85d516fab59
11 changes: 9 additions & 2 deletions convert/poe2arb/converter.go
Original file line number Diff line number Diff line change
@@ -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 {
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
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=