📜  prekladac (1)

📅  最后修改于: 2023-12-03 15:18:41.598000             🧑  作者: Mango

Prekladac

Prekladac is a command-line tool for translating text from one language to another using the Google Translate API. It is a useful tool for developers who need to translate large amounts of text automatically.

Getting Started

To use Prekladac, you will need to have a Google Translate API key. You can obtain a key by signing up for the Google Cloud Platform and enabling the Google Translate API.

Once you have an API key, you can install Prekladac using pip:

pip install prekladac

After installation, you can run Prekladac from the command line using the following syntax:

prekladac [options] input_language output_language input_file output_file
  • input_language: the language of the input text (e.g. "en" for English).
  • output_language: the language to translate the input text to (e.g. "fr" for French).
  • input_file: the file containing the input text to be translated.
  • output_file: the file to write the translated text to.

Prekladac can also be used programmatically in Python, as shown below:

from prekladac import translate_text

result = translate_text("Hello, world!", "en", "es")
print(result)
Options
  • -k, --api_key: specify the Google Translate API key to use (overrides the key specified in the environment variable GOOGLE_APPLICATION_CREDENTIALS).
  • -t, --text: translate a text string instead of a file.
  • -n, --no_formatting: disable formatting (useful for translating code snippets).
  • -c, --config: specify a configuration file containing the Google Translate API key.
Conclusion

Prekladac is a helpful tool for translating text automatically using the Google Translate API. With its simple command-line interface and easy-to-use Python API, it can save developers a lot of time when working with multilingual text.