String actionName; if (args.length >= 3 && !ACTIONS.containsKey(args[1])) { optionsBuilder.setApiKey(args[0]); actionName = args[2]; optionsBuilder.setTargetLanguage(args[1]); args = Arrays.copyOfRange(args, 3, args.length); } else if (args.length >= 2 && !ACTIONS.containsKey(args[0])) { optionsBuilder.setTargetLanguage(args[0]); actionName = args[1]; args = Arrays.copyOfRange(args, 2, args.length); return; Translate translate = optionsBuilder.build().getService(); action.run(translate, arg);
TranslateOptions translateOptions = TranslateOptions.newBuilder() .setCredentials(GoogleCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retryParams()) .setTransportOptions(transportOptions) .build(); return new RemoteTranslateHelper(translateOptions); } catch (IOException ex) {
TranslateOptions translateOptions = TranslateOptions.newBuilder() .setCredentials(GoogleCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retryParams()) .setTransportOptions(transportOptions) .build(); return new RemoteTranslateHelper(translateOptions); } catch (IOException ex) {
@Override protected Void doInBackground(Void... params) { TranslateOptions options = TranslateOptions.newBuilder() .setApiKey(API_KEY) .build(); Translate translate = options.getService(); final Translation translation = translate.translate("Hello World", Translate.TranslateOption.targetLanguage("de")); textViewHandler.post(new Runnable() { @Override public void run() { if (textView != null) { textView.setText(translation.getTranslatedText()); } } }); return null; } }.execute();
/** * Creates a {@code RemoteTranslateHelper} object for the given API key. * * @param apiKey API key used to issue requests to Google Translation. */ @Deprecated public static RemoteTranslateHelper create(String apiKey) { HttpTransportOptions transportOptions = TranslateOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); TranslateOptions translateOptions = TranslateOptions.newBuilder() .setApiKey(apiKey) .setRetrySettings(retryParams()) .setTransportOptions(transportOptions) .build(); return new RemoteTranslateHelper(translateOptions); }
/** * Creates a {@code RemoteTranslateHelper} object using default project id and authentication * credentials. */ public static RemoteTranslateHelper create() { HttpTransportOptions transportOptions = TranslateOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); TranslateOptions translateOption = TranslateOptions.newBuilder() .setRetrySettings(retryParams()) .setTransportOptions(transportOptions) .build(); return new RemoteTranslateHelper(translateOption); }
/** * Creates a {@code RemoteTranslateHelper} object for the given API key. * * @param apiKey API key used to issue requests to Google Translate. */ public static RemoteTranslateHelper create(String apiKey) { TranslateOptions translateOptions = TranslateOptions.builder() .apiKey(apiKey) .retryParams(retryParams()) .connectTimeout(60000) .readTimeout(60000) .build(); return new RemoteTranslateHelper(translateOptions); }
/** * Sets the code for the default target language. If not set, english ({@code en}) is used. * {@link Translate#translate(List, TranslateOption...)} and * {@link Translate#translate(String, TranslateOption...)} calls will use this * value unless a {@link TranslateOption#targetLanguage(String)} option is explicitly * provided. * * @return the builder */ public Builder targetLanguage(String targetLanguage) { this.targetLanguage = targetLanguage; return self(); }
/** * Returns a default {@code TranslateOptions} instance. */ public static TranslateOptions defaultInstance() { return builder().build(); }
/** * Sets project id. Setting a project id has no impact on the {@link Translate} service. * * @return the builder */ @Override public Builder projectId(String projectId) { super.projectId(projectId); return self(); }
@SuppressWarnings("unchecked") @Override public Builder toBuilder() { return new Builder(this); }
/** Returns a default {@code TranslateOptions} instance. */ public static TranslateOptions getDefaultInstance() { return newBuilder().build(); }
/** * Creates a {@code RemoteStorageHelper} object. */ public static RemoteTranslateHelper create() { TranslateOptions translateOption = TranslateOptions.builder() .retryParams(retryParams()) .connectTimeout(60000) .readTimeout(60000) .build(); return new RemoteTranslateHelper(translateOption); }
/** * Returns a builder for {@code TranslateOptions} objects. */ public static Builder builder() { return new Builder(); } }
/** * Sets the service authentication credentials. Setting credentials has no impact on the * {@link Translate} service. * * @return the builder */ public Builder authCredentials(AuthCredentials authCredentials) { super.authCredentials(authCredentials); return self(); }
/** * Sets the project ID. Setting a project ID has no impact on the {@link Translate} service. * * @return the builder */ @Override public Builder setProjectId(String projectId) { super.setProjectId(projectId); return self(); }
/** Returns a builder for {@code TranslateOptions} objects. */ public static Builder newBuilder() { return new Builder(); } }
@SuppressWarnings("unchecked") @Override public Builder toBuilder() { return new Builder(this); }
/** * Sets the code for the default target language. If not set, English ({@code en}) is used. * Calls to {@link Translate#translate(List, TranslateOption...)} and {@link * Translate#translate(String, TranslateOption...)} will use this value unless an option from * {@link TranslateOption#targetLanguage(String)} is explicitly provided. * * @return the builder */ public Builder setTargetLanguage(String targetLanguage) { this.targetLanguage = targetLanguage; return self(); }