Skip to content

Commit

Permalink
chore: fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed May 16, 2024
1 parent a359744 commit 0b8b93c
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions README.prp.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ An unofficial Java library for translating text using Azure AI Cognitive Service

## 📝 Documentation

- [VitePress Docs](https://brenoepics.github.io/at4j/)
- [AT4J Docs](https://brenoepics.github.io/at4j/)
- [JavaDoc](https://brenoepics.github.io/at4j/javadoc/)

## 🎉 Basic Usage
Expand All @@ -30,30 +30,29 @@ The following example translates a simple Hello World to Portuguese, Spanish and

```java
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());
}
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());
}
}
```

Expand Down

0 comments on commit 0b8b93c

Please sign in to comment.