Skip to content

Commit

Permalink
Release 1.1.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics authored Feb 16, 2024
2 parents f448ea1 + 1ab2124 commit 28d91d5
Show file tree
Hide file tree
Showing 53 changed files with 54,127 additions and 429 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/codesee-arch-diagram.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.3
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
2 changes: 0 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,5 @@ jobs:
- name: Build and analyze
run: mvn -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=brenoepics_at4j -P coverage
env:
AZURE_KEY: ${{ secrets.AZURE_KEY }}
AZURE_REGION: ${{ secrets.AZURE_REGION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
89 changes: 35 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=brenoepics_at4j&metric=coverage)](https://sonarcloud.io/summary/new_code?id=brenoepics_at4j)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=brenoepics_at4j&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=brenoepics_at4j)


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

## ✨ Features
Expand All @@ -29,37 +28,36 @@ 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 -> {
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()));
});
}
}

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());
}
}
```
<details>
<summary>Expected Output</summary>

```console
Translations:
pt: Olá, Mundo!
es: ¡Hola mundo!
fr: Salut tout le monde!
Expand Down Expand Up @@ -98,38 +96,21 @@ libraryDependencies += "io.github.brenoepics" % "at4j" % "1.0.0"
```
</details>

### 🔑 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](https://portal.azure.com/).
- [How to generate my own keys?](https://brenoepics.github.io/at4j/guide/azure-subscription.html#azure-subscription)
- [Azure Free Tier](https://brenoepics.github.io/at4j/guide/azure-subscription.html#azure-free-tier)

### 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.
### Frequently Asked Questions (FAQ)

More info at our [Docs](https://brenoepics.github.io/at4j/guide/installation.html#logger-dependency)
**Q:** How do I access Azure Translator Keys for my project?

## 📋 Version Numbers
**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](https://brenoepics.github.io/at4j/guide/azure-subscription.html#azure-subscription). Additionally, you can explore the [Azure Free Tier](https://brenoepics.github.io/at4j/guide/azure-subscription.html#azure-free-tier) for more information.

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
Optional Logger Dependency
**Q:** Is there a recommended logger dependency for the project?

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.
**A:** While our project is compatible with any Log4j-2-compatible logging framework, integrating one can enhance your logging experience significantly. This allows you to configure log format, log targets (console, file, database, etc.), log levels per class, and more. For further details, please visit our [Docs](https://brenoepics.github.io/at4j/guide/installation.html#logger-dependency).

## 🤝 Thank You!
- **Microsoft Azure**: Supporting our project with a generous grant of $10,000+ in Azure credits, enabling us to utilize virtual machines, document translation and other essential cloud resources for our development needs.
- We extend our sincere thanks to all contributors for their invaluable contributions.

## 🧑‍💻 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.
Expand Down
12 changes: 8 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ export const sidebar = {
text: 'Basic',
items: [
{
text: 'Guide',
link: '/guide/introduction'
text: 'Translate Hello World',
link: '/examples/#translator'
},
{
text: 'Detect Language',
link: '/examples/#detect'
},
{
text: 'Hello World',
link: '/examples/#hello-world'
text: 'Guide',
link: '/guide/introduction'
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/error-reference/ErrorsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defineProps<{

<style scoped>
.highlight {
color: var(--vt-c-yellow-darker);
color: var(--vp-c-yellow-soft);
font-weight: bold;
}
</style>
61 changes: 57 additions & 4 deletions docs/src/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,61 @@ outline: false

# Examples {#examples}

::: warning
This section is under construction.
:::

This section contains examples of how to use AT4J in different scenarios.

## Translate Hello World {#translator}

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

## Language Detector {#detect}

```java
public class ExampleDetector {
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();

DetectLanguageParams params =
new DetectLanguageParams("Hello World!").addText("Bonjour le monde!");

// Translate the text
Optional<DetectResponse> result = api.detectLanguage(params).join();

// Print the translations
result.ifPresent(
response -> response.getDetectedLanguages().forEach(ExampleDetector::logLanguage));
}

public static void logLanguage(DetectedLanguage detectedLanguage) {
System.out.println(detectedLanguage.getLanguageCode() + ": " + detectedLanguage.getScore());
}
}
```
43 changes: 17 additions & 26 deletions docs/src/guide/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,33 @@ public class ExampleApi {
// Insert your Azure key and region here
String azureKey = "<Your Azure Subscription Key>";
String azureRegion = "<Your Azure Subscription Region>";
azureApi = new AzureApiBuilder().setKey(azureKey).region(azureRegion)
.build();
azureApi = new AzureApiBuilder().setKey(azureKey).region(azureRegion).build();

translate(args.join(" "), List.of("pt", "es", "fr"));
}
}
```

```java
private static void translate(String inputText, List<String> targetLanguages) {
TranslateParams params = new TranslateParams(inputText, targetLanguages);
Optional<TranslationResponse> request = azureApi.translate(params).join();

request.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()));
});
private static void translate(String inputText, List<String> targetLanguages) {
TranslateParams params = new TranslateParams(inputText, targetLanguages);
Optional<TranslationResponse> result = azureApi.translate(params).join();

result.ifPresent(response ->
response.getFirstResult().getTranslations().forEach(ExampleApi::log));
}

public static void log(Translation translation) {
System.out.println(translation.getLanguageCode() + ": " + translation.getText());
}
}
```

```java
private static void example() {
translate("Hello World!", List.of("pt", "es", "fr"));
}
**Input**
```console
Hello, World!
```

**Result**

```console
Translations:
pt: Olá, Mundo!
es: ¡Hola mundo!
fr: Salut tout le monde!
Expand Down
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.brenoepics</groupId>
<artifactId>at4j</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<name>Azure Translator For Java</name>
<description>
Expand Down Expand Up @@ -109,6 +109,7 @@
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -209,5 +210,19 @@
</plugins>
</build>
</profile>
<profile>
<id>publish</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit 28d91d5

Please sign in to comment.