@@ -16,6 +16,7 @@ import (
1616 "github.com/Smartling/smartling-cli/services/helpers/rlog"
1717
1818 api "github.com/Smartling/api-sdk-go/api/mt"
19+ smfile "github.com/Smartling/api-sdk-go/helpers/sm_file"
1920)
2021
2122// TranslateParams is the parameters for the RunTranslate method.
@@ -30,27 +31,38 @@ type TranslateParams struct {
3031 AccountUID api.AccountUID
3132}
3233
33- func (s service ) RunTranslate (ctx context.Context , p TranslateParams , files []string , updates chan any ) ([]TranslateOutput , error ) {
34+ func (s service ) RunTranslate (ctx context.Context , params TranslateParams , files []string , updates chan any ) ([]TranslateOutput , error ) {
3435 var res []TranslateOutput
3536
3637 for fileID , file := range files {
3738 rlog .Debugf ("Running translate for file %s" , file )
38- contents , err := getContent (p .InputDirectory , file )
39+ contents , err := getContent (params .InputDirectory , file )
3940 if err != nil {
4041 return nil , err
4142 }
42- fileType , found := api .TypeByExt [filepath .Ext (file )]
43+ var fileType api.Type
44+ var found bool
45+ if params .OverrideFileType != "" {
46+ fileType , found = smfile .ParseType (api .FirstType , api .LastType , params .OverrideFileType )
47+ if ! found {
48+ rlog .Debugf ("unknown override file type: %s" , params .OverrideFileType )
49+ }
50+ }
4351 if ! found {
44- rlog .Debugf ("unknown file type: %s" , file )
52+ var found bool
53+ fileType , found = api .TypeByExt [filepath .Ext (file )]
54+ if ! found {
55+ rlog .Debugf ("unknown file type for file: %s" , file )
56+ }
4557 }
4658 request := api.UploadFileRequest {
4759 File : contents ,
48- LocalesToAuthorize : []string {p .SourceLocale },
60+ LocalesToAuthorize : []string {params .SourceLocale },
4961 FileType : fileType ,
50- Directives : p .Directives ,
62+ Directives : params .Directives ,
5163 }
5264 rlog .Debugf ("start upload" )
53- uploadFileResponse , err := s .uploader .UploadFile (p .AccountUID , filepath .Base (file ), request )
65+ uploadFileResponse , err := s .uploader .UploadFile (params .AccountUID , filepath .Base (file ), request )
5466 if err != nil {
5567 return nil , err
5668 }
@@ -59,9 +71,9 @@ func (s service) RunTranslate(ctx context.Context, p TranslateParams, files []st
5971 update := TranslateUpdates {ID : uint32 (fileID ), Upload : pointer .NewP (true )}
6072 updates <- update
6173
62- if p .SourceLocale == "" {
74+ if params .SourceLocale == "" {
6375 rlog .Debugf ("detect language" )
64- detectFileLanguageResponse , err := s .translationControl .DetectFileLanguage (p .AccountUID , uploadFileResponse .FileUID )
76+ detectFileLanguageResponse , err := s .translationControl .DetectFileLanguage (params .AccountUID , uploadFileResponse .FileUID )
6577 if err != nil {
6678 return nil , err
6779 }
@@ -72,7 +84,7 @@ func (s service) RunTranslate(ctx context.Context, p TranslateParams, files []st
7284 return nil , errors .New ("timeout exceeded for polling detect file language progress: FileUID:" + string (uploadFileResponse .FileUID ))
7385 }
7486 rlog .Debugf ("check detection progress" )
75- detectionProgressResponse , err := s .translationControl .DetectionProgress (p .AccountUID , uploadFileResponse .FileUID , detectFileLanguageResponse .LanguageDetectionUID )
87+ detectionProgressResponse , err := s .translationControl .DetectionProgress (params .AccountUID , uploadFileResponse .FileUID , detectFileLanguageResponse .LanguageDetectionUID )
7688 if err != nil {
7789 return nil , err
7890 }
@@ -92,17 +104,17 @@ func (s service) RunTranslate(ctx context.Context, p TranslateParams, files []st
92104 break
93105 }
94106 if len (detectionProgressResponse .DetectedSourceLanguages ) > 0 {
95- p .SourceLocale = detectionProgressResponse .DetectedSourceLanguages [0 ].LanguageID
107+ params .SourceLocale = detectionProgressResponse .DetectedSourceLanguages [0 ].LanguageID
96108 }
97109 }
98110 }
99111
100- params := api.StartParams {
101- SourceLocaleIO : p .SourceLocale ,
102- TargetLocaleIDs : p .TargetLocales ,
112+ startParams := api.StartParams {
113+ SourceLocaleID : params .SourceLocale ,
114+ TargetLocaleIDs : params .TargetLocales ,
103115 }
104116 rlog .Debugf ("start translation" )
105- translatorStartResponse , err := s .fileTranslator .Start (p .AccountUID , uploadFileResponse .FileUID , params )
117+ translatorStartResponse , err := s .fileTranslator .Start (params .AccountUID , uploadFileResponse .FileUID , startParams )
106118 if err != nil {
107119 return nil , err
108120 }
@@ -131,7 +143,7 @@ func (s service) RunTranslate(ctx context.Context, p TranslateParams, files []st
131143 return nil , errors .New ("timeout exceeded for polling file translation progress FileUID:" + string (uploadFileResponse .FileUID ))
132144 }
133145 rlog .Debugf ("check translation progress" )
134- progressResponse , err := s .fileTranslator .Progress (p .AccountUID , uploadFileResponse .FileUID , translatorStartResponse .MtUID )
146+ progressResponse , err := s .fileTranslator .Progress (params .AccountUID , uploadFileResponse .FileUID , translatorStartResponse .MtUID )
135147 if err != nil {
136148 return nil , err
137149 }
@@ -172,21 +184,21 @@ func (s service) RunTranslate(ctx context.Context, p TranslateParams, files []st
172184
173185 for _ , localeProcessStatus := range progressResponse .LocaleProcessStatuses {
174186 rlog .Debugf ("download start" )
175- reader , err := s .downloader .File (p .AccountUID , uploadFileResponse .FileUID , translatorStartResponse .MtUID , localeProcessStatus .LocaleID )
187+ reader , err := s .downloader .File (params .AccountUID , uploadFileResponse .FileUID , translatorStartResponse .MtUID , localeProcessStatus .LocaleID )
176188 if err != nil {
177189 return nil , err
178190 }
179191 rlog .Debugf ("download finished" )
180192 ext := filepath .Ext (file )
181193 filenameLocale := strings .TrimSuffix (file , ext ) + "_" + localeProcessStatus .LocaleID + ext
182- outputDirectory , err := filepath .Abs (p .OutputDirectory )
194+ outputDirectory , err := filepath .Abs (params .OutputDirectory )
183195 if err != nil {
184196 return nil , clierror.UIError {
185197 Err : err ,
186198 Operation : "get absolute output directory" ,
187199 Description : "unable to get absolute path for output directory" ,
188200 Fields : map [string ]string {
189- "outputDirectory" : p .OutputDirectory ,
201+ "outputDirectory" : params .OutputDirectory ,
190202 },
191203 }
192204 }
0 commit comments