Skip to content

Client

This section contains the reference for the implementation of translate-md's SpanglishClient.

SpanglishClient

SpanglishClient(url: str = SPANGLISH_URL) -> None

Client to interact with the Spanglish service.

Parameters:

Name Type Description Default
url str

URL where the service is exposed. Defaults to SPANGLISH_URL.

SPANGLISH_URL

translate

translate(text: str) -> str

Translate a piece of text from english to spanish.

Parameters:

Name Type Description Default
text str

string to translate.

required

Returns:

Name Type Description
str str

translated text

Examples:

>>> client.translate("hello world")
'hola mundo'

translate_batch

translate_batch(texts: list[str]) -> list[str]

Translates a batch of texts.

Instead of calling repeatedly on a loop the method translate, this method should be preferred, send a list of texts to translate and get them back in the same order.

Parameters:

Name Type Description Default
texts list[str]

Texts to translate

required

Returns:

Type Description
list[str]

list[str]: list of texts translated.

Examples:

>>> client.translate_batch(["hello", "world", "one", "two"])
["hola", "mundo", "uno", "dos"]

translate_file

translate_file(
    filename: Path, new_filename: Optional[Path] = None
) -> None

Takes the filename of a markdown file in disk and processes to obtain the paragraphs which contain text, sends them to translate them and replaces the new text. Finally writes the new document to disk.

Parameters:

Name Type Description Default
filename Path

Path to the markdown file.

required
new_filename Optional[Path]

Filename for the new markdown file to be generated. Defaults to None, in which case it is generated internally.

None