Skip to content

Commit

Permalink
ref(locale): use go-18n.Messge and rename i18n to locale (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 9, 2024
1 parent 218e56a commit b17e887
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 43 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"nakedret",
"natefinch",
"navi",
"nicksnyder",
"nolint",
"nolintlint",
"nosec",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/snivilised/cobrass v0.4.5
github.com/spf13/afero v1.11.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/snivilised/pixa/src/app/plog"
"github.com/snivilised/pixa/src/app/proxy"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/i18n"
"github.com/snivilised/pixa/src/locale"
)

type LocaleDetector interface {
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(i18n.RootCmdShortDescTemplData{}),
Long: xi18n.Text(i18n.RootCmdLongDescTemplData{}),
Short: xi18n.Text(locale.RootCmdShortDescTemplData{}),
Long: xi18n.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(i18n.UsingConfigFileTemplData{
msg := xi18n.Text(locale.UsingConfigFileTemplData{
ConfigFileName: b.OptionsInfo.Config.Viper.ConfigFileUsed(),
})

Expand Down
28 changes: 14 additions & 14 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/snivilised/pixa/src/app/proxy"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/i18n"
"github.com/snivilised/pixa/src/locale"
)

// We define all the options here, even the ones inherited from the root
Expand Down Expand Up @@ -83,11 +83,11 @@ type shrinkParameterSetPtr = *assistant.ParamSet[common.ShrinkParameterSet]
func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cobra.Command {
shrinkCommand := &cobra.Command{
Use: "shrink",
Short: i18n.LeadsWith(
Short: locale.LeadsWith(
"shrink",
xi18n.Text(i18n.ShrinkCmdShortDefinitionTemplData{}),
xi18n.Text(locale.ShrinkCmdShortDefinitionTemplData{}),
),
Long: xi18n.Text(i18n.ShrinkLongDefinitionTemplData{}),
Long: xi18n.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(i18n.ShrinkCmdOutputPathParamUsageTemplData{}),
xi18n.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(i18n.ShrinkCmdTrashPathParamUsageTemplData{}),
xi18n.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(i18n.ShrinkCmdCuddleParamUsageTemplData{}),
xi18n.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(i18n.ShrinkCmdGaussianBlurParamUsageTemplData{}),
xi18n.Text(locale.ShrinkCmdGaussianBlurParamUsageTemplData{}),
defaultBlur,
),
&paramSet.Native.ThirdPartySet.GaussianBlur,
Expand All @@ -246,15 +246,15 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedEnum(
newShrinkFlagInfoWithShort(
xi18n.Text(i18n.ShrinkCmdSamplingFactorParamUsageTemplData{}),
xi18n.Text(locale.ShrinkCmdSamplingFactorParamUsageTemplData{}),
defaultSamplingFactor,
),
&paramSet.Native.ThirdPartySet.SamplingFactorEn.Source,
func(value string, f *pflag.Flag) error {
if f.Changed && !(common.SamplingFactorEnumInfo.IsValid(value)) {
acceptableSet := common.SamplingFactorEnumInfo.AcceptablePrimes()

return i18n.NewInvalidSamplingFactorError(value, acceptableSet)
return locale.NewInvalidSamplingFactorError(value, acceptableSet)
}

return nil
Expand All @@ -271,15 +271,15 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindValidatedEnum(
newShrinkFlagInfoWithShort(
xi18n.Text(i18n.ShrinkCmdInterlaceParamUsageTemplData{}),
xi18n.Text(locale.ShrinkCmdInterlaceParamUsageTemplData{}),
defaultInterlace,
),
&paramSet.Native.ThirdPartySet.InterlaceEn.Source,
func(value string, f *pflag.Flag) error {
if f.Changed && !(common.InterlaceEnumInfo.IsValid(value)) {
acceptableSet := common.InterlaceEnumInfo.AcceptablePrimes()

return i18n.NewInterlaceError(value, acceptableSet)
return locale.NewInterlaceError(value, acceptableSet)
}

return nil
Expand All @@ -294,7 +294,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

paramSet.BindBool(
newShrinkFlagInfoWithShort(
xi18n.Text(i18n.ShrinkCmdStripParamUsageTemplData{}),
xi18n.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(i18n.ShrinkCmdQualityParamUsageTemplData{}),
xi18n.Text(locale.ShrinkCmdQualityParamUsageTemplData{}),
defaultQuality,
),
&paramSet.Native.ThirdPartySet.Quality,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/helpers/test-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/snivilised/cobrass/src/assistant/configuration"
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/i18n"
"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"
Expand Down Expand Up @@ -122,7 +122,7 @@ func UseI18n(l10nPath string) error {
uo.From = xi18n.LoadFrom{
Path: l10nPath,
Sources: xi18n.TranslationFiles{
i18n.PixaSourceID: xi18n.TranslationSource{
locale.PixaSourceID: xi18n.TranslationSource{
Name: "dummy-cobrass",
},

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package i18n_test
package locale_test

import (
"testing"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/onsi/gomega"
)

func TestI18n(t *testing.T) {
func TestLocale(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "I18n Suite")
ginkgo.RunSpecs(t, "Locale Suite")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package i18n
package locale

import (
"github.com/nicksnyder/go-i18n/v2/i18n"
xi18n "github.com/snivilised/extendio/i18n"
)

Expand All @@ -12,8 +13,8 @@ type ShrinkCmdSamplingFactorInvalidTemplData struct {
Acceptable string
}

func (td ShrinkCmdSamplingFactorInvalidTemplData) Message() *xi18n.Message {
return &xi18n.Message{
func (td ShrinkCmdSamplingFactorInvalidTemplData) Message() *i18n.Message {
return &i18n.Message{
ID: "shrink-cmd-sampling-factor-invalid.error",
Description: "shrink command sampling factor failed validation",
Other: "invalid sampling factor value: {{.Value}}, acceptable: {{.Acceptable}}",
Expand Down Expand Up @@ -49,8 +50,8 @@ type ShrinkCmdInterlaceInvalidTemplData struct {
Acceptable string
}

func (td ShrinkCmdInterlaceInvalidTemplData) Message() *xi18n.Message {
return &xi18n.Message{
func (td ShrinkCmdInterlaceInvalidTemplData) Message() *i18n.Message {
return &i18n.Message{
ID: "shrink-cmd-interlace-invalid.error",
Description: "shrink command interlace failed validation",
Other: "invalid interlace value: {{.Value}}, acceptable: {{.Acceptable}}",
Expand Down Expand Up @@ -85,8 +86,8 @@ type ShrinkCmdOutputPathDoesNotExistTemplData struct {
Path string
}

func (td ShrinkCmdOutputPathDoesNotExistTemplData) Message() *xi18n.Message {
return &xi18n.Message{
func (td ShrinkCmdOutputPathDoesNotExistTemplData) Message() *i18n.Message {
return &i18n.Message{
ID: "shrink-cmd-output-path-does-not-exist.error",
Description: "shrink command mirror path does not exist validation",
Other: "output path: {{.Path}}, does not exist",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package i18n
package locale

import (
"github.com/snivilised/extendio/i18n"
"github.com/nicksnyder/go-i18n/v2/i18n"
)

// ⚠️ for the usage definitions, make sure that the first token inside the "Other"
Expand Down
9 changes: 5 additions & 4 deletions src/i18n/messages-errors.go → src/locale/messages-errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package i18n
package locale

import (
i18n "github.com/snivilised/extendio/i18n"
i18n "github.com/nicksnyder/go-i18n/v2/i18n"
xi18n "github.com/snivilised/extendio/i18n"
)

// ❌ FooBar
Expand Down Expand Up @@ -34,7 +35,7 @@ type FooBarErrorBehaviourQuery interface {
}

type FooBarError struct {
i18n.LocalisableError
xi18n.LocalisableError
}

// FooBar enables the client to check if error is FooBarError
Expand All @@ -46,7 +47,7 @@ func (e FooBarError) FooBar() bool {
// NewFooBarError creates a FooBarError
func NewFooBarError(path string, reason error) FooBarError {
return FooBarError{
LocalisableError: i18n.LocalisableError{
LocalisableError: xi18n.LocalisableError{
Data: FooBarTemplData{
Path: path,
Reason: reason,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package i18n
package locale

import (
"github.com/snivilised/extendio/i18n"
"github.com/nicksnyder/go-i18n/v2/i18n"
)

type UsingConfigFileTemplData struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package i18n_test
package locale_test

import (
"github.com/snivilised/extendio/i18n"
"github.com/nicksnyder/go-i18n/v2/i18n"
)

const (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package i18n
package locale

// TODO: Should be updated to use url of the implementing project,
// so should not be left as arcadia.
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/utils.go → src/locale/utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package i18n
package locale

import (
"strings"
Expand Down

0 comments on commit b17e887

Please sign in to comment.