Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make language mappings deterministic #241

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
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
Loading