Search code examples
csvgoogle-translateglossary

Add Glossary to Google translte V3 API by python


I am trying to add a glossary by CSV. I put the CSV on my google storage. I got this Error:

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

my CSV is super simple. I made sure I save in utf-8. I also added # -*- coding: utf-8 -*- on top of my code.

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

The code is copied from the document.


Solution

  • I also encounter your error when using the CSV you provided. This is because the CSV file used does not have a header.

    enter image description here

    To fix this just add a header on your CSV file. Make sure you match the headers with your language code defined in your code.

    test_glossary_1.csv:

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

    Create a glossary using the CSV with headers: enter image description here

    Check glossary if created: enter image description here