Skip to content

Commit

Permalink
Merge pull request #242 from transifex/devel
Browse files Browse the repository at this point in the history
Merge for 1.6.17
  • Loading branch information
kbairak committed Sep 5, 2024
2 parents b0cf262 + e7feea3 commit 30dac14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
6 changes: 2 additions & 4 deletions internal/txlib/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,11 @@ func (task *ResourcePullTask) Run(send func(string), abort func()) {
}
sendMessage("Getting info", false)

localToRemoteLanguageMappings := makeLocalToRemoteLanguageMappings(
remoteToLocalLanguageMappings := makeRemoteToLocalLanguageMappings(
*cfg,
*cfgResource,
)
remoteToLocalLanguageMappings := makeRemoteToLocalLanguageMappings(
localToRemoteLanguageMappings,
)
localToRemoteLanguageMappings := reverseMap(remoteToLocalLanguageMappings)

var err error
var resource *jsonapi.Resource
Expand Down
8 changes: 5 additions & 3 deletions internal/txlib/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,11 @@ func (task *ResourcePushTask) Run(send func(string), abort func()) {
}
}
if args.Translation { // -t flag is set
localToRemoteLanguageMappings := makeLocalToRemoteLanguageMappings(
*cfg,
*cfgResource,
localToRemoteLanguageMappings := reverseMap(
makeRemoteToLocalLanguageMappings(
*cfg,
*cfgResource,
),
)
overrides := cfgResource.Overrides

Expand Down
22 changes: 10 additions & 12 deletions internal/txlib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func stringSliceContains(haystack []string, needle string) bool {
return false
}

func makeLocalToRemoteLanguageMappings(
func makeRemoteToLocalLanguageMappings(
cfg config.Config, cfgResource config.Resource,
) map[string]string {
// In the configuration, the language mappings are "remote code -> local
Expand All @@ -133,24 +133,22 @@ func makeLocalToRemoteLanguageMappings(
// reverse the maps

result := make(map[string]string)
for key, value := range cfg.Local.LanguageMappings {
result[value] = key
for transifexLanguageCode, localLanguageCode := range cfg.Local.LanguageMappings {
result[transifexLanguageCode] = localLanguageCode
}
for key, value := range cfgResource.LanguageMappings {
for transifexLanguageCode, localLanguageCode := range cfgResource.LanguageMappings {
// Resource language mappings overwrite "global" language mappings
result[value] = key
result[transifexLanguageCode] = localLanguageCode
}
return result
}

func makeRemoteToLocalLanguageMappings(
localToRemoteLanguageMappings map[string]string,
) map[string]string {
result := make(map[string]string)
for key, value := range localToRemoteLanguageMappings {
result[value] = key
func reverseMap(src map[string]string) map[string]string {
dst := make(map[string]string)
for key, value := range src {
dst[value] = key
}
return result
return dst
}

/*
Expand Down

0 comments on commit 30dac14

Please sign in to comment.