1Vue.component('external-service-translation', { 2 template: '#external-service-translation', 3 props: { 4 pageData: { 5 type: Object, 6 default: () => { 7 }, 8 }, 9 translationData: Object, 10 renderContent: Boolean, 11 onlySpaces: false 12 }, 13 data() { 14 return { 15 formData: { 16 domain: 'General', 17 }, 18 translationOptions: [], 19 domainOptions: [ 20 { 21 id: 'General', 22 name: translation.general, 23 }, 24 { 25 id: 'Legal', 26 name: translation.summary_law, 27 }, 28 ], 29 translatedText: '', 30 translatedFileData: '', 31 processingTranslation: false, 32 isReversed: false, 33 error: false, 34 legalTextFileFormats: ['txt', 'doc', 'docx', 'odt'], 35 fileUploadCheck: null, 36 }; 37 }, 38 computed: { 39 showText() { 40 return this.pageData.inputState === 'text'; 41 }, 42 showUpload() { 43 return this.pageData.inputState === 'upload'; 44 }, 45 fileName() { 46 return this.pageData.file ? this.pageData.file.name : ''; 47 }, 48 translateFrom() { 49 return { 50 name: this.isReversed 51 ? this.translationData.nameTo 52 : this.translationData.nameFrom, 53 code: this.isReversed 54 ? this.translationData.langCodeTo 55 : this.translationData.langCodeFrom, 56 }; 57 }, 58 translateTo() { 59 return { 60 name: this.isReversed 61 ? this.translationData.nameFrom 62 : this.translationData.nameTo, 63 code: this.isReversed 64 ? this.translationData.langCodeFrom 65 : this.translationData.langCodeTo, 66 }; 67 }, 68 translatedFilename() { 69 return `[${this.translateTo.code.toUpperCase()}]dokumentas.txt`; 70 }, 71 disableButton() { 72 return this.fileUploadCheck !== null; 73 } 74 }, 75 methods: { 76 getCurrentDomain() { 77 return this.translationOptions.find( 78 option => option.SourceLanguage.Code === this.translateFrom.code 79 && option.TargetLanguage.Code === this.translateTo.code 80 && option.Domain === this.formData.domain 81 ); 82 }, 83 onTranslate() { 84 this.$validator.validateAll() 85 .then(isValid => { 86 if (!isValid) { 87 this.onlySpaces = true; 88 return; 89 } 90 this.onlySpaces = false; 91 const isFileInput = this.pageData.inputState !== 'text'; 92 const domain = this.getCurrentDomain(); 93 let endpoint = ''; 94 let formData = new FormData() 95 96 if (isFileInput) { 97 endpoint = `${ajaxTranslatorApi}translate/file`; 98 formData.append('file', this.pageData.file); 99 } else { 100 endpoint = `${ajaxTranslatorApi}translate/text`; 101 formData.append('text', this.pageData.text); 102 } 103 104 formData.append('translationId', domain.ID); 105 106 this.processingTranslation = true; 107 108 jQuery.ajax({ 109 url: endpoint, 110 type: 'POST', 111 data: formData, 112 contentType: false, 113 processData: false, 114 success: (data) => { 115 if (isFileInput) { 116 this.translatedFileData = data; 117 } else { 118 this.translatedText = data.data; 119 } 120 this.error = false; 121 }, 122 error: () => { 123 this.error = true; 124 }, 125 complete: () => { 126 this.processingTranslation = false; 127 } 128 }); 129 130 }) 131 }, 132 onFileDownload() { 133 downloadFileFromBlob(this.translatedFileData, this.translatedFilename, 'text/plain'); 134 }, 135 onFileUpload(e) { 136 if (e.target.files.length) { 137 this.error = false; 138 this.pageData.file = e.target.files[0]; 139 let fileSplit = this.pageData.file.name.split('.'); 140 141 if (!this.legalTextFileFormats.includes(fileSplit[fileSplit.length - 1])) { 142 this.fileUploadCheck = translation.not_valid_mp3_wav; 143 }
144 switch (fileSplit[fileSplit.length - 1]) { 145 case 'txt': 146 if (this.pageData.file.size / 1024 >= 100) { 147 this.fileUploadCheck = translation.not_valid_txt; 148 } 149 break; 150 case 'docx': 151 if (this.pageData.file.size / 1024 > 20) { 152 this.fileUploadCheck = translation.not_valid_docx; 153 } 154 break; 155 case 'doc': 156 if (this.pageData.file.size / 1024 > 70) { 157 this.fileUploadCheck = translation.not_valid_doc; 158 } 159 break; 160 case 'odt': 161 if (this.pageData.file.size / 1024 > 6) { 162 this.fileUploadCheck = translation.not_valid_odt; 163 } 164 break; 165 } 166 } 167 }, 168 removeUploadedFile() { 169 this.pageData.file = null; 170 this.translatedFileData = null; 171 this.error = false; 172 this.fileUploadCheck = null; 173 }, 174 onBackClick() { 175 this.$emit('on-back-click'); 176 }, 177 resetOutputData() { 178 this.translatedText = ''; 179 this.translatedFileData = ''; 180 }, 181 fetchOptions() { 182 jQuery.ajax({ 183 url: `${ajaxTranslatorApi}translate/options?uiLanguage=lt`, 184 type: 'GET', 185 cache: false, 186 dataType: 'json', 187 success: ({data}) => { 188 this.translationOptions = data; 189 }, 190 }); 191 }, 192 onReverseClick() { 193 this.isReversed = !this.isReversed; 194 }, 195 onOpenServiceInfoModal(key, from, to) { 196 jQuery(`#service-about-modal_${key}_${from}_${to}`).modal('show'); 197 }, 198 }, 199 watch: { 200 renderContent() { 201 if (!this.renderContent) { 202 return; 203 } 204 205 this.resetOutputData(); 206 207 if (!this.translationOptions.length) { 208 this.fetchOptions(); 209 } 210 211 this.isReversed = false; 212 }, 213 pageData: { 214 deep: true, 215 handler: function () { 216 if (this.pageData.inputState === 'text' && this.pageData.text.length === 0) { 217 this.translatedText = ''; 218 } 219 }, 220 }, 221 }, 222});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.