4
4
import com .crowdin .cli .client .CrowdinProjectFull ;
5
5
import com .crowdin .cli .client .CrowdinProjectInfo ;
6
6
import com .crowdin .cli .client .ProjectClient ;
7
+ import com .crowdin .cli .client .ResponseException ;
7
8
import com .crowdin .cli .commands .NewAction ;
8
9
import com .crowdin .cli .commands .Outputter ;
9
10
import com .crowdin .cli .commands .functionality .ProjectFilesUtils ;
13
14
import com .crowdin .cli .utils .console .ConsoleSpinner ;
14
15
import com .crowdin .client .labels .model .Label ;
15
16
import com .crowdin .client .languages .model .Language ;
17
+ import com .crowdin .client .machinetranslationengines .model .MachineTranslation ;
16
18
import com .crowdin .client .projectsgroups .model .Type ;
17
19
import com .crowdin .client .sourcefiles .model .Branch ;
18
20
import com .crowdin .client .sourcefiles .model .FileInfo ;
24
26
import java .util .stream .Collectors ;
25
27
26
28
import static com .crowdin .cli .BaseCli .RESOURCE_BUNDLE ;
29
+ import static com .crowdin .cli .utils .console .ExecutionStatus .OK ;
27
30
import static com .crowdin .cli .utils .console .ExecutionStatus .WARNING ;
28
31
29
32
@ AllArgsConstructor
@@ -50,7 +53,7 @@ public void act(Outputter out, PropertiesWithFiles properties, ProjectClient cli
50
53
this .noProgress , this .plainView , () -> client .downloadFullProject (this .branchName ));
51
54
boolean isStringsBasedProject = Objects .equals (project .getType (), Type .STRINGS_BASED );
52
55
53
- List <String > languages = this .prepareLanguageIds (project );
56
+ List <String > languages = this .prepareLanguageIds (project , client , out );
54
57
List <Long > labelIds = this .prepareLabelIds (out , client );
55
58
56
59
if (isStringsBasedProject ) {
@@ -121,23 +124,35 @@ public void act(Outputter out, PropertiesWithFiles properties, ProjectClient cli
121
124
}
122
125
}
123
126
124
- private List <String > prepareLanguageIds (CrowdinProjectInfo projectInfo ) {
127
+ private List <String > prepareLanguageIds (CrowdinProjectInfo projectInfo , ProjectClient client , Outputter out ) {
125
128
List <String > projectLanguages = projectInfo .getProjectLanguages (false ).stream ()
126
129
.map (Language ::getId )
127
130
.collect (Collectors .toList ());
128
- if (languageIds .size () == 1 && BaseCli .ALL .equalsIgnoreCase (languageIds .get (0 ))) {
129
- return projectLanguages ;
130
- } else {
131
- String wrongLanguageIds = languageIds .stream ()
132
- .filter (langId -> !projectLanguages .contains (langId ))
133
- .map (id -> "'" + id + "'" )
134
- .collect (Collectors .joining (", " ));
135
- if (!wrongLanguageIds .isEmpty ()) {
136
- throw new ExitCodeExceptionMapper .NotFoundException (
137
- String .format (RESOURCE_BUNDLE .getString ("error.languages_not_exist" ), wrongLanguageIds ));
131
+ if (languageIds == null || (languageIds .size () == 1 && BaseCli .ALL .equalsIgnoreCase (languageIds .get (0 )))) {
132
+ if (Method .MT .equals (method )) {
133
+ try {
134
+ ConsoleSpinner .start (out , RESOURCE_BUNDLE .getString ("message.spinner.validating_mt_languages" ), this .noProgress );
135
+ MachineTranslation mt = client .getMt (engineId );
136
+ ConsoleSpinner .stop (OK , RESOURCE_BUNDLE .getString ("message.spinner.validation_success" ));
137
+ Set <String > supportedMtLanguageIds = new HashSet <>(mt .getSupportedLanguageIds ());
138
+ return projectLanguages .stream ()
139
+ .filter (supportedMtLanguageIds ::contains )
140
+ .collect (Collectors .toList ());
141
+ } catch (ResponseException e ) {
142
+ ConsoleSpinner .stop (WARNING , String .format (RESOURCE_BUNDLE .getString ("message.spinner.validation_error" ), e .getMessage ()));
143
+ }
138
144
}
139
- return languageIds ;
145
+ return projectLanguages ;
146
+ }
147
+ String wrongLanguageIds = languageIds .stream ()
148
+ .filter (langId -> !projectLanguages .contains (langId ))
149
+ .map (id -> "'" + id + "'" )
150
+ .collect (Collectors .joining (", " ));
151
+ if (!wrongLanguageIds .isEmpty ()) {
152
+ throw new ExitCodeExceptionMapper .NotFoundException (
153
+ String .format (RESOURCE_BUNDLE .getString ("error.languages_not_exist" ), wrongLanguageIds ));
140
154
}
155
+ return languageIds ;
141
156
}
142
157
143
158
private List <Long > prepareLabelIds (Outputter out , ProjectClient client ) {
0 commit comments