SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
НазадМетки: airflow apache airflow
Translate a string or list of strings.
For parameter definition, take a look at CloudTranslateTextOperator
Basic usage of the operator:
airflow/contrib/example_dags/example_gcp_translate.pyVIEW SOURCE
product_set_create = CloudTranslateTextOperator( task_id='translate', values=['zażółć gęślą jaźń'], target_language='en', format_='text', source_language=None, model='base', )
The result of translation is available as dictionary or array of dictionaries accessible via the usual XCom mechanisms of Airflow:
airflow/contrib/example_dags/example_gcp_translate.pyVIEW SOURCE
translation_access = BashOperator( task_id='access', bash_command="echo '{{ task_instance.xcom_pull(\"translate\")[0] }}'" ) product_set_create >> translation_access
template_fields = ('values', 'target_language', 'format_', 'source_language', 'model', 'gcp_conn_id')
See Google Cloud Translate documentation.