Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
run: |
npm install
npm run generate.go
cd ./clients/go/test
go test
cd ./clients/go
go test ./... -v
- name: License check
uses: phrase/actions/lawa-ci@v1
with:
Expand Down
31 changes: 21 additions & 10 deletions clients/go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Config struct {
Pull []byte
Push []byte

LocaleMapping map[string]string

UserAgent string
}

Expand Down Expand Up @@ -132,17 +134,19 @@ func configPath() (string, error) {

func (cfg *Config) UnmarshalYAML(unmarshal func(i interface{}) error) error {
m := map[string]interface{}{}
localeMapping := map[string]interface{}{}
err := ParseYAMLToMap(unmarshal, map[string]interface{}{
"access_token": &cfg.Credentials.Token,
"host": &cfg.Credentials.Host,
"debug": &cfg.Debug,
"page": &cfg.Page,
"per_page": &cfg.PerPage,
"project_id": &cfg.DefaultProjectID,
"file_format": &cfg.DefaultFileFormat,
"push": &cfg.Push,
"pull": &cfg.Pull,
"defaults": &m,
"access_token": &cfg.Credentials.Token,
"host": &cfg.Credentials.Host,
"debug": &cfg.Debug,
"page": &cfg.Page,
"per_page": &cfg.PerPage,
"project_id": &cfg.DefaultProjectID,
"file_format": &cfg.DefaultFileFormat,
"push": &cfg.Push,
"pull": &cfg.Pull,
"locale_mapping": &localeMapping,
"defaults": &m,
})
if err != nil {
return err
Expand All @@ -156,6 +160,13 @@ func (cfg *Config) UnmarshalYAML(unmarshal func(i interface{}) error) error {
}
}

if len(localeMapping) > 0 {
cfg.LocaleMapping, err = ConvertToStringMap(localeMapping)
if err != nil {
return err
}
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions clients/go/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ func TestParseConfig(t *testing.T) {
if config.Token != "123" {
t.Errorf("Got %s, expected %s", config.Token, "123")
}

if config.LocaleMapping["en"] != "English" {
t.Errorf("Got %s, expected %s", config.LocaleMapping["en"], "English")
}

}

func TestParseConfig_fromPath(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions clients/go/testdata/config_files/.phrase.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
phrase:
access_token: "123"
locale_mapping:
en: English
push:
sources:
- file: "./config/locales/<locale_name>.yml"
Expand Down
Loading