From cbb06f475928bc0c366dd6cbc31ff7317e5e7e4f Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Tue, 24 Sep 2024 15:44:50 +0200 Subject: [PATCH 01/13] add new download parameters --- paths/locales/download.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/paths/locales/download.yaml b/paths/locales/download.yaml index 0f309a8e..2347cc78 100644 --- a/paths/locales/download.yaml +++ b/paths/locales/download.yaml @@ -112,6 +112,18 @@ parameters: in: query schema: type: string + - description: Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job. + example: "prefix_" + name: translation_key_prefix + in: query + schema: + type: string + - description: Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job. + example: + name: use_translation_key_prefix_as_filter + in: query + schema: + type: boolean - name: custom_metadata_filters in: query description: | From b3f054617fcfaae8872ec599e83f91e863e4fcde Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Tue, 24 Sep 2024 16:48:50 +0200 Subject: [PATCH 02/13] add support to use the file path as prefix --- clients/cli/cmd/internal/pull_target.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clients/cli/cmd/internal/pull_target.go b/clients/cli/cmd/internal/pull_target.go index 68914ee6..1a8b9cc1 100644 --- a/clients/cli/cmd/internal/pull_target.go +++ b/clients/cli/cmd/internal/pull_target.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" + "github.com/antihax/optional" "github.com/phrase/phrase-cli/cmd/internal/paths" "github.com/phrase/phrase-cli/cmd/internal/placeholders" "github.com/phrase/phrase-cli/cmd/internal/shared" @@ -190,6 +191,9 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { if target.FileFormat == "" { target.FileFormat = fileFormat } + if target.Params.TranslationKeyPrefix.Value() == "" { + target.Params.TranslationKeyPrefix = optional.NewString(TruncateString(target.File)) + } validTargets = append(validTargets, target) } @@ -199,3 +203,10 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { return validTargets, nil } + +func TruncateString(s string) string { + if len(s) > 255 { + return s[len(s)-255:] + } + return s +} From 9d3b36456cbf992dae2ebafe7d75c69dd64a4c77 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 08:52:32 +0200 Subject: [PATCH 03/13] fix test --- .../test/java/com/phrase/client/api/LocalesApiTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java index abbdf5f8..a6de8c98 100644 --- a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java +++ b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java @@ -169,7 +169,14 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx String fallbackLocaleId = null; String sourceLocaleId = null; Object customMetadataFilters = null; - File response = api.localeDownload(projectId, id, xPhraseAppOTP, ifModifiedSince, ifNoneMatch, branch, fileFormat, tags, tag, includeEmptyTranslations, excludeEmptyZeroForms, includeTranslatedKeys, keepNotranslateTags, convertEmoji, formatOptions, encoding, skipUnverifiedTranslations, includeUnverifiedTranslations, useLastReviewedVersion, fallbackLocaleId, sourceLocaleId, customMetadataFilters); + String translationKeyPrefix = null; + Boolean useTranslationKeyPrefixAsFilter = null; + File response = api.localeDownload(projectId, id, xPhraseAppOTP, ifModifiedSince, ifNoneMatch, + branch, fileFormat, tags, tag, includeEmptyTranslations, excludeEmptyZeroForms, + includeTranslatedKeys, keepNotranslateTags, convertEmoji, formatOptions, encoding, + skipUnverifiedTranslations, includeUnverifiedTranslations, useLastReviewedVersion, + fallbackLocaleId, sourceLocaleId, customMetadataFilters, translationKeyPrefix, + useTranslationKeyPrefixAsFilter); String fileContents = new String(java.nio.file.Files.readAllBytes(response.toPath())); Assert.assertEquals("Correct file contents", fileContents, body); From 5ea0de410b34ddb5714cc691e4663b6679669a08 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 09:01:00 +0200 Subject: [PATCH 04/13] update descriptions for new parameters --- doc/compiled.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/compiled.json b/doc/compiled.json index cab923ae..5488f7a1 100644 --- a/doc/compiled.json +++ b/doc/compiled.json @@ -8775,6 +8775,24 @@ "type": "string" } }, + { + "description": "Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job.", + "example": "prefix_", + "name": "translation_key_prefix", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "description": "Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job.", + "example": null, + "name": "use_translation_key_prefix_as_filter", + "in": "query", + "schema": { + "type": "boolean" + } + }, { "name": "custom_metadata_filters", "in": "query", From d6142006a3cb6f23c54decf92b8d676edf4e092e Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 10:34:09 +0200 Subject: [PATCH 05/13] update descriptions and test --- .../src/test/java/com/phrase/client/api/LocalesApiTest.java | 4 ++-- paths/locales/download.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java index a6de8c98..d44a0ec0 100644 --- a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java +++ b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java @@ -175,8 +175,8 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx branch, fileFormat, tags, tag, includeEmptyTranslations, excludeEmptyZeroForms, includeTranslatedKeys, keepNotranslateTags, convertEmoji, formatOptions, encoding, skipUnverifiedTranslations, includeUnverifiedTranslations, useLastReviewedVersion, - fallbackLocaleId, sourceLocaleId, customMetadataFilters, translationKeyPrefix, - useTranslationKeyPrefixAsFilter); + fallbackLocaleId, sourceLocaleId, translationKeyPrefix, useTranslationKeyPrefixAsFilter, + customMetadataFilters); String fileContents = new String(java.nio.file.Files.readAllBytes(response.toPath())); Assert.assertEquals("Correct file contents", fileContents, body); diff --git a/paths/locales/download.yaml b/paths/locales/download.yaml index 2347cc78..3baf8f3d 100644 --- a/paths/locales/download.yaml +++ b/paths/locales/download.yaml @@ -112,13 +112,13 @@ parameters: in: query schema: type: string - - description: Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job. + - description: "Download all translation keys, and remove the specified prefix where possible. Warning: this may create duplicate key names if other keys share the same name after the prefix is removed." example: "prefix_" name: translation_key_prefix in: query schema: type: string - - description: Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job. + - description: Only download translation keys containing the specified prefix, and remove the prefix from the generated file. example: name: use_translation_key_prefix_as_filter in: query From a3ae3ace8065ebf433bb05222791c5b27f359c76 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 10:36:09 +0200 Subject: [PATCH 06/13] update the doc file --- doc/compiled.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/compiled.json b/doc/compiled.json index 5488f7a1..02b4fda8 100644 --- a/doc/compiled.json +++ b/doc/compiled.json @@ -8776,7 +8776,7 @@ } }, { - "description": "Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job.", + "description": "Download all translation keys, and remove the specified prefix where possible. Warning: this may create duplicate key names if other keys share the same name after the prefix is removed.", "example": "prefix_", "name": "translation_key_prefix", "in": "query", @@ -8785,7 +8785,7 @@ } }, { - "description": "Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a tag parameter indicating a specific job.", + "description": "Only download translation keys containing the specified prefix, and remove the prefix from the generated file.", "example": null, "name": "use_translation_key_prefix_as_filter", "in": "query", From 815efb577f529d305191a740893570818c69f89b Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 10:39:17 +0200 Subject: [PATCH 07/13] fix php test --- clients/php/test/Api/LocalesApiTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clients/php/test/Api/LocalesApiTest.php b/clients/php/test/Api/LocalesApiTest.php index fa62833b..cea02557 100644 --- a/clients/php/test/Api/LocalesApiTest.php +++ b/clients/php/test/Api/LocalesApiTest.php @@ -165,6 +165,8 @@ public function testLocaleDownload() null, null, null, + null, + null, $custom_metadata_filters ); From a83a76af5b93b6eb3b5f74b9bcd5162a756bb837 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 11:40:58 +0200 Subject: [PATCH 08/13] add new param for upload --- doc/compiled.json | 5 +++++ paths/uploads/create.yaml | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/doc/compiled.json b/doc/compiled.json index 02b4fda8..c6a05d89 100644 --- a/doc/compiled.json +++ b/doc/compiled.json @@ -15077,6 +15077,11 @@ "type": "boolean", "default": false, "example": null + }, + "translation_key_prefix": { + "description": "This prefix will be added to all uploaded translation key names to prevent collisions. Use a meaningful prefix related to your project or file to keep key names organized.", + "type": "string", + "example": "prefix_" } } } diff --git a/paths/uploads/create.yaml b/paths/uploads/create.yaml index 53115249..0225dfab 100644 --- a/paths/uploads/create.yaml +++ b/paths/uploads/create.yaml @@ -143,4 +143,8 @@ requestBody: type: boolean default: false example: + translation_key_prefix: + description: This prefix will be added to all uploaded translation key names to prevent collisions. Use a meaningful prefix related to your project or file to keep key names organized. + type: string + example: prefix_ x-cli-version: '2.12' From ee7a86b7613fade02d9f8fac05a8bce1b37d6a62 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 11:41:16 +0200 Subject: [PATCH 09/13] accept file path as prefix --- clients/cli/cmd/internal/init.go | 7 +++++++ clients/cli/cmd/internal/pull_target.go | 9 +-------- clients/cli/cmd/internal/push_source.go | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/clients/cli/cmd/internal/init.go b/clients/cli/cmd/internal/init.go index 73ff5f53..212168bc 100644 --- a/clients/cli/cmd/internal/init.go +++ b/clients/cli/cmd/internal/init.go @@ -406,3 +406,10 @@ func firstPush() error { cmd := &PushCommand{Config: *config} return cmd.Run() } + +func TruncateString(s string, length int) string { + if len(s) > length { + return s[len(s)-length:] + } + return s +} diff --git a/clients/cli/cmd/internal/pull_target.go b/clients/cli/cmd/internal/pull_target.go index 1a8b9cc1..aaf600c3 100644 --- a/clients/cli/cmd/internal/pull_target.go +++ b/clients/cli/cmd/internal/pull_target.go @@ -192,7 +192,7 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { target.FileFormat = fileFormat } if target.Params.TranslationKeyPrefix.Value() == "" { - target.Params.TranslationKeyPrefix = optional.NewString(TruncateString(target.File)) + target.Params.TranslationKeyPrefix = optional.NewString(TruncateString(target.File, 255)) } validTargets = append(validTargets, target) } @@ -203,10 +203,3 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { return validTargets, nil } - -func TruncateString(s string) string { - if len(s) > 255 { - return s[len(s)-255:] - } - return s -} diff --git a/clients/cli/cmd/internal/push_source.go b/clients/cli/cmd/internal/push_source.go index c60837de..e8256dd0 100644 --- a/clients/cli/cmd/internal/push_source.go +++ b/clients/cli/cmd/internal/push_source.go @@ -50,6 +50,9 @@ func SourcesFromConfig(config phrase.Config) (Sources, error) { if source.Params == nil { source.Params = new(UploadParams) } + if source.Params.TranslationKeyPrefix.Value() == "" { + source.Params.TranslationKeyPrefix = optional.NewString(TruncateString(source.File, 255)) + } if !source.Params.FileFormat.IsSet() { switch { From 3a6c754f031756c77e1a3ea75091b19741832d58 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Wed, 25 Sep 2024 15:38:58 +0200 Subject: [PATCH 10/13] add changes after rebase --- .../test/java/com/phrase/client/api/UploadsApiTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java b/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java index a19a8408..3d3699d1 100644 --- a/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java +++ b/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java @@ -109,6 +109,7 @@ public void uploadCreateTest() throws ApiException, IOException, InterruptedExce Boolean autotranslate = null; Boolean markReviewed = null; Boolean tagOnlyAffectedKeys = null; + String translationKeyPrefix = null; Map nestedFormatOptionsMap = new HashMap<>(); nestedFormatOptionsMap.put("nested_option", "sub_option"); @@ -118,7 +119,11 @@ public void uploadCreateTest() throws ApiException, IOException, InterruptedExce formatOptionsMap.put("fallback_language", "en"); formatOptionsMap.put("more_options", nestedFormatOptionsMap); - Upload response = api.uploadCreate(projectId, file, fileFormat, localeId, xPhraseAppOTP, branch, tags, updateTranslations, updateTranslationKeys, updateTranslationsOnSourceMatch, updateDescriptions, convertEmoji, skipUploadTags, skipUnverification, fileEncoding, localeMapping, formatOptionsMap, autotranslate, markReviewed, tagOnlyAffectedKeys); + Upload response = api.uploadCreate(projectId, file, fileFormat, localeId, xPhraseAppOTP, branch, + tags, updateTranslations, updateTranslationKeys, updateTranslationsOnSourceMatch, + updateDescriptions, convertEmoji, skipUploadTags, skipUnverification, fileEncoding, + localeMapping, formatOptionsMap, autotranslate, markReviewed, tagOnlyAffectedKeys, + translationKeyPrefix); Assert.assertEquals("valid id returned", "id_example", response.getId()); Assert.assertEquals("valid creation date returned", OffsetDateTime.parse("2015-01-28T09:52:53Z"), response.getCreatedAt()); From 4f1ceeb0d1ad3b1dac2e6632f1f7ef1b43724b16 Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Thu, 26 Sep 2024 12:53:42 +0200 Subject: [PATCH 11/13] don't truncate file path to throw phrase error and stay transparent --- clients/cli/cmd/internal/init.go | 7 ------- clients/cli/cmd/internal/pull_target.go | 2 +- clients/cli/cmd/internal/push_source.go | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/clients/cli/cmd/internal/init.go b/clients/cli/cmd/internal/init.go index 212168bc..73ff5f53 100644 --- a/clients/cli/cmd/internal/init.go +++ b/clients/cli/cmd/internal/init.go @@ -406,10 +406,3 @@ func firstPush() error { cmd := &PushCommand{Config: *config} return cmd.Run() } - -func TruncateString(s string, length int) string { - if len(s) > length { - return s[len(s)-length:] - } - return s -} diff --git a/clients/cli/cmd/internal/pull_target.go b/clients/cli/cmd/internal/pull_target.go index aaf600c3..5c3db22b 100644 --- a/clients/cli/cmd/internal/pull_target.go +++ b/clients/cli/cmd/internal/pull_target.go @@ -192,7 +192,7 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { target.FileFormat = fileFormat } if target.Params.TranslationKeyPrefix.Value() == "" { - target.Params.TranslationKeyPrefix = optional.NewString(TruncateString(target.File, 255)) + target.Params.TranslationKeyPrefix = optional.NewString(target.File) } validTargets = append(validTargets, target) } diff --git a/clients/cli/cmd/internal/push_source.go b/clients/cli/cmd/internal/push_source.go index e8256dd0..8ec37c0e 100644 --- a/clients/cli/cmd/internal/push_source.go +++ b/clients/cli/cmd/internal/push_source.go @@ -51,7 +51,7 @@ func SourcesFromConfig(config phrase.Config) (Sources, error) { source.Params = new(UploadParams) } if source.Params.TranslationKeyPrefix.Value() == "" { - source.Params.TranslationKeyPrefix = optional.NewString(TruncateString(source.File, 255)) + source.Params.TranslationKeyPrefix = optional.NewString(source.File) } if !source.Params.FileFormat.IsSet() { From 580589efd54df3b1d16ecf1e51587bbf2715a7bf Mon Sep 17 00:00:00 2001 From: Matias Alvarez Date: Thu, 26 Sep 2024 16:27:51 +0200 Subject: [PATCH 12/13] change the name of the parameter --- .../src/test/java/com/phrase/client/api/LocalesApiTest.java | 4 ++-- doc/compiled.json | 2 +- paths/locales/download.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java index d44a0ec0..ee541541 100644 --- a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java +++ b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java @@ -170,12 +170,12 @@ public void localeDownloadTest() throws ApiException, IOException, InterruptedEx String sourceLocaleId = null; Object customMetadataFilters = null; String translationKeyPrefix = null; - Boolean useTranslationKeyPrefixAsFilter = null; + Boolean filterByPrefix = null; File response = api.localeDownload(projectId, id, xPhraseAppOTP, ifModifiedSince, ifNoneMatch, branch, fileFormat, tags, tag, includeEmptyTranslations, excludeEmptyZeroForms, includeTranslatedKeys, keepNotranslateTags, convertEmoji, formatOptions, encoding, skipUnverifiedTranslations, includeUnverifiedTranslations, useLastReviewedVersion, - fallbackLocaleId, sourceLocaleId, translationKeyPrefix, useTranslationKeyPrefixAsFilter, + fallbackLocaleId, sourceLocaleId, translationKeyPrefix, filterByPrefix, customMetadataFilters); String fileContents = new String(java.nio.file.Files.readAllBytes(response.toPath())); diff --git a/doc/compiled.json b/doc/compiled.json index c6a05d89..2129dca2 100644 --- a/doc/compiled.json +++ b/doc/compiled.json @@ -8787,7 +8787,7 @@ { "description": "Only download translation keys containing the specified prefix, and remove the prefix from the generated file.", "example": null, - "name": "use_translation_key_prefix_as_filter", + "name": "filter_by_prefix", "in": "query", "schema": { "type": "boolean" diff --git a/paths/locales/download.yaml b/paths/locales/download.yaml index 3baf8f3d..406b55be 100644 --- a/paths/locales/download.yaml +++ b/paths/locales/download.yaml @@ -120,7 +120,7 @@ parameters: type: string - description: Only download translation keys containing the specified prefix, and remove the prefix from the generated file. example: - name: use_translation_key_prefix_as_filter + name: filter_by_prefix in: query schema: type: boolean From f0a0ef4c5d4402e9f7851967410c39bdee4c85b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Behrendt?= Date: Wed, 2 Oct 2024 10:41:56 +0200 Subject: [PATCH 13/13] Fix placeholders in file path --- .../cmd/internal/placeholders/placeholders.go | 21 +++++++++++++++++++ clients/cli/cmd/internal/pull.go | 6 ++++++ clients/cli/cmd/internal/pull_target.go | 4 ---- clients/cli/cmd/internal/push_source.go | 10 ++++++--- clients/cli/go.sum | 4 ++-- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/clients/cli/cmd/internal/placeholders/placeholders.go b/clients/cli/cmd/internal/placeholders/placeholders.go index edd3c970..94d47c8c 100644 --- a/clients/cli/cmd/internal/placeholders/placeholders.go +++ b/clients/cli/cmd/internal/placeholders/placeholders.go @@ -2,10 +2,12 @@ package placeholders import ( "fmt" + "os" "path/filepath" "regexp" "strings" + "github.com/antihax/optional" "github.com/phrase/phrase-cli/cmd/internal/stringz" ) @@ -92,3 +94,22 @@ func Resolve(s, pattern string) (map[string]string, error) { return values, nil } + +func ResolveTranslationKeyPrefix(translationKeyPrefix optional.String, filePath string) (optional.String, error) { + if strings.Contains(translationKeyPrefix.Value(), "") { + currentDir, err := os.Getwd() + if err != nil { + return optional.EmptyString(), err + } + + filePath, err := filepath.Rel(currentDir, filePath) + if err != nil { + return optional.EmptyString(), err + } + + resolvedKeyPrefix := strings.Replace(translationKeyPrefix.Value(), "", filePath, 1) + return optional.NewString(resolvedKeyPrefix), nil + } + + return translationKeyPrefix, nil +} diff --git a/clients/cli/cmd/internal/pull.go b/clients/cli/cmd/internal/pull.go index 523a6a82..4b8c5558 100644 --- a/clients/cli/cmd/internal/pull.go +++ b/clients/cli/cmd/internal/pull.go @@ -144,6 +144,11 @@ func (target *Target) DownloadAndWriteToFile(client *phrase.APIClient, localeFil if target.Params != nil { localVarOptionals = target.Params.LocaleDownloadOpts + translationKeyPrefix, err := placeholders.ResolveTranslationKeyPrefix(target.Params.TranslationKeyPrefix, localeFile.Path) + if err != nil { + return err + } + localVarOptionals.TranslationKeyPrefix = translationKeyPrefix } if localVarOptionals.FileFormat.Value() == "" { @@ -170,6 +175,7 @@ func (target *Target) DownloadAndWriteToFile(client *phrase.APIClient, localeFil debugFprintln("Tags", localVarOptionals.Tags) debugFprintln("Branch", localVarOptionals.Branch) debugFprintln("FormatOptions", localVarOptionals.FormatOptions) + debugFprintln("TranslationKeyPrefix", localVarOptionals.TranslationKeyPrefix) if async { return target.downloadAsynchronously(client, localeFile, localVarOptionals) diff --git a/clients/cli/cmd/internal/pull_target.go b/clients/cli/cmd/internal/pull_target.go index 5c3db22b..68914ee6 100644 --- a/clients/cli/cmd/internal/pull_target.go +++ b/clients/cli/cmd/internal/pull_target.go @@ -6,7 +6,6 @@ import ( "path/filepath" "strings" - "github.com/antihax/optional" "github.com/phrase/phrase-cli/cmd/internal/paths" "github.com/phrase/phrase-cli/cmd/internal/placeholders" "github.com/phrase/phrase-cli/cmd/internal/shared" @@ -191,9 +190,6 @@ func TargetsFromConfig(config phrase.Config) (Targets, error) { if target.FileFormat == "" { target.FileFormat = fileFormat } - if target.Params.TranslationKeyPrefix.Value() == "" { - target.Params.TranslationKeyPrefix = optional.NewString(target.File) - } validTargets = append(validTargets, target) } diff --git a/clients/cli/cmd/internal/push_source.go b/clients/cli/cmd/internal/push_source.go index 8ec37c0e..e5265044 100644 --- a/clients/cli/cmd/internal/push_source.go +++ b/clients/cli/cmd/internal/push_source.go @@ -8,6 +8,7 @@ import ( "github.com/antihax/optional" "github.com/phrase/phrase-cli/cmd/internal/paths" + "github.com/phrase/phrase-cli/cmd/internal/placeholders" "github.com/phrase/phrase-go/v3" "github.com/spf13/viper" ) @@ -50,9 +51,6 @@ func SourcesFromConfig(config phrase.Config) (Sources, error) { if source.Params == nil { source.Params = new(UploadParams) } - if source.Params.TranslationKeyPrefix.Value() == "" { - source.Params.TranslationKeyPrefix = optional.NewString(source.File) - } if !source.Params.FileFormat.IsSet() { switch { @@ -202,6 +200,12 @@ func (source *Source) uploadFile(client *phrase.APIClient, localeFile *LocaleFil params.Branch = optional.NewString(branch) } + translationKeyPrefix, err := placeholders.ResolveTranslationKeyPrefix(params.UploadCreateOpts.TranslationKeyPrefix, localeFile.Path) + if err != nil { + return nil, err + } + params.UploadCreateOpts.TranslationKeyPrefix = translationKeyPrefix + upload, _, err := client.UploadsApi.UploadCreate(Auth, source.ProjectID, file, params.FileFormat.Value(), params.LocaleId.Value(), ¶ms.UploadCreateOpts) return &upload, err diff --git a/clients/cli/go.sum b/clients/cli/go.sum index 8a0936e6..6e83933a 100644 --- a/clients/cli/go.sum +++ b/clients/cli/go.sum @@ -220,8 +220,8 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= -github.com/phrase/phrase-go/v3 v3.3.0 h1:kq2eFgKE6mUUZpud1KWsTa1RO4T+ztB2JI3DsCfqHog= -github.com/phrase/phrase-go/v3 v3.3.0/go.mod h1:s0uOYiXLxKAYlaIS6TbKv3efkKFUlY4OB6OL+VgvK90= +github.com/phrase/phrase-go/v3 v3.5.0 h1:zviffIun5A10PNnnSV0ynHjs+VRY7fc9xXVtNOjkm3o= +github.com/phrase/phrase-go/v3 v3.5.0/go.mod h1:s0uOYiXLxKAYlaIS6TbKv3efkKFUlY4OB6OL+VgvK90= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=