ropensci-review-tools / babeldown

Helpers for Automatic Translation of Markdown-based Content
https://docs.ropensci.org/babeldown/
Other
20 stars 2 forks source link

Trying documentation examples, I get these kinds of errors #39

Closed yabellini closed 1 year ago

yabellini commented 1 year ago

Error in read_xml.character(temp_file) : Input is not proper UTF-8, indicate encoding ! Bytes: 0xF3 0x6E 0x20 0x67 [9]

Error in read_xml.character(temp_file) : Input is not proper UTF-8, indicate encoding ! Bytes: 0xED 0x20 0x71 0x75 [9]

maelle commented 1 year ago

from the README?

yabellini commented 1 year ago

From the docs page of the package.

yabellini commented 1 year ago
babeldown::deepl_translate_markdown_string(
  "[So _incredibly_ **wonderful**](https://ropensci.org)!",
  source_lang = "EN",
  target_lang = "ES"
)
#> Error in read_xml.character(temp_file): Input is not proper UTF-8, indicate encoding !
#> Bytes: 0xED 0x20 0x71 0x75 [9]

Created on 2023-06-08 with reprex v2.0.2

yabellini commented 1 year ago
english_lines <- c(
  "## A cool section", "",
  "This is the first paragraph. `system.file()` is cool, right?", "",
  "Another paragraph. I really enjoy developing R packages.", "",
  "Do you enjoy debugging?"
)
file <- withr::local_tempfile()
writeLines(english_lines, file)

out_path <- withr::local_tempfile()

babeldown::deepl_translate(
  path = file,
  out_path = out_path,
  source_lang = "EN",
  target_lang = "ES",
  formality = "less"
)
#> Error in read_xml.character(temp_file): Input is not proper UTF-8, indicate encoding !
#> Bytes: 0xF3 0x6E 0x20 0x67 [9]

readLines(out_path)
#> Warning in file(con, "r"): no fue posible abrir el archivo
#> 'C:\Users\usuario\AppData\Local\Temp\RtmpieMokT\file2ca82d443886': No such file
#> or directory
#> Error in file(con, "r"): no se puede abrir la conexión

Created on 2023-06-08 with reprex v2.0.2

yabellini commented 1 year ago
english_lines <- c(
  "---",
  "title: Nice document",
  "description: An example for sure",
  "---",
  "## A cool section", "",
  "This is the first paragraph. `system.file()` is cool, right?", "",
  "Another paragraph. I really enjoy developing R packages.", "",
  "Do you enjoy debugging?"
)
file <- withr::local_tempfile()
writeLines(english_lines, file)

out_path <- withr::local_tempfile()

babeldown::deepl_translate(
  path = file,
  out_path = out_path,
  source_lang = "EN",
  target_lang = "ES",
  formality = "less"
)
#> Error in read_xml.character(temp_file): Input is not proper UTF-8, indicate encoding !
#> Bytes: 0xF3 0x6E 0x20 0x67 [9]

readLines(out_path)
#> Warning in file(con, "r"): no fue posible abrir el archivo
#> 'C:\Users\usuario\AppData\Local\Temp\Rtmp4q9q46\file51cc690737b0': No such file
#> or directory
#> Error in file(con, "r"): no se puede abrir la conexión

Created on 2023-06-08 with reprex v2.0.2

maelle commented 1 year ago

@yabellini thank you! Could you please add the result of session_info()? I'm wondering whether it's a locale problem.

yabellini commented 1 year ago

R version 4.1.3 (2022-03-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045), RStudio 2023.3.1.446

Locale: LC_COLLATE=Spanish_Argentina.1252 LC_CTYPE=Spanish_Argentina.1252
LC_MONETARY=Spanish_Argentina.1252 LC_NUMERIC=C
LC_TIME=Spanish_Argentina.1252

Package version: askpass_1.1 babeldown_0.0.0.9000 babelquarto_0.0.0.9000 base64enc_0.1.3
bit_4.0.4 bit64_4.0.5 brio_1.1.3 bslib_0.4.0
cachem_1.0.6 callr_3.7.0 cli_3.6.1 clipr_0.8.0
commonmark_1.9.0 compiler_4.1.3 cpp11_0.4.2 crayon_1.5.1
curl_4.3.2 digest_0.6.29 ellipsis_0.3.2 evaluate_0.15
fansi_1.0.3 fastmap_1.1.0 fs_1.6.2 glue_1.6.2
graphics_4.1.3 grDevices_4.1.3 highr_0.9 hms_1.1.3
htmltools_0.5.5 httr_1.4.6 httr2_0.2.2 jquerylib_0.1.4
jsonlite_1.8.5 knitr_1.38 later_1.3.0 lifecycle_1.0.3
magrittr_2.0.3 memoise_2.0.1 methods_4.1.3 mime_0.12
openssl_2.0.5 packrat_0.9.1 pak_0.5.1 pillar_1.9.0
pkgconfig_2.0.3 prettyunits_1.1.1 processx_3.7.0 progress_1.2.2
ps_1.7.1 purrr_1.0.1 quarto_1.2 R6_2.5.1
rappdirs_0.3.3 Rcpp_1.0.9 readr_2.1.4 reprex_2.0.2
rlang_1.1.1 rmarkdown_2.13 rsconnect_0.8.29 rstudioapi_0.14
sass_0.4.6 snakecase_0.11.0 stats_4.1.3 stringi_1.7.8
stringr_1.5.0 sys_3.4.1 tibble_3.2.1 tidyselect_1.2.0
tinkr_0.2.0 tinytex_0.38 tools_4.1.3 tzdb_0.3.0
utf8_1.2.2 utils_4.1.3 vctrs_0.6.2 vroom_1.6.3
whoami_1.3.0 withr_2.5.0 xfun_0.39 xml2_1.3.3
xslt_1.4.4 yaml_2.3.5

yabellini commented 1 year ago
withr::with_locale(
  new = c(
    "LC_COLLATE" = "en_US.utf8",
    "LC_CTYPE" = "en_US.utf8",
    "LC_MONETARY" = "en_US.utf8",
    "LC_NUMERIC" = "en_US.utf8",
    "LC_TIME" = "en_US.utf8"
  ), {
    Sys.setenv("DEEPL_API_URL" = "https://api.deepl.com")
    Sys.setenv(DEEPL_API_KEY = keyring::key_get("deepl"))
    babeldown::deepl_translate_markdown_string(
      "[So _incredibly_ **wonderful**](https://ropensci.org)!",
      source_lang = "EN",
      target_lang = "ES"
    )
  }

)
#> Warning in (function (category = "LC_ALL", locale = "") : OS reports request to
#> set locale to "en_US.utf8" cannot be honored

#> Warning in (function (category = "LC_ALL", locale = "") : OS reports request to
#> set locale to "en_US.utf8" cannot be honored

#> Warning in (function (category = "LC_ALL", locale = "") : OS reports request to
#> set locale to "en_US.utf8" cannot be honored
#> Warning in (function (category = "LC_ALL", locale = "") : especificacion de
#> 'LC_NUMERIC' puede forzar R a funcionar de forma extraña
#> Warning in (function (category = "LC_ALL", locale = "") : OS reports request to
#> set locale to "en_US.utf8" cannot be honored

#> Warning in (function (category = "LC_ALL", locale = "") : OS reports request to
#> set locale to "en_US.utf8" cannot be honored
#> Error in b_wincred_i_get(target): Windows credential store error in 'get': No se ha encontrado el elemento.

Created on 2023-06-09 with reprex v2.0.2

yabellini commented 1 year ago

@maelle now it is working. @paocorrales tested on Linux and Windows and works, so I tried again in my computer and now the examples works.

I think we can close this issue, right?

maelle commented 1 year ago

Wow so cool! Easiest debugging ever, thanks both!!

Now I really wonder what was wrong the last time. :thinking: