Skip to content

Commit 67eb7ae

Browse files
ja-openaiaurambaj
authored andcommitted
Don't upload empty files to Phrase TMS as it triggers an error.
1 parent 66ef94a commit 67eb7ae

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,46 @@ public void push(
161161
getEscapeTypeAtomicReference(nativeClient, optionsParser);
162162

163163
Stopwatch stopwatchGetTextUnitDTO = Stopwatch.createStarted();
164+
165+
String tagForUpload = getTagForUpload(repository.getName());
166+
164167
List<TextUnitDTO> search =
165168
getSourceTextUnitDTOs(repository, skipTextUnitsWithPattern, skipAssetsWithPathPattern);
166169
logger.info("Get Source TextUnitDTO for push took: {}", stopwatchGetTextUnitDTO.elapsed());
167-
String text = getFileContent(pluralSeparator, search, true, null, escapeType.get());
168170

169-
String tagForUpload = getTagForUpload(repository.getName());
170-
171-
if (nativeClient) {
172-
logger.debug("Pushing with native and options: {}", formatOptions);
173-
Stopwatch stopWatchPhaseNativePush = Stopwatch.createStarted();
174-
phraseClient.nativeUploadAndWait(
175-
projectId,
176-
repository.getSourceLocale().getBcp47Tag(),
177-
"xml",
178-
repository.getName() + "-strings.xml",
179-
text,
180-
ImmutableList.of(tagForUpload),
181-
formatOptions.isEmpty() ? null : formatOptions);
182-
logger.info(
183-
"Pushing with native and options: {}, took: {}",
184-
formatOptions,
185-
stopWatchPhaseNativePush.elapsed());
171+
if (!search.isEmpty()) {
172+
173+
String text = getFileContent(pluralSeparator, search, true, null, escapeType.get());
174+
175+
if (nativeClient) {
176+
logger.debug("Pushing with native and options: {}", formatOptions);
177+
Stopwatch stopWatchPhaseNativePush = Stopwatch.createStarted();
178+
phraseClient.nativeUploadAndWait(
179+
projectId,
180+
repository.getSourceLocale().getBcp47Tag(),
181+
"xml",
182+
repository.getName() + "-strings.xml",
183+
text,
184+
ImmutableList.of(tagForUpload),
185+
formatOptions.isEmpty() ? null : formatOptions);
186+
logger.info(
187+
"Pushing with native and options: {}, took: {}",
188+
formatOptions,
189+
stopWatchPhaseNativePush.elapsed());
190+
} else {
191+
phraseClient.uploadAndWait(
192+
projectId,
193+
repository.getSourceLocale().getBcp47Tag(),
194+
"xml",
195+
repository.getName() + "-strings.xml",
196+
text,
197+
ImmutableList.of(tagForUpload),
198+
null);
199+
}
186200
} else {
187-
phraseClient.uploadAndWait(
188-
projectId,
189-
repository.getSourceLocale().getBcp47Tag(),
190-
"xml",
191-
repository.getName() + "-strings.xml",
192-
text,
193-
ImmutableList.of(tagForUpload),
194-
null);
201+
logger.info(
202+
"Repository: {} as no strings, don't push as empty file trigger an error",
203+
repository.getName());
195204
}
196205

197206
boolean skipRemoveUnusedKeysAndTags =

0 commit comments

Comments
 (0)