Skip to content

Commit c26189d

Browse files
jrjrguoJiarui Guo
andauthored
Azure-AI-Translation-Text 2.0.0-beta.1 (#47412)
* 10-01 api codegen * remove breaksentence & dictionary codes * update service methods in client * update tests * Update samples * Update test resources & add LLM test * docs, version & llm sample * update version_client * update test resources & recordings * update link * fix javadoc checks * fix typos * mark service methods * customization to remove V3_0 * avoid 'body' in params and classes * consistent fromScript/toScript naming * simplify convenience methods * fix return type per audit * clean up customization code * config to hide internal types * clean up TextTranslationClientBuilder * update docs * llm cspell fix --------- Co-authored-by: Jiarui Guo <[email protected]>
1 parent 77c7526 commit c26189d

File tree

70 files changed

+2532
-5592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2532
-5592
lines changed

eng/versioning/version_client.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ com.azure:azure-ai-personalizer;1.0.0-beta.1;1.0.0-beta.2
5555
com.azure:azure-ai-projects;1.0.0-beta.3;1.0.0-beta.4
5656
com.azure:azure-ai-textanalytics;5.5.11;5.6.0-beta.1
5757
com.azure:azure-ai-textanalytics-perf;1.0.0-beta.1;1.0.0-beta.1
58-
com.azure:azure-ai-translation-text;1.1.7;1.2.0-beta.1
58+
com.azure:azure-ai-translation-text;1.1.7;2.0.0-beta.1
5959
com.azure:azure-ai-translation-document;1.0.6;1.1.0-beta.1
6060
com.azure:azure-ai-vision-face;1.0.0-beta.2;1.0.0-beta.3
6161
com.azure:azure-ai-voicelive;1.0.0-beta.3;1.0.0-beta.4

sdk/translation/azure-ai-translation-text/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
# Release History
22

3-
## 1.2.0-beta.1 (Unreleased)
3+
## 2.0.0-beta.1 (Unreleased)
44

55
### Features Added
66

7+
- Added support for the latest Azure AI Translator API, including translations using LLM models, adaptive custom translation, tone variant translations, and gender-specific translations.
8+
- Added `TranslationTarget` class for configuring translation options.
9+
710
### Breaking Changes
811

12+
- Added `Models` property to `GetSupportedLanguagesResult` to include the list of LLM models available for translations.
13+
- Changed the name of `TargetLanguage` property to `Language` in `TranslationText`.
14+
- Changed the name of `Confidence` property to `Score` in `DetectedLanguage`.
15+
- Removed `SourceText` and `Transliteration` properties in translation responses.
16+
- Dictionary, sentence boundaries and text alignments features have been deprecated and relevant classes and properties have been removed.
17+
918
### Bugs Fixed
1019

1120
### Other Changes

sdk/translation/azure-ai-translation-text/README.md

Lines changed: 23 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# Azure Text Translation client library for Java
22

3-
Text translation is a cloud-based REST API feature of the Translator service that uses neural machine translation technology to enable quick and accurate source-to-target text translation in real time across all supported languages.
3+
Azure text translation is a cloud-based REST API provided by the Azure Translator service. It utilizes neural machine translation technology to deliver precise, contextually relevant, and semantically accurate real-time text translations across all supported languages.
44

55
Use the Text Translation client library for Java to:
66

7-
* Return a list of languages supported by Translate, Transliterate, and Dictionary operations.
7+
- Retrieve the list of languages supported for translation and transliteration operations, as well as LLM models available for translations.
88

9-
* Render single source-language text to multiple target-language texts with a single request.
9+
- Perform deterministic text translation from a specified source language to a target language, with configurable parameters to ensure precision and maintain contextual integrity.
1010

11-
* Convert text of a source language in letters of a different script.
11+
- Execute transliteration by converting text from the original script to an alternative script representation.
1212

13-
* Return equivalent words for the source term in the target language.
14-
15-
* Return grammatical structure and context examples for the source term and target term pair.
13+
- Use LLM models to produce translation output variants that are tone-specific and gender-aware.
1614

1715
## Documentation
1816

@@ -36,7 +34,7 @@ Various documentation is available to help you get started
3634
<dependency>
3735
<groupId>com.azure</groupId>
3836
<artifactId>azure-ai-translation-text</artifactId>
39-
<version>1.2.0-beta.1</version>
37+
<version>2.0.0-beta.1</version>
4038
</dependency>
4139
```
4240
[//]: # ({x-version-update-end})
@@ -100,7 +98,7 @@ GetSupportedLanguagesResult languages = client.getSupportedLanguages();
10098

10199
System.out.println("Number of supported languages for translate operation: " + languages.getTranslation().size() + ".");
102100
System.out.println("Number of supported languages for transliterate operation: " + languages.getTransliteration().size() + ".");
103-
System.out.println("Number of supported languages for dictionary operations: " + languages.getDictionary().size() + ".");
101+
System.out.println("Number of supported models for translate operation: " + languages.getModels().size() + ".");
104102

105103
System.out.println("Translation Languages:");
106104
for (Map.Entry<String, TranslationLanguage> translationLanguage : languages.getTranslation().entrySet()) {
@@ -112,9 +110,9 @@ for (Map.Entry<String, TransliterationLanguage> transliterationLanguage : langua
112110
System.out.println(transliterationLanguage.getKey() + " -- name: " + transliterationLanguage.getValue().getName() + ", supported script count: " + transliterationLanguage.getValue().getScripts().size());
113111
}
114112

115-
System.out.println("Dictionary Languages:");
116-
for (Map.Entry<String, SourceDictionaryLanguage> dictionaryLanguage : languages.getDictionary().entrySet()) {
117-
System.out.println(dictionaryLanguage.getKey() + " -- name: " + dictionaryLanguage.getValue().getName() + ", supported target languages count: " + dictionaryLanguage.getValue().getTranslations().size());
113+
System.out.println("Available models:");
114+
for (String model : languages.getModels()) {
115+
System.out.println(model);
118116
}
119117
```
120118

@@ -125,14 +123,15 @@ Please refer to the service documentation for a conceptual discussion of [langua
125123
Renders single source-language text to multiple target-language texts with a single request.
126124

127125
```java getTextTranslationMultiple
128-
TranslateOptions translateOptions = new TranslateOptions()
129-
.setSourceLanguage("en")
130-
.addTargetLanguage("es");
126+
TranslateInputItem input = new TranslateInputItem(
127+
"This is a test.",
128+
Arrays.asList(new TranslationTarget("es"), new TranslationTarget("fr")));
129+
input.setLanguage("en");
131130

132-
TranslatedTextItem translation = client.translate("This is a test.", translateOptions);
131+
TranslatedTextItem translation = client.translate(Arrays.asList(input)).get(0);
133132

134133
for (TranslationText textTranslation : translation.getTranslations()) {
135-
System.out.println("Text was translated to: '" + textTranslation.getTargetLanguage() + "' and the result is: '" + textTranslation.getText() + "'.");
134+
System.out.println("Text was translated to: '" + textTranslation.getLanguage() + "' and the result is: '" + textTranslation.getText() + "'.");
136135
}
137136
```
138137

@@ -155,58 +154,6 @@ System.out.println("Input text was transliterated to '" + transliteration.getScr
155154

156155
Please refer to the service documentation for a conceptual discussion of [transliterate][transliterate_doc].
157156

158-
### Break Sentence
159-
160-
Identifies the positioning of sentence boundaries in a piece of text.
161-
162-
```java getTextTranslationSentenceBoundaries
163-
String sourceLanguage = "zh-Hans";
164-
String sourceScript = "Latn";
165-
String content = "zhè shì gè cè shì。";
166-
167-
BreakSentenceItem breakSentence = client.findSentenceBoundaries(content, sourceLanguage, sourceScript);
168-
169-
System.out.println("The detected sentence boundaries: " + breakSentence.getSentencesLengths());
170-
```
171-
172-
Please refer to the service documentation for a conceptual discussion of [break sentence][breaksentence_doc].
173-
174-
### Dictionary Lookup
175-
176-
Returns equivalent words for the source term in the target language.
177-
178-
```java getTextTranslationDictionaryLookup
179-
String sourceLanguage = "en";
180-
String targetLanguage = "es";
181-
String content = "fly";
182-
183-
DictionaryLookupItem dictionaryEntry = client.lookupDictionaryEntries(sourceLanguage, targetLanguage, content);
184-
185-
System.out.println("For the given input " + dictionaryEntry.getTranslations().size() + " entries were found in the dictionary.");
186-
System.out.println("First entry: '" + dictionaryEntry.getTranslations().get(0).getDisplayTarget() + "', confidence: " + dictionaryEntry.getTranslations().get(0).getConfidence());
187-
```
188-
189-
Please refer to the service documentation for a conceptual discussion of [dictionary lookup][dictionarylookup_doc].
190-
191-
### Dictionary Examples
192-
193-
Returns grammatical structure and context examples for the source term and target term pair.
194-
195-
```java getTextTranslationDictionaryExamples
196-
String sourceLanguage = "en";
197-
String targetLanguage = "es";
198-
List<DictionaryExampleTextItem> content = new ArrayList<>();
199-
content.add(new DictionaryExampleTextItem("fly", "volar"));
200-
201-
List<DictionaryExampleItem> dictionaryEntries = client.lookupDictionaryExamples(sourceLanguage, targetLanguage, content);
202-
203-
for (DictionaryExampleItem dictionaryEntry : dictionaryEntries) {
204-
System.out.println("For the given input " + dictionaryEntry.getExamples().size() + " entries were found in the dictionary.");
205-
System.out.println("Example: '" + dictionaryEntry.getExamples().get(0).getTargetPrefix() + dictionaryEntry.getExamples().get(0).getTargetTerm() + dictionaryEntry.getExamples().get(0).getTargetSuffix());
206-
}
207-
```
208-
209-
Please refer to the service documentation for a conceptual discussion of [dictionary examples][dictionaryexamples_doc].
210157

211158
## Troubleshooting
212159

@@ -225,19 +172,14 @@ Samples are provided for each main functional area, and for each area, samples a
225172
* [Translation to multiple languages][sample_translatetargets]
226173
* [Translation of multiple sources][sample_translatesources]
227174
* [Translation and Transliteration][sample_translatetransliteration]
175+
* [Translation using LLM][sample_translatelargelanguagemodel]
228176
* [Using Custom Translation Model][sample_translatecustom]
229-
* [Translation with Custom Dictionary][sample_translatedictionary]
230177
* [Translation with NoTranslate tag][sample_translatenotranslate]
231-
* [Translation with Alignments][sample_translatealignments]
232-
* [Translation with Sentence Boundaries][sample_translatesentencelength]
233178
* [Handling translation of HTML text][sample_translatetexttypes]
234179
* [Transliteration][sample_transliterate]
235180
* [Get Languages][sample_getlanguages]
236181
* [Get Localized Languages][sample_getlanguagesaccept]
237182
* [Get Scoped Languages][sample_getlanguagesscope]
238-
* [Find Sentence Boundaries][sample_breaksentence]
239-
* [Lookup Dictionary Examples][sample_dictionaryexamples]
240-
* [Lookup Dictionary Entries][sample_dictionarylookup]
241183

242184
## Contributing
243185

@@ -250,7 +192,7 @@ For details on contributing to this repository, see the [contributing guide](htt
250192
1. Create new Pull Request
251193

252194
<!-- LINKS -->
253-
[product_documentation]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference
195+
[product_documentation]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/overview
254196
[docs]: https://azure.github.io/azure-sdk-for-java/
255197
[jdk]: https://learn.microsoft.com/java/azure/jdk/
256198
[azure_subscription]: https://azure.microsoft.com/free/
@@ -259,32 +201,24 @@ For details on contributing to this repository, see the [contributing guide](htt
259201
[azure_cli]: https://learn.microsoft.com/cli/azure
260202
[azure_portal]: https://portal.azure.com
261203

262-
[translator_auth]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#authentication
204+
[translator_auth]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/reference/authentication
263205
[translator_limits]: https://learn.microsoft.com/azure/cognitive-services/translator/request-limits
264206

265-
[languages_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-languages
266-
[translate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-translate
267-
[transliterate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-transliterate
268-
[breaksentence_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-break-sentence
269-
[dictionarylookup_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-lookup
270-
[dictionaryexamples_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-examples
207+
[languages_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/get-languages
208+
[translate_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/translate-api
209+
[transliterate_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/transliterate-api
271210

272-
[sample_breaksentence]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/BreakSentence.java
273-
[sample_dictionaryexamples]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/DictionaryExamples.java
274-
[sample_dictionarylookup]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/DictionaryLookup.java
275211
[sample_getlanguages]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/GetLanguages.java
276212
[sample_getlanguagesaccept]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/GetLanguagesAcceptLanguage.java
277213
[sample_getlanguagesscope]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/GetLanguagesScope.java
278214
[sample_translate]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/Translate.java
279-
[sample_translatealignments]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateAlignments.java
215+
[sample_translatelargelanguagemodel]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateLlm.java
280216
[sample_translatecustom]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateCustom.java
281217
[sample_translatedetection]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateDetection.java
282-
[sample_translatedictionary]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateDictionary.java
283218
[sample_translatesources]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateMultipleSources.java
284219
[sample_translatetargets]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateMultipleTargets.java
285220
[sample_translatenotranslate]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateNoTranslate.java
286221
[sample_translateprofanity]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateProfanity.java
287-
[sample_translatesentencelength]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateSentenceLength.java
288222
[sample_translatetexttypes]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateTextType.java
289223
[sample_translatetransliteration]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/TranslateWithTransliteration.java
290224
[sample_transliterate]: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-text/src/samples/java/com/azure/ai/translation/text/Transliterate.java

sdk/translation/azure-ai-translation-text/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/translation/azure-ai-translation-text",
5-
"Tag": "java/translation/azure-ai-translation-text_177e917101"
5+
"Tag": "java/translation/azure-ai-translation-text_3fac03d964"
66
}

sdk/translation/azure-ai-translation-text/customization/src/main/java/TextTranslationClientBuilderCustomization.java renamed to sdk/translation/azure-ai-translation-text/customization/src/main/java/TextTranslationCustomization.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import org.slf4j.Logger;
66

77
/**
8-
* This class contains the customization code to customize the TypeSpec generated code for Text Translation Client Builder.
8+
* This class contains the customization code to customize the TypeSpec generated code for Text Translation.
99
*/
10-
public class TextTranslationClientBuilderCustomization extends Customization {
10+
public class TextTranslationCustomization extends Customization {
1111

1212
@Override
1313
public void customize(LibraryCustomization customization, Logger logger) {
@@ -36,5 +36,29 @@ public void customize(LibraryCustomization customization, Logger logger) {
3636
}
3737
});
3838
});
39+
40+
logger.info("Customizing the TextTranslationServiceVersion enum - removing V3_0");
41+
customization.getClass("com.azure.ai.translation.text", "TextTranslationServiceVersion")
42+
.customizeAst(ast -> ast.getEnumByName("TextTranslationServiceVersion")
43+
.ifPresent(enumDeclaration -> {
44+
enumDeclaration.getEntries().stream()
45+
.filter(entry -> entry.getNameAsString().equals("V3_0"))
46+
.findFirst()
47+
.ifPresent(enumConstant -> enumConstant.remove());
48+
}
49+
)
50+
);
51+
52+
logger.info("Customizing the client classes - public protocol methods");
53+
customization.getClass("com.azure.ai.translation.text", "TextTranslationClient").customizeAst(ast ->
54+
ast.getClassByName("TextTranslationClient").ifPresent(clazz -> {
55+
clazz.getMethodsByName("translateWithResponse").forEach(method -> method.setPublic(true));
56+
clazz.getMethodsByName("transliterateWithResponse").forEach(method -> method.setPublic(true));
57+
}));
58+
customization.getClass("com.azure.ai.translation.text", "TextTranslationAsyncClient").customizeAst(ast ->
59+
ast.getClassByName("TextTranslationAsyncClient").ifPresent(clazz -> {
60+
clazz.getMethodsByName("translateWithResponse").forEach(method -> method.setPublic(true));
61+
clazz.getMethodsByName("transliterateWithResponse").forEach(method -> method.setPublic(true));
62+
}));
3963
}
4064
}

sdk/translation/azure-ai-translation-text/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.azure</groupId>
1313
<artifactId>azure-ai-translation-text</artifactId>
14-
<version>1.2.0-beta.1</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;current} -->
14+
<version>2.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;current} -->
1515

1616
<name>Microsoft Azure client library for Text Translation</name>
1717
<description>This package contains Microsoft Azure Text Translation client library.</description>

0 commit comments

Comments
 (0)