通过python将词汇表添加到Google translte V3 API

问题描述

我正在尝试通过 CSV 添加词汇表。我把 CSV 放在我的谷歌存储上。我收到此错误

google.api_core.exceptions.InvalidArgument: 400 Failed to parse content of input file. Error: Not enough valid languages in CSV file. Must have terms for at least two different languages. num_valid_languages_in_csv = 0

我的 CSV 非常简单。我确保我保存在 utf-8 中。我还在代码顶部添加# -*- coding: utf-8 -*-

Liz,栗子
Tom,汤姆
Nancy,楠西

代码是从文档中复制的。

解决方法

我在使用您提供的 CSV 时也遇到了您的错误。这是因为使用的 CSV 文件没有标题。

enter image description here

要解决此问题,只需在 CSV 文件中添加标题即可。确保将标题与代码中定义的语言代码相匹配。

test_glossary_1.csv:

en,zh
Liz,栗子
Tom,汤姆
Nancy,楠西

使用带有标题的 CSV 创建词汇表: enter image description here

检查词汇表(如果已创建): enter image description here