Skip to content

Vidigal-code/at4j

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Translator 4 Java (AT4J)

Maven Central Static Badge Static Badge Coverage Quality Gate Status

An unofficial Java library for translating text using Azure AI Cognitive Services.

✨ Features

  • Text Translation: Translate text from one language (or detect) to another or to a list of languages.
  • Language Detection: Detect the language of a given text.
  • Profanity Handling: Options for handling profanity in translations.
  • Text Type Support: We support both plain text and HTML text translation.
  • And more.

📝 Documentation

🎉 Basic Usage

Note

Example repository Azure-Translator-Example

The following example translates a simple Hello World to Portuguese, Spanish and French.

public class ExampleTranslator {
	public static void main(String[] args) {
		// Insert your Azure key and region here
		String azureKey = "<Your Azure Subscription Key>";
		String azureRegion = "<Your Azure Subscription Region>";
		AzureApi api = new AzureApiBuilder().setKey(azureKey).region(azureRegion).build();

		// Set up translation parameters
		List<String> targetLanguages = List.of("pt", "es", "fr");
		TranslateParams params = new TranslateParams("Hello World!", targetLanguages).setSourceLanguage("en");

		// Translate the text
		Optional<TranslationResponse> translationResult = api.translate(params).join();

		// Print the translations
		translationResult.ifPresent(response -> {
			System.out.println("Translations:");
			
			// Create a single stream of translations from all results
			response.getResultList()
			.stream()
			.flatMap(result -> result.getTranslations().stream())
			.forEach(translation -> System.out.println(translation.getLanguageCode() + ": " + translation.getText()));
		});
		}
    }
Expected Output
Translations:
pt: Olá, Mundo!
es: ¡Hola mundo!
fr: Salut tout le monde!

📦 Download / Installation

The recommended way to get AT4J is to use a build manager, like Gradle or Maven.

Gradle
implementation group: 'io.github.brenoepics', name: 'at4j', version: '1.0.0'
Maven
<dependency>
    <groupId>io.github.brenoepics</groupId>
    <artifactId>at4j</artifactId>
    <version>1.0.0</version>
</dependency>
Sbt
libraryDependencies += "io.github.brenoepics" % "at4j" % "1.0.0"

🔑 Azure Translator Keys

Warning

Remember to keep your keys secure and do not share them publicly. If you believe that a key has been compromised, you must regenerate it in Azure's Panel. For more information, visit the Azure portal.

Optional Logger Dependency

Any Log4j-2-compatible logging framework can be used to provide a more sophisticated logging experience with being able to configure log format, log targets (console, file, database, etc.), log levels per class, and much more.

More info at our Docs

📋 Version Numbers

The version number has a 3-digit format: major.minor.trivial

  • major: Increased extremely rarely to mark a major release (usually a rewrite affecting very huge parts of the library).
  • minor: Any backward incompatible change to the api wrapper.
  • trivial: A backward compatible change to the api wrapper. This is usually an important bugfix (or a bunch of smaller ones) or a backwards compatible feature addition.

🔨 Deprecation Policy

A method or class that is marked as deprecated can be removed with the next minor release (but it will usually stay for several minor releases). A minor release might remove a class or method without having it deprecated, but we will do our best to deprecate it before removing it. We are unable to guarantee this though, because we might have to remove / replace something due to changes made by Azure, which we are unable to control. Usually you can expect a deprecated method or class to stay for at least 6 months before it finally gets removed, but this is not guaranteed.

🧑‍💻 Contributing

Contributions of any kind are welcome. You can start contributing to this library by creating issues, submitting pull requests or giving a star to the project.

📃 License

AT4J is distributed under the Apache license version 2.0.

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%