Miscellaneous
An unofficial Java library for translating text using Azure AI Cognitive Services.
[!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 ->
response.getFirstResult().getTranslations().forEach(ExampleTranslator::logLanguage));
}
public static void logLanguage(Translation translation) {
System.out.println(translation.getLanguageCode() + ": " + translation.getText());
}
}
pt: OlΓ‘, Mundo!
es: Β‘Hola mundo!
fr: Salut tout le monde!
The recommended way to get AT4J is to use a build manager, like Gradle or Maven.
implementation group: 'io.github.brenoepics', name: 'at4j', version: '1.2.0'
<dependency>
<groupId>io.github.brenoepics</groupId>
<artifactId>at4j</artifactId>
<version>1.2.0</version>
</dependency>
libraryDependencies += "io.github.brenoepics" % "at4j" % "1.2.0"
Q: How do I access Azure Translator Keys for my project?
A: You can access your Azure Translator Keys through your Azure portal. Remember to keep your keys secure and refrain from sharing them publicly. If you suspect a key has been compromised, it's crucial to regenerate it promptly. For detailed instructions on generating your own keys, refer to this guide. Additionally, you can explore the Azure Free Tier for more information.
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.
AT4J is distributed under the Apache license version 2.0.