From ba995b6264d6c43e1b71d49f855d656214d284f3 Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Thu, 5 Sep 2024 23:49:43 +0200 Subject: [PATCH 1/5] add translations --- inst/po/fr/LC_MESSAGES/R-safetensors.mo | Bin 0 -> 1306 bytes po/R-fr.po | 48 ++++++++++++++++++++++++ po/R-safetensors.pot | 47 +++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 inst/po/fr/LC_MESSAGES/R-safetensors.mo create mode 100644 po/R-fr.po create mode 100644 po/R-safetensors.pot diff --git a/inst/po/fr/LC_MESSAGES/R-safetensors.mo b/inst/po/fr/LC_MESSAGES/R-safetensors.mo new file mode 100644 index 0000000000000000000000000000000000000000..c20c7f584060744979ac91cf2d9d683f56d97433 GIT binary patch literal 1306 zcmb7D%Wl&^6djpM^b zegFhiPBC^J+yXoOIyeBo1{3%r_$v4dI0F9yJAM5$V?V)9!S})KGvl~7;5*oVp6q{v ztJvR|W9%CE8Q8_Y0xyBzfqn2dFjBJ%fa@J$45`^gV7kst9?pW#0|;Sku`IGQ=2j#m zc`gibEl4U$Jj>K3PE$$S0oQ%9LK>ybfUQYW7KPF-CgGNoeOU;IHh4zcTZ0+F{+GG1 zypp(+<5aULdK!&wD!o3f5g3v6D!a!sxpvQ|a+h!X39i2DctCk+EOiBO%2H#4W8S-| zBqJ569+{YDTvPmr2BEj0B+4TPE+oSJZrNK!##4EB^nFIyduyE~zqzM#wR%GPEg7pMmHmjC z-PC$d{0Bk`J#M0{M3P#n2aTZau@yK\n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: safetensors.R:122 +msgid "Unsupported framework {.val {.self$framework}}" +msgstr "" + +#: safetensors.R:163 +msgid "Unsupported dtype {.val {x}}" +msgstr "" + +#: safetensors.R:169 +msgid "Unsupported framework {.val {x}}" +msgstr "" + +#: write.R:25 +msgid "Duplicated names are not allowed in {.arg tensors}" +msgstr "" + +#: write.R:121 +msgid "Unsupported data type {.val {x}}" +msgstr "" + +#: write.R:147 +msgid "Unsupported dtype {.val {meta$dtype}}" +msgstr "" + +#: write.R:154 +msgid "{.arg metadata} must be a list." +msgstr "" + +#: write.R:155 +msgid "{.arg metadata} must be a named list." +msgstr "" + +#: write.R:158 +msgid "{.arg metadata} must be a named list of scalar characters." +msgstr "" From 46912df5276a554cacac1d85a3da1e7351a9f10d Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Fri, 6 Sep 2024 00:03:52 +0200 Subject: [PATCH 2/5] wrap cli_* functions with gettext --- R/safetensors.R | 8 ++++---- R/write.R | 12 ++++++------ inst/po/fr/LC_MESSAGES/R-safetensors.mo | Bin 1306 -> 1423 bytes po/R-fr.po | 16 ++++++++++------ po/R-safetensors.pot | 6 +++++- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/R/safetensors.R b/R/safetensors.R index 603b2be..7479541 100644 --- a/R/safetensors.R +++ b/R/safetensors.R @@ -119,7 +119,7 @@ safetensors <- R6::R6Class( if (self$framework == "torch") { torch_tensor_from_raw(raw_tensor, meta, self$device) } else { - cli::cli_abort("Unsupported framework {.val {.self$framework}}") + cli::cli_abort(gettext("Unsupported framework {.val {.self$framework}}")) } } ), @@ -160,16 +160,16 @@ torch_dtype_from_safe <- function(x) { "I32" = "int32", "I64" = "int64", "BF16" = "bfloat16", - cli::cli_abort("Unsupported dtype {.val {x}}") + cli::cli_abort(gettext("Unsupported dtype {.val {x}}")) ) } validate_framework <- function(x) { if (!x %in% c("torch")) { - cli::cli_abort("Unsupported framework {.val {x}}") + cli::cli_abort(gettext("Unsupported framework {.val {x}}")) } if (x == "torch") { - rlang::check_installed(x, reason = "for loading torch tensors.") + rlang::check_installed(x, reason = gettext("for loading torch tensors.")) } x } diff --git a/R/write.R b/R/write.R index 34e3602..655423a 100644 --- a/R/write.R +++ b/R/write.R @@ -22,7 +22,7 @@ #' @export safe_save_file <- function(tensors, path, ..., metadata = NULL) { if (any(duplicated(names(tensors)))) { - cli::cli_abort("Duplicated names are not allowed in {.arg tensors}") + cli::cli_abort(gettext("Duplicated names are not allowed in {.arg tensors}")) } if (is.character(path)) { @@ -118,7 +118,7 @@ torch_dtype_to_safe <- function(x) { } else if (x == torch::torch_int64()) { return("I64") } else { - cli::cli_abort("Unsupported data type {.val {x}}") + cli::cli_abort(gettext("Unsupported data type {.val {x}}")) } } @@ -144,18 +144,18 @@ size_from_meta <- function(meta) { } else if (meta$dtype == "BOOL") { 1L } else { - cli::cli_abort("Unsupported dtype {.val {meta$dtype}}") + cli::cli_abort(gettext("Unsupported dtype {.val {meta$dtype}}")) } as.integer(numel*el_size) } validate_metadata <- function(x) { - if (!rlang::is_list(x)) cli::cli_abort("{.arg metadata} must be a list.") - if (!rlang::is_named(x)) cli::cli_abort("{.arg metadata} must be a named list.") + if (!rlang::is_list(x)) cli::cli_abort(gettext("{.arg metadata} must be a list.")) + if (!rlang::is_named(x)) cli::cli_abort(gettext("{.arg metadata} must be a named list.")) lapply(x, function(item) { if (!rlang::is_scalar_character(item)) - cli::cli_abort("{.arg metadata} must be a named list of scalar characters.") + cli::cli_abort(gettext("{.arg metadata} must be a named list of scalar characters.")) }) x } diff --git a/inst/po/fr/LC_MESSAGES/R-safetensors.mo b/inst/po/fr/LC_MESSAGES/R-safetensors.mo index c20c7f584060744979ac91cf2d9d683f56d97433..34c1dd83e218394564f533c1f6bffd696a864451 100644 GIT binary patch delta 456 zcmY+_mgr*S8Bkla-eeTc~tn1ru z$7`|B7fzdn+zWiUnqHEhsk>~0Syt1k%bWCr;YR&#=QxUQ19_l5=C+01<0rm2lKc9C z+|i5w?vyHhKf-LzoVG1myvMzexjabb^GIN!URRT+`rdLi@;D24H13Y?v2$_I7Pb?{ NBf$gJR+eVQ_yx91S6To7 delta 355 zcmX}mtxp3n7=ZD2_rcf*hy?|NHDL(E2<#w`Nxn3efGKws3zvi3Hhq>UM1z@_Bf+2$ z7!(Np1%iO!5nu>G@f=@Gp8VRTZF(}&FK3Sx?^GCNnxdFS>6-HKN)37=MYV#+EN)_c z{s8Ck7!_V&74NZ$ADEvH9Fce2!8P1=zwc#YnXIsJ^RpqJxX60W6PdwX%pb^b3(v5Q zFUZ?6O!?=zCcG^r`Wr*P6CaDj6_JhZQQQi3$3!a8cDnFj6KBHKor~hKY6Q)tRr~B* zmQ13e!|r};?7+SA*L9Q{`{YjAo>%!_Rju}GcFbQGH!9Sr4m-E!scEZrsAJu-dw%c* Dl2JOP diff --git a/po/R-fr.po b/po/R-fr.po index e477047..06263dd 100644 --- a/po/R-fr.po +++ b/po/R-fr.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: safetensors 0.1.2.9000\n" -"POT-Creation-Date: 2024-09-05 23:44+0200\n" -"PO-Revision-Date: 2024-09-05 23:48+0200\n" +"POT-Creation-Date: 2024-09-05 23:57+0200\n" +"PO-Revision-Date: 2024-09-06 00:02+0200\n" "Last-Translator: \n" "Language-Team: \n" "Language: fr\n" @@ -13,7 +13,7 @@ msgstr "" #: safetensors.R:122 msgid "Unsupported framework {.val {.self$framework}}" -msgstr "Cadre non pris en charge {.val {.self$framework}}" +msgstr "Framework non pris en charge {.val {.self$framework}}" #: safetensors.R:163 msgid "Unsupported dtype {.val {x}}" @@ -21,11 +21,15 @@ msgstr "Type de données non pris en charge {.val {x}}" #: safetensors.R:169 msgid "Unsupported framework {.val {x}}" -msgstr "Cadre non pris en charge {.val {x}}" +msgstr "Framework non pris en charge {.val {x}}" + +#: safetensors.R:172 +msgid "for loading torch tensors." +msgstr "pour le chargement des tenseurs torch." #: write.R:25 msgid "Duplicated names are not allowed in {.arg tensors}" -msgstr "Les noms en double ne sont pas autorisés dans les tenseurs {.arg}" +msgstr "Les noms dupliqués ne sont pas autorisés dans les tenseurs {.arg}" #: write.R:121 msgid "Unsupported data type {.val {x}}" @@ -45,4 +49,4 @@ msgstr "{.arg metadata} doit être une liste nommée." #: write.R:158 msgid "{.arg metadata} must be a named list of scalar characters." -msgstr "{.arg metadata} doit être une liste nommée de caractères scalaires." +msgstr "{.arg metadata} doit être une liste nommée d'une seule chaîne de caractères." diff --git a/po/R-safetensors.pot b/po/R-safetensors.pot index 700a23c..e4a50b7 100644 --- a/po/R-safetensors.pot +++ b/po/R-safetensors.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: safetensors 0.1.2.9000\n" -"POT-Creation-Date: 2024-09-05 23:44+0200\n" +"POT-Creation-Date: 2024-09-05 23:57+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -22,6 +22,10 @@ msgstr "" msgid "Unsupported framework {.val {x}}" msgstr "" +#: safetensors.R:172 +msgid "for loading torch tensors." +msgstr "" + #: write.R:25 msgid "Duplicated names are not allowed in {.arg tensors}" msgstr "" From 07d82fb22ca230c8ab29fd2bc321b083945c7a27 Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Fri, 6 Sep 2024 00:15:20 +0200 Subject: [PATCH 3/5] fix translation typo and add test --- inst/po/fr/LC_MESSAGES/R-safetensors.mo | Bin 1423 -> 1427 bytes po/R-fr.po | 4 ++-- tests/testthat/test-message-translations.R | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-message-translations.R diff --git a/inst/po/fr/LC_MESSAGES/R-safetensors.mo b/inst/po/fr/LC_MESSAGES/R-safetensors.mo index 34c1dd83e218394564f533c1f6bffd696a864451..9d2afa0209577d7b9c7409413aaa0817b234378c 100644 GIT binary patch delta 122 zcmeC@p3FU=#@C&JfuWn3fk6*QUk1|VK$?jK!nXp_ra*oskX8rM^MSM)kUkEiRe|(7 zARPdtMOYaabb)m0#*<=9OoqmjA2Qt*O;pIqEG|h^sMbp?N>?aJ%`46?D&BmS`4A%j DRJ0fR delta 118 zcmbQt-OoLt#@CsFfuWn3fk6*Qp9j+BK>8n)Z^pvFU<%}?0%>(1JsU`?0qMg)S`|pY z0@49MT7Z>-K^I6TZagW*#AIMJ`61J7!PH`flGME7)Y772g=)RTqV&xdnGZ1n08Nk= AZ~y=R diff --git a/po/R-fr.po b/po/R-fr.po index 06263dd..d28829a 100644 --- a/po/R-fr.po +++ b/po/R-fr.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: safetensors 0.1.2.9000\n" "POT-Creation-Date: 2024-09-05 23:57+0200\n" -"PO-Revision-Date: 2024-09-06 00:02+0200\n" +"PO-Revision-Date: 2024-09-06 00:13+0200\n" "Last-Translator: \n" "Language-Team: \n" "Language: fr\n" @@ -29,7 +29,7 @@ msgstr "pour le chargement des tenseurs torch." #: write.R:25 msgid "Duplicated names are not allowed in {.arg tensors}" -msgstr "Les noms dupliqués ne sont pas autorisés dans les tenseurs {.arg}" +msgstr "Les noms dupliqués ne sont pas autorisés dans la liste {.arg tensors}" #: write.R:121 msgid "Unsupported data type {.val {x}}" diff --git a/tests/testthat/test-message-translations.R b/tests/testthat/test-message-translations.R new file mode 100644 index 0000000..a622aea --- /dev/null +++ b/tests/testthat/test-message-translations.R @@ -0,0 +1,9 @@ +test_that("R-level cli_abort messages are correctly translated in FR", { + + withr::with_language(lang = "fr", + expect_error( + safe_save_file(list(x = torch::torch_randn(10, 10), x = torch::torch_randn(10, 10))), + regexp = "Les noms dupliqués ne sont pas autorisés", + fixed = TRUE + )) + }) From 1014d2adaa02212407036107b5e493c50bf88919 Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Fri, 6 Sep 2024 00:17:19 +0200 Subject: [PATCH 4/5] add NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a2c07b3..1227488 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # safetensors (development version) +* Add FR translation of messages (#7 @cregouby) + # safetensors 0.1.2 * Added support for BF16 data types. From 4338306643cc3481ccbb20e8dc4009a3e24a1abc Mon Sep 17 00:00:00 2001 From: Daniel Falbel Date: Tue, 17 Sep 2024 11:24:22 -0300 Subject: [PATCH 5/5] Suggest withr for tests --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd9a0cc..8cf3e54 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,8 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Suggests: testthat (>= 3.0.0), - torch (>= 0.11.0) + torch (>= 0.11.0), + withr Config/testthat/edition: 3 Imports: cli,