Translate
Protocol: JSON 1.1 (X-Amz-Target: AWSShineFrontendService_20170701.*)
Endpoint: POST http://localhost:4566/
Supported Actions
| Action | Description |
|---|---|
TranslateText |
Translate a UTF-8 text string between two languages |
TranslateDocument |
Translate a document (≤100 KB) supplied as a base64 blob |
ListLanguages |
List the language codes and names Floci recognizes |
Emulation Behavior
- No machine translation:
TranslateTextreturns the requestTextverbatim asTranslatedText, andTranslateDocumentreturns the requestDocument.Contentbytes unchanged asTranslatedDocument.Content. To exercise logic that branches on a specific translation, use the mock config below. - Language detection: a
SourceLanguageCodeofautois accepted and reported back asen(the stub's fixed "detected" language); no Comprehend call is made. - Real input validation:
Text/Document.Content/Document.ContentTypeand both language codes are required.SourceLanguageCodemust beautoor a code from the catalog returned byListLanguages;TargetLanguageCodemust be a catalog code. An unknown code returnsUnsupportedLanguagePairException. TranslateTextrejects aTextlonger than 10,000 UTF-8 bytes withTextSizeLimitExceededException, matching AWS. Any language pair is allowed (TranslateTextis any-to-any).TranslateDocumentrequires an English pivot: either the source or the target language must resolve toen, otherwise it returnsUnsupportedLanguagePairException. It also rejects aContentTypeother thantext/plain,text/html, or the Word (.docx) MIME type, aContentthat is not valid base64, and a decoded document over 100 KB, all withInvalidRequestException(TranslateDocumentdoes not modelTextSizeLimitExceededException).- Fixed catalog:
ListLanguagesreturns a curated ~35-language subset of Translate's full list, enough to drive an i18n pipeline.MaxResults/NextTokenare accepted but ignored (the whole catalog fits in one page, so noNextTokenis returned).DisplayLanguageCodeis validated against the AWS enum (de,en,es,fr,it,ja,ko,pt,zh,zh-TW) but everyLanguageNameis returned in English regardless. - Out of scope: custom terminology, parallel data, asynchronous batch translation jobs
(
StartTextTranslationJoband friends), and tagging, all needing persistent state. - Deviation:
ListLanguagesalways returnsLanguageNames in English regardless ofDisplayLanguageCode(real Translate localizes them), and theFormality/Profanity/Brevitytranslation settings are accepted but ignored.
Configuration
| Variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_TRANSLATE_ENABLED |
true |
Enable or disable the service |
AI_MOCK_CONFIG |
unset | Path to a shared mock-response config file; see "Mock Responses" below |
Mock Responses
To return a real translated string instead of the echoed input, point AI_MOCK_CONFIG at a
JSON file shared across Translate, Comprehend, Textract, and Rekognition:
{
"translate": {
"Hello world": {
"TranslateText": { "TranslatedText": "Hola mundo", "SourceLanguageCode": "en", "TargetLanguageCode": "es" }
}
}
}
The lookup key is the exact Text value sent in the request, so only TranslateText
can be mocked; TranslateDocument carries a binary payload with no stable key. The file is
re-read when its modification time changes, so it can be edited without restarting the
emulator. A missing file, an unset AI_MOCK_CONFIG, or no matching entry all fall back to
the echoed-input default. Mocking is opt-in and never breaks a call that isn't using it.
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
aws translate translate-text \
--text "Floci makes local AWS testing painless" \
--source-language-code en \
--target-language-code fr \
--endpoint-url $AWS_ENDPOINT_URL
aws translate list-languages \
--endpoint-url $AWS_ENDPOINT_URL
SDK Example (Java)
TranslateClient translate = TranslateClient.builder()
.endpointOverride(URI.create("http://localhost:4566"))
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("test", "test")))
.build();
TranslateTextResponse response = translate.translateText(req -> req
.text("Floci makes local AWS testing painless")
.sourceLanguageCode("en")
.targetLanguageCode("fr"));
System.out.println("Translated: " + response.translatedText());