Skip to content

Commit

Permalink
ref: replace extendio.i18n with li18ngo (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 9, 2024
1 parent 6ae7817 commit 2e0dee7
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 52 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/snivilised/pixa

go 1.22
go 1.23.0

require (
github.com/charmbracelet/bubbletea v1.1.1
Expand All @@ -11,6 +11,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.47.0
github.com/snivilised/extendio v0.7.0
github.com/snivilised/li18ngo v0.1.4
github.com/snivilised/lorax v0.5.2
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/snivilised/cobrass v0.4.5 h1:NeU/NwuOuJzotqa4JwnqGqbV1fs1SjB6GF53sXFO
github.com/snivilised/cobrass v0.4.5/go.mod h1:hGVu/zjWVG3tRKo3P0tjelm5S44vMTa/w29ygnvi+lY=
github.com/snivilised/extendio v0.7.0 h1:MY6w9qCK5wVEvP2WpMT5ywJwpDJe97WHDGuwrsTLpek=
github.com/snivilised/extendio v0.7.0/go.mod h1:l8MwJOy9ojMQYJrSKRbQS3WfDylevnRtBp/zwAmFEKc=
github.com/snivilised/li18ngo v0.1.4 h1:y6EECoVFpmkud2yDEeBnMnebPmSvdrEZ/LAq1PoPctE=
github.com/snivilised/li18ngo v0.1.4/go.mod h1:Or3qUhpR6AM1X51i82RtyCvORWy2/hrxY9lg1i1gFTE=
github.com/snivilised/lorax v0.5.2 h1:iReIJl63tydiPSSD0YzsNQFX1CctmvMkYx0aSxoZJKo=
github.com/snivilised/lorax v0.5.2/go.mod h1:7H1JPgSn4h4p8NSqfl64raacYefdm/FiFkfcZ51PVHY=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down
14 changes: 7 additions & 7 deletions src/app/cfg/config-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/snivilised/cobrass/src/assistant/configuration"
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
"github.com/snivilised/extendio/collections"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/spf13/viper"
"golang.org/x/text/language"
Expand Down Expand Up @@ -216,18 +216,18 @@ func (c *configRunner) handleLangSetting(config configuration.ViperConfig) {
return parsedTag
},
func() language.Tag {
return xi18n.DefaultLanguage.Get()
return li18ngo.DefaultLanguage
},
)

err := xi18n.Use(func(uo *xi18n.UseOptions) {
err := li18ngo.Use(func(uo *li18ngo.UseOptions) {
uo.Tag = tag
uo.From = xi18n.LoadFrom{
Sources: xi18n.TranslationFiles{
c.sourceID: xi18n.TranslationSource{
uo.From = li18ngo.LoadFrom{
Sources: li18ngo.TranslationFiles{
c.sourceID: li18ngo.TranslationSource{
Name: c.applicationName,
},
ci18n.CobrassSourceID: xi18n.TranslationSource{
ci18n.CobrassSourceID: li18ngo.TranslationSource{
Name: "cobrass",
},
},
Expand Down
7 changes: 6 additions & 1 deletion src/app/cfg/config-runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/snivilised/cobrass/src/assistant/mocks"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
Expand Down Expand Up @@ -58,7 +59,7 @@ type runnerTE struct {
assert func(entry *runnerTE, runner common.ConfigRunner, err error)
}

var _ = Describe("ConfigRunner", func() {
var _ = Describe("ConfigRunner", Ordered, func() {
var (
repo string
configPath string
Expand All @@ -67,6 +68,10 @@ var _ = Describe("ConfigRunner", func() {
mock *mocks.MockViperConfig
)

BeforeAll(func() {
li18ngo.Use()
})

BeforeEach(func() {
viper.Reset()
vfs = storage.UseMemFS()
Expand Down
22 changes: 11 additions & 11 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/assistant/configuration"
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/extendio/xfs/utils"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/plog"
"github.com/snivilised/pixa/src/app/proxy"
Expand Down Expand Up @@ -51,7 +51,7 @@ func validatePositionalArgs(cmd *cobra.Command, args []string) error {
directory := utils.ResolvePath(args[0])

if !utils.Exists(directory) {
return xi18n.NewPathNotFoundError("shrink directory", directory)
return li18ngo.NewPathNotFoundError("shrink directory", directory)
}

return nil
Expand Down Expand Up @@ -125,8 +125,8 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
b.Container = assistant.NewCobraContainer(
&cobra.Command{
Use: "main",
Short: xi18n.Text(locale.RootCmdShortDescTemplData{}),
Long: xi18n.Text(locale.RootCmdLongDescTemplData{}),
Short: li18ngo.Text(locale.RootCmdShortDescTemplData{}),
Long: li18ngo.Text(locale.RootCmdLongDescTemplData{}),
Version: fmt.Sprintf("'%v'", Version),
RunE: func(_ *cobra.Command, args []string) error {
inputs := b.getRootInputs()
Expand Down Expand Up @@ -178,7 +178,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

func (b *Bootstrap) configure() {
if err := b.OptionsInfo.Runner.Run(); err != nil {
msg := xi18n.Text(locale.UsingConfigFileTemplData{
msg := li18ngo.Text(locale.UsingConfigFileTemplData{
ConfigFileName: b.OptionsInfo.Config.Viper.ConfigFileUsed(),
})

Expand All @@ -202,18 +202,18 @@ func handleLangSetting(config configuration.ViperConfig) {
return parsedTag
},
func() language.Tag {
return xi18n.DefaultLanguage.Get()
return li18ngo.DefaultLanguage
},
)

err := xi18n.Use(func(uo *xi18n.UseOptions) {
err := li18ngo.Use(func(uo *li18ngo.UseOptions) {
uo.Tag = tag
uo.From = xi18n.LoadFrom{
Sources: xi18n.TranslationFiles{
common.Definitions.Pixa.SourceID: xi18n.TranslationSource{
uo.From = li18ngo.LoadFrom{
Sources: li18ngo.TranslationFiles{
common.Definitions.Pixa.SourceID: li18ngo.TranslationSource{
Name: common.Definitions.Pixa.AppName,
},
ci18n.CobrassSourceID: xi18n.TranslationSource{
ci18n.CobrassSourceID: li18ngo.TranslationSource{
Name: "cobrass",
},
},
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/app/command/magick-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
. "github.com/onsi/gomega" //nolint:revive // foo

"github.com/snivilised/cobrass/src/assistant/configuration"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
Expand All @@ -28,7 +28,7 @@ var _ = Describe("MagickCmd", Ordered, func() {
})

BeforeEach(func() {
xi18n.ResetTx()
Expect(li18ngo.Use()).To(Succeed())
vfs, _ = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)
Expand Down
2 changes: 2 additions & 0 deletions src/app/command/root-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega" //nolint:revive // foo

"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
Expand All @@ -28,6 +29,7 @@ var _ = Describe("RootCmd", Ordered, func() {
)

BeforeAll(func() {
Expect(li18ngo.Use()).To(Succeed())
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
Expand Down
22 changes: 11 additions & 11 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/snivilised/cobrass"
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/store"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/utils"
"github.com/snivilised/li18ngo"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -85,9 +85,9 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
Use: "shrink",
Short: locale.LeadsWith(
"shrink",
xi18n.Text(locale.ShrinkCmdShortDefinitionTemplData{}),
li18ngo.Text(locale.ShrinkCmdShortDefinitionTemplData{}),
),
Long: xi18n.Text(locale.ShrinkLongDefinitionTemplData{}),
Long: li18ngo.Text(locale.ShrinkLongDefinitionTemplData{}),

RunE: func(cmd *cobra.Command, args []string) error {
var appErr error
Expand Down Expand Up @@ -168,7 +168,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedString(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdOutputPathParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdOutputPathParamUsageTemplData{}),
defaultOutputPath,
),
&paramSet.Native.OutputPath, func(_ string, _ *pflag.Flag) error {
Expand All @@ -190,7 +190,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedString(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdTrashPathParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdTrashPathParamUsageTemplData{}),
defaultTrashPath,
),
&paramSet.Native.TrashPath, func(_ string, _ *pflag.Flag) error {
Expand All @@ -212,7 +212,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindBool(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdCuddleParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdCuddleParamUsageTemplData{}),
defaultCuddle,
),
&paramSet.Native.Cuddle,
Expand All @@ -228,7 +228,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedFloat32Within(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdGaussianBlurParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdGaussianBlurParamUsageTemplData{}),
defaultBlur,
),
&paramSet.Native.ThirdPartySet.GaussianBlur,
Expand All @@ -246,7 +246,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedEnum(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdSamplingFactorParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdSamplingFactorParamUsageTemplData{}),
defaultSamplingFactor,
),
&paramSet.Native.ThirdPartySet.SamplingFactorEn.Source,
Expand All @@ -271,7 +271,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedEnum(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdInterlaceParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdInterlaceParamUsageTemplData{}),
defaultInterlace,
),
&paramSet.Native.ThirdPartySet.InterlaceEn.Source,
Expand All @@ -294,7 +294,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindBool(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdStripParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdStripParamUsageTemplData{}),
defaultStrip,
),
&paramSet.Native.ThirdPartySet.Strip,
Expand All @@ -310,7 +310,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedIntWithin(
newShrinkFlagInfoWithShort(
xi18n.Text(locale.ShrinkCmdQualityParamUsageTemplData{}),
li18ngo.Text(locale.ShrinkCmdQualityParamUsageTemplData{}),
defaultQuality,
),
&paramSet.Native.ThirdPartySet.Quality,
Expand Down
2 changes: 2 additions & 0 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
. "github.com/onsi/ginkgo/v2" //nolint:revive // foo
. "github.com/onsi/gomega" //nolint:revive // foo
"github.com/snivilised/cobrass/src/assistant/configuration"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"
Expand Down Expand Up @@ -92,6 +93,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
)

BeforeAll(func() {
Expect(li18ngo.Use()).To(Succeed())
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/app/proxy/filing/path-finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/samber/lo"

"github.com/snivilised/extendio/xfs/nav"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/app/proxy/filing"
Expand Down Expand Up @@ -52,6 +53,8 @@ var _ = Describe("PathFinder", Ordered, func() {
)

BeforeAll(func() {
Expect(li18ngo.Use()).To(Succeed())

schemes = &cfg.MsSchemesConfig{
"blur-sf": &cfg.MsSchemeConfig{
ProfilesData: []string{"blur", "sf"},
Expand Down
3 changes: 3 additions & 0 deletions src/app/proxy/pixa-legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/snivilised/cobrass/src/assistant/configuration"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/extendio/xfs/utils"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"

Expand Down Expand Up @@ -108,6 +109,8 @@ var _ = Describe("pixa-legacy", Ordered, func() {
)

BeforeAll(func() {
Expect(li18ngo.Use()).To(Succeed())

repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
Expand Down
File renamed without changes.
15 changes: 7 additions & 8 deletions src/internal/helpers/test-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (
"github.com/pkg/errors"
"github.com/snivilised/cobrass/src/assistant/configuration"
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/matchers"
"github.com/snivilised/pixa/src/locale"

xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/storage"
"golang.org/x/text/language"
)

Expand Down Expand Up @@ -118,15 +117,15 @@ func SetupTest(
}

func UseI18n(l10nPath string) error {
return xi18n.Use(func(uo *xi18n.UseOptions) {
uo.From = xi18n.LoadFrom{
return li18ngo.Use(func(uo *li18ngo.UseOptions) {
uo.From = li18ngo.LoadFrom{
Path: l10nPath,
Sources: xi18n.TranslationFiles{
locale.PixaSourceID: xi18n.TranslationSource{
Sources: li18ngo.TranslationFiles{
locale.PixaSourceID: li18ngo.TranslationSource{
Name: "dummy-cobrass",
},

ci18n.CobrassSourceID: xi18n.TranslationSource{
ci18n.CobrassSourceID: li18ngo.TranslationSource{
Name: "dummy-cobrass",
},
},
Expand Down
Loading

0 comments on commit 2e0dee7

Please sign in to comment.