Skip to content
Open
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
17 changes: 9 additions & 8 deletions clients/cli/cmd/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ var stepFuncs = map[string]stepFunc{
// structs that can be marshalled to YAML to create a valid configuration file

type ConfigYAML struct {
Host string `yaml:"host,omitempty"`
AccessToken string `yaml:"access_token,omitempty"`
ProjectID string `yaml:"project_id"`
FileFormat string `yaml:"file_format,omitempty"`
PerPage int `yaml:"per_page,omitempty"`
Defaults map[string]map[string]interface{} `yaml:"defaults,omitempty"`
Push PushYAML `yaml:"push,omitempty"`
Pull PullYAML `yaml:"pull,omitempty"`
Host string `yaml:"host,omitempty"`
AccessToken string `yaml:"access_token,omitempty"`
ProjectID string `yaml:"project_id"`
FileFormat string `yaml:"file_format,omitempty"`
PerPage int `yaml:"per_page,omitempty"`
Defaults map[string]map[string]interface{} `yaml:"defaults,omitempty"`
Push PushYAML `yaml:"push,omitempty"`
Pull PullYAML `yaml:"pull,omitempty"`
LocaleMapping map[string]string `yaml:"locale_mapping,omitempty"`
}

type PushYAML struct {
Expand Down
15 changes: 14 additions & 1 deletion clients/cli/cmd/internal/pull_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Target struct {
AccessToken string `json:"access_token"`
FileFormat string `json:"file_format"`
Params *PullParams `json:"params" mapstructure:"omittable-nested,omitempty"`
LocaleMapping map[string]string
RemoteLocales []*phrase.Locale
}

Expand Down Expand Up @@ -118,7 +119,7 @@ func (target *Target) ReplacePlaceholders(localeFile *LocaleFile) (string, error
return "", err
}

path := strings.Replace(absPath, "<locale_name>", localeFile.Name, -1)
path := strings.Replace(absPath, "<locale_name>", target.applyLocaleMapping(localeFile.Name), -1)
path = strings.Replace(path, "<locale_code>", localeFile.Code, -1)
path = strings.Replace(path, "<tag>", localeFile.Tag, -1)

Expand Down Expand Up @@ -197,6 +198,7 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) {
if target.FileFormat == "" {
target.FileFormat = fileFormat
}
target.LocaleMapping = config.LocaleMapping
validTargets = append(validTargets, target)
}

Expand All @@ -206,3 +208,14 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) {

return validTargets, nil
}

// applyLocaleMapping returns the mapped local locale name if a mapping exists,
// otherwise returns the original remote name
func (target *Target) applyLocaleMapping(remoteName string) string {
if target.LocaleMapping != nil {
if localName, ok := target.LocaleMapping[remoteName]; ok {
return localName
}
}
return remoteName
}
Loading
Loading