Translation module

Translation module providing integration with sdcv.

Route

app.features.translation.route.translate(body)

Word translation via sdcv — tags:

  • features/translation

security:
  • BearerAuth: []

requestBody:

required: true content:

application/json:
schema:

type: object required:

  • word

  • sdcv_type

properties:
word:

type: string description: The word to translate example: “meet”

filters:

type: array description: A list of dictionaries for filtering items:

type: string

example: [“Mueller7GPL”, “Full English-Russian”]

sdcv_type:

type: string description: Where to run sdcv from example: “docker”

container_name:

type: string description: Container name, if sdcv is in docker example: “sdcv-test”

responses:
200:

description: Successful translation content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: array items:

type: object required: [dict, definition] properties:

dict:

type: string example: “Mueller7GPL”

definition:

type: string example: “встречать”

error:

type: string nullable: true example: null

400:

description: Validation error of incoming JSON (Pydantic) content:

application/json:
schema:

type: object properties:

validation_error:

type: object properties:

body_params:

type: array items:

type: object properties:

input:

type: string example: “”

loc:

type: array items:

type: string

example: [“word”]

msg:

type: string example: “Field required”

type:

type: string example: “missing”

409:

description: Translation error content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: object nullable: true example: null

error:

type: string example: “Word not found”

Parameters:

body (TranslateRequest)

Service

class app.features.translation.service.TranslateService

Bases: object

Service handling translation operations and history tracking.

save_history(word, user_id)

Saves a translated word to the user’s search history.

Parameters:
  • word (str) – The word to save.

  • user_id (int) – The unique ID of the user.

Returns:

True if the word was successfully saved to history, False otherwise.

Return type:

bool

translate(engine, word, filters)

Translates a specific word using the provided engine and filters.

Parameters:
  • engine (BaseSdcvEngine) – The specific engine implementation based on the sdcv deployment location.

  • word (str) – The word to look up.

  • filters (list[str]) – A list of dictionary names to filter the search results.

Returns:

The data transfer object containing the translation results.

Return type:

BaseDTO[List[TranslationData]]

Repository

class app.features.translation.repository.TranslationRepository

Bases: object

Repository for managing and saving translation history.

save_history(_word, _user_id, _time)

Adds a new translation history item.

Parameters:
  • _word (str) – The word that was requested.

  • _user_id (int) – The unique ID of the user.

  • _time (datetime) – The timestamp of the request.

Raises:

Exception – If the database record creation fails.

user_exists(user_id)

Checks if a user already exists in the system.

Parameters:
  • _user_id (int) – The unique ID of the user to check.

  • user_id (int)

Returns:

True if the user exists, False otherwise.

Return type:

bool

Requests

class app.features.translation.requests.TranslateRequest

Bases: BaseModel

Represents the request payload for a word translation.

Fields

Field

Type

Required

Default

Constraints

container_name

str

Yes

min_length=0

filters

List[str]

No

[]

sdcv_type

str

Yes

min_length=0

word

str

Yes

min_length=0

container_name: str

The name of the sdcv container, if deployed inside Docker.

Constraints:
  • min_length = 0

filters: List[str]

A list of specific dictionary names to filter the results.

sdcv_type: str

The deployment type of the sdcv application.

Constraints:
  • min_length = 0

word: str

The word to be translated.

Constraints:
  • min_length = 0

Responses

app.features.translation.responses.TranslateResponse

Type alias for the API response containing a list of translation data.

Fields

Field

Type

Required

Default

data

List[TranslationData] | None

No

None

error

str | None

No

None

class app.features.translation.responses.TranslationData

Bases: BaseModel

Represents the structured translation data returned from a dictionary lookup.

Fields

Field

Type

Required

Default

definition

str

Yes

dict

str

Yes

definition: str

The word definition.

Consts

class app.features.translation.consts.ResultCodes

Operation execution result codes.

WORD_NOT_FOUND = 'Word not found'

The requested word was not found in the dictionary.

UNEXPECTED_ERROR = 'Unexpected error'

An unhandled or unexpected error occurred during execution.

ERROR_IN_FINDING = 'Error while finding word'

An error occurred specifically during the dictionary lookup process.