Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# safetensors (development version)

* Add FR translation of messages (#7 @cregouby)

# safetensors 0.1.2

* Added support for BF16 data types.
Expand Down
8 changes: 4 additions & 4 deletions R/safetensors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"))
}
}
),
Expand Down Expand Up @@ -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
}
12 changes: 6 additions & 6 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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}}"))
}
}

Expand All @@ -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
}
Binary file added inst/po/fr/LC_MESSAGES/R-safetensors.mo
Binary file not shown.
52 changes: 52 additions & 0 deletions po/R-fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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:13+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.3\n"

#: safetensors.R:122
msgid "Unsupported framework {.val {.self$framework}}"
msgstr "Framework non pris en charge {.val {.self$framework}}"

#: safetensors.R:163
msgid "Unsupported dtype {.val {x}}"
msgstr "Type de données non pris en charge {.val {x}}"

#: safetensors.R:169
msgid "Unsupported framework {.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 dupliqués ne sont pas autorisés dans la liste {.arg tensors}"

#: write.R:121
msgid "Unsupported data type {.val {x}}"
msgstr "Type de données non pris en charge {.val {x}}"

#: write.R:147
msgid "Unsupported dtype {.val {meta$dtype}}"
msgstr "Type de données non pris en charge {.val {meta$dtype}}"

#: write.R:154
msgid "{.arg metadata} must be a list."
msgstr "{.arg metadata} doit être une liste."

#: write.R:155
msgid "{.arg metadata} must be a named list."
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 d'une seule chaîne de caractères."
51 changes: 51 additions & 0 deletions po/R-safetensors.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
msgid ""
msgstr ""
"Project-Id-Version: safetensors 0.1.2.9000\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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

#: safetensors.R:172
msgid "for loading torch tensors."
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 ""
9 changes: 9 additions & 0 deletions tests/testthat/test-message-translations.R
Original file line number Diff line number Diff line change
@@ -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
))
})