Skip to content

Error ! HTTP 400 Bad Request. when creating a Spanish to English glossary #87

@avallecam

Description

@avallecam

Hi @maelle, have you tried doing Spanish to English translations? I'm trying to use a glossary file that works with English to Spanish, but not in the other direction. I'm following the babeldown::deepl_languages(type = "target") name for English (American). Could the space be the issue?

From deepl:

Error 400
Bad request. Please check error message and your parameters
This error occurs when a required parameter of the request is missing or one of the specified parameters is not supported, is misspelled, or the value is wrong.

Here is a reprex:

library(tidyverse)
library(babeldown)

# first time user
# 1. create a Free Api account
# 2. copy the API key and paste it as a password in:
# keyring::key_set("deepl")
Sys.setenv(DEEPL_API_KEY = keyring::key_get("deepl"))

# read and bind files -----------------------------------------------------

# rOpenSci glossary
# https://translationguide.ropensci.org/es/specific_guidelines.es.html#glosario-es
filename <- "https://raw.githubusercontent.com/ropensci-review-tools/glossary/refs/heads/master/glossary.csv"

# file contents for info
bind_glossary <- readr::read_csv(filename, show_col_types = FALSE) %>%
  dplyr::add_row(
    english = "force of infection",
    spanish = "fuerza de infección"
  )

# from english to spanish ------------------------------------------------

tmp <- file.path(tempdir(), "mixed_glossary.csv")

bind_glossary %>%
  dplyr::select("Spanish" = spanish, "English" = english) %>%
  readr::write_csv(tmp)

babeldown::deepl_upsert_glossary(
  filename = tmp,
  glossary_name = "rstats-glosario",
  target_lang = "Spanish",
  source_lang = "English"
)
#> Updating glossary rstats-glosario

babeldown::deepl_translate_markdown_string(
  markdown_string = "[So _incredibly_ **force of infection!**](https://ropensci.org)",
  source_lang = "EN",
  target_lang = "ES",
  glossary_name = "rstats-glosario"
)
#> [1] "[Así que *increíblemente* **¡fuerza de infección!**](https://ropensci.org)"


# from spanish to english ------------------------------------------------

tmp <- file.path(tempdir(), "mixed_glossary.csv")

bind_glossary %>%
  dplyr::select("Spanish" = spanish, "English (American)" = english) %>%
  readr::write_csv(tmp)

babeldown::deepl_upsert_glossary(
  filename = tmp,
  glossary_name = "rstats-glosario",
  target_lang = "English (American)",
  source_lang = "Spanish"
)
#> Creating glossary rstats-glosario
#> Error in `httr2::req_perform()`:
#> ! HTTP 400 Bad Request.

babeldown::deepl_translate_markdown_string(
  markdown_string = "[Así que *increíblemente* **¡fuerza de infección!**](https://ropensci.org)",
  source_lang = "ES",
  target_lang = "EN-US",
  glossary_name = "rstats-glosario"
)
#> Error in `deepl_translate()`:
#> ! Can't find glossary_name "rstats-glosario".
#> ℹ Check the spelling, or create it with `upsert_glossary()`.

Created on 2025-06-18 with reprex v2.1.1

edit: replaced reading sheet with adding a row

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions