Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GroupDocs.Translation Cloud-Java
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add FROM storage name here
String srcStorageName = "";
// add TO storage name here
String destStorageName = "";
// add FROM folder name here
String srcPath = "";
// add TO folder name here
String destPath = "";
Call<Void> call_move = storageApi.moveFile(srcPath, destPath, srcStorageName, destStorageName, null);
Response<Void> res_move = call_move.execute();
out.print("File "+srcPath + " copied to " + destPath);
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import java.io.File;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add FROM storage name here
String srcStorageName = "";
// add TO storage name here
String destStorageName = "";
// add FROM folder name here
String srcPath = "";
// add TO folder name here
String destPath = "";
Call<Void> call_move = storageApi.moveFolder(srcPath, destPath, srcStorageName, destStorageName);
Response<Void> res_move = call_move.execute();
out.print("Folder" + srcPath + " copied to " + destPath);
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import com.GroupDocs.storage.model.ObjectExist;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add folder path here
String path = "";
Call<Void> call_exist = storageApi.createFolder(path, storageName);
Response<ObjectExist> res_exist = call_exist.execute();
out.print("Folder " + path + " created.");
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add file path here
String path = "";
Call<Void> call_response = storageApi.deleteFile(path, storageName, null);
Response<Void> res = call_response.execute();
out.print("File " + path + "deleted.");
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add folder path here
String path = "";
Call<Void> call_response = storageApi.deleteFolder(path, storageName, true);
Response<Void> res = call_response.execute();
out.print("Folder " + path + "deleted.");
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
import java.io.*;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add file path here
String path = "";
Call<ResponseBody> call_download = storageApi.downloadFile(path, storageName, null);
Response<ResponseBody> res = call_download.execute();
ResponseBody res_download = res.body();
InputStream inputStream = res_download.byteStream();
}
import com.GroupDocs.storage.model.FileVersions;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add file/folder path here
String path = "";
Call<FileVersions> call = storageApi.getFileVersions(path, storageName);
Response<FileVersions> res = call.execute();
FileVersions result = res.body();
out.print("File version: " + result.toString());
}
import com.GroupDocs.storage.model.FilesList;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add file/folder path here
String filePath = "";
Call<FilesList> call = storageApi.getFilesList(filePath, storageName);
Response<FilesList> res = call.execute();
FilesList response = res.body();
out.print("Files list: " + response.toString());
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add FROM storage name here
String srcStorageName = "";
// add TO storage name here
String destStorageName = "";
// add FROM folder name here
String srcPath = "";
// add TO folder name here
String destPath = "";
Call<Void> call_move = storageApi.moveFile(srcPath, destPath, srcStorageName, destStorageName, null);
Response<Void> res_move = call_move.execute();
out.print("File "+srcPath + " moved to " + destPath);
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import java.io.File;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add FROM storage name here
String srcStorageName = "";
// add TO storage name here
String destStorageName = "";
// add FROM folder name here
String srcPath = "";
// add TO folder name here
String destPath = "";
Call<Void> call_move = storageApi.moveFolder(srcPath, destPath, srcStorageName, destStorageName);
Response<Void> res_move = call_move.execute();
out.print("Folder" + srcPath + " moved to " + destPath);
}
import com.GroupDocs.storage.model.StorageExist;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add file/folder path here
String filePath = "";
Call<ObjectExist> call = storageApi.objectExists(existFile, storageName, null);
Response<ObjectExist> res_exist = call.execute();
ObjectExist res_exist_body = res_exist.body();
out.print("Object exists: " + res_exist_body.isExists())
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import com.GroupDocs.storage.model.DiscUsage;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
Call<DiscUsage> call = storageApi.getDiscUsage(storageName);
Response<DiscUsage> res = call.execute();
DiscUsage result = res.body();
out.println("Used size: " + res.getUsedSize());
out.println("Total disk size: " + res.getTotalSize());
}
import com.GroupDocs.storage.model.StorageExist;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
string storageName = "";
Call<StorageExist> call = storageApi.storageExists(storageName);
Response<StorageExist> res = call.execute();
StorageExist result = res.body();
out.print("Storage exists: " + result.isExists())
}
import com.GroupDocs.translate.api.*;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}
// add file name to translate here
String name = "";
// add file name to translate here
String folder = "";
// add language pair here, see https://wiki.groupdocs.cloud/translationcloud/developer-guide/supported-languages/
String pair = "";
// add format of file to translate, see https://wiki.groupdocs.cloud/translationcloud/developer-guide/supported-formats/
String format = "";
// add storage name, add "First Storage" if default storage is used
String storage = "";
// add name of translated file
String saveFile = "";
// add path where file is kept, leave as empty string if no specific folder
String savePath = "";
// add option to translate masters slides
Boolean masters = false;
// add numbers of pages to translate
ArrayList<Integer> elements = null;
// add format of file to convert
String outformat = "";
FileInfo fileInfo = new FileInfo(name, folder, storage, format, savePath, saveFile, pair, masters, elements, outformat);
TranslationDocumentRequest translationDocumentRequest = new TranslationDocumentRequest(fileInfo.toString());
TranslateDocumentResponse translateDocumentResponse = TranslationApi.TranslateDocument(translationDocumentRequest);
out.print(translateDocumentResponse.message);
}
import com.GroupDocs.translate.api.*;
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
// add language pair here, see https://wiki.groupdocs.cloud/translationcloud/developer-guide/supported-languages/
pair = ""
// add text to translate here
text = ""
TextInfo textInfo = new TextInfo(pair, text);
String userRequest = textInfoList.toString();
TranslationTextRequest translationTextRequest = new TranslationTextRequest(userRequest);
TranslationTextResponse translateTextResponse = TranslationApi.TranslateText(translationTextRequest);
out.print(translateTextResponse.translation);
}
import com.GroupDocs.translate.Configuration;
import static java.lang.System.out;
import java.io.File;
import com.GroupDocs.storage.model.FilesUploadResult;
import retrofit2.Call;
import retrofit2.Response;
public static void main(String[] args) throws Exception {
// add your client id here
Configuration.setClient_id("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
// add your client secret here
Configuration.setClient_secret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StorageApi storageApi = new ApiClient().createService(StorageApi.class);
// add storage name here
String storageName = "";
// add path to file to upload on storage
String path = "";
// add path to file to upload here
String localPath = "";
File f = new File(localPath);
RequestBody requestBody = RequestBody.create( MediaType.parse("multipart/form-data"), f);
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", f.getName(), requestBody);
Call<FilesUploadResult> call = storageApi.uploadFile(path, fileToUpload, storageName);
Response<FilesUploadResult> res = call.execute();
out.print("File " + f.getName() + " uploaded.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment