diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-08-07 22:08:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-07 22:08:19 -0400 |
| commit | 9da79c880e387ab05a683b67feb8f3da600d937d (patch) | |
| tree | 8cb5ee1feb0516c24ee270fcee5ed00d310aced8 /shared-bindings | |
| parent | 2029c4e87e3e71ada07c8be91fe6877edf4a606b (diff) | |
| parent | 933add6cd833bb6ba6682ad2b6eb478871415ff5 (diff) | |
Merge pull request #1097 from tannewt/i18n_only
Support internationalisation.
Diffstat (limited to 'shared-bindings')
34 files changed, 131 insertions, 103 deletions
diff --git a/shared-bindings/_stage/Layer.c b/shared-bindings/_stage/Layer.c index 3e615c497..a3334f635 100644 --- a/shared-bindings/_stage/Layer.c +++ b/shared-bindings/_stage/Layer.c @@ -28,6 +28,7 @@ #include "__init__.h" #include "Layer.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: _stage //| @@ -67,20 +68,20 @@ STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args, mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); self->graphic = bufinfo.buf; if (bufinfo.len != 2048) { - mp_raise_ValueError("graphic must be 2048 bytes long"); + mp_raise_ValueError(translate("graphic must be 2048 bytes long")); } mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); self->palette = bufinfo.buf; if (bufinfo.len != 32) { - mp_raise_ValueError("palette must be 32 bytes long"); + mp_raise_ValueError(translate("palette must be 32 bytes long")); } if (n_args > 4) { mp_get_buffer_raise(args[4], &bufinfo, MP_BUFFER_READ); self->map = bufinfo.buf; if (bufinfo.len < (self->width * self->height) / 2) { - mp_raise_ValueError("map buffer too small"); + mp_raise_ValueError(translate("map buffer too small")); } } else { self-> map = NULL; diff --git a/shared-bindings/_stage/Text.c b/shared-bindings/_stage/Text.c index c62d22afe..7a406271d 100644 --- a/shared-bindings/_stage/Text.c +++ b/shared-bindings/_stage/Text.c @@ -28,6 +28,7 @@ #include "__init__.h" #include "Text.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: _stage //| @@ -65,19 +66,19 @@ STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args, mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); self->font = bufinfo.buf; if (bufinfo.len != 2048) { - mp_raise_ValueError("font must be 2048 bytes long"); + mp_raise_ValueError(translate("font must be 2048 bytes long")); } mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); self->palette = bufinfo.buf; if (bufinfo.len != 32) { - mp_raise_ValueError("palette must be 32 bytes long"); + mp_raise_ValueError(translate("palette must be 32 bytes long")); } mp_get_buffer_raise(args[4], &bufinfo, MP_BUFFER_READ); self->chars = bufinfo.buf; if (bufinfo.len < self->width * self->height) { - mp_raise_ValueError("chars buffer too small"); + mp_raise_ValueError(translate("chars buffer too small")); } return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 721448fa4..58ed5b6b2 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -34,6 +34,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: analogio //| @@ -114,7 +115,7 @@ STATIC mp_obj_t analogio_analogout_obj_set_value(mp_obj_t self_in, mp_obj_t valu raise_error_if_deinited(common_hal_analogio_analogout_deinited(self)); uint32_t v = mp_obj_get_int(value); if (v >= (1 << 16)) { - mp_raise_ValueError("AnalogOut is only 16 bits. Value must be less than 65536."); + mp_raise_ValueError(translate("AnalogOut is only 16 bits. Value must be less than 65536.")); } common_hal_analogio_analogout_set_value(self, v); return mp_const_none; diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 4254c8ddb..e3eef924d 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -33,6 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: audiobusio //| @@ -221,7 +222,7 @@ STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) { raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); if (!common_hal_audiobusio_i2sout_get_playing(self)) { - mp_raise_RuntimeError("Not playing"); + mp_raise_RuntimeError(translate("Not playing")); } common_hal_audiobusio_i2sout_pause(self); return mp_const_none; diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 9ddfc5f11..831baea90 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -34,6 +34,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiobusio/PDMIn.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: audiobusio //| @@ -120,11 +121,11 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar uint32_t sample_rate = args[ARG_sample_rate].u_int; uint8_t bit_depth = args[ARG_bit_depth].u_int; if (bit_depth % 8 != 0) { - mp_raise_ValueError("Bit depth must be multiple of 8."); + mp_raise_ValueError(translate("Bit depth must be multiple of 8.")); } uint8_t oversample = args[ARG_oversample].u_int; if (oversample % 8 != 0) { - mp_raise_ValueError("Oversample must be multiple of 8."); + mp_raise_ValueError(translate("Oversample must be multiple of 8.")); } bool mono = args[ARG_mono].u_bool; @@ -132,7 +133,7 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar ? STARTUP_DELAY_DEFAULT : mp_obj_get_float(args[ARG_startup_delay].u_obj); if (startup_delay < 0.0 || startup_delay > 1.0) { - mp_raise_ValueError("Microphone startup delay must be in range 0.0 to 1.0"); + mp_raise_ValueError(translate("Microphone startup delay must be in range 0.0 to 1.0")); } common_hal_audiobusio_pdmin_construct(self, clock_pin, data_pin, sample_rate, @@ -189,7 +190,7 @@ STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destinat audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_obj); raise_error_if_deinited(common_hal_audiobusio_pdmin_deinited(self)); if (!MP_OBJ_IS_SMALL_INT(destination_length) || MP_OBJ_SMALL_INT_VALUE(destination_length) < 0) { - mp_raise_TypeError("destination_length must be an int >= 0"); + mp_raise_TypeError(translate("destination_length must be an int >= 0")); } uint32_t length = MP_OBJ_SMALL_INT_VALUE(destination_length); @@ -198,13 +199,13 @@ STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destinat mp_raise_NotImplementedError(""); } else if (mp_get_buffer(destination, &bufinfo, MP_BUFFER_WRITE)) { if (bufinfo.len / mp_binary_get_size('@', bufinfo.typecode, NULL) < length) { - mp_raise_ValueError("Destination capacity is smaller than destination_length."); + mp_raise_ValueError(translate("Destination capacity is smaller than destination_length.")); } uint8_t bit_depth = common_hal_audiobusio_pdmin_get_bit_depth(self); if (bufinfo.typecode != 'H' && bit_depth == 16) { - mp_raise_ValueError("destination buffer must be an array of type 'H' for bit_depth = 16"); + mp_raise_ValueError(translate("destination buffer must be an array of type 'H' for bit_depth = 16")); } else if (bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE && bit_depth == 8) { - mp_raise_ValueError("destination buffer must be a bytearray or array of type 'B' for bit_depth = 8"); + mp_raise_ValueError(translate("destination buffer must be a bytearray or array of type 'B' for bit_depth = 8")); } // length is the buffer length in slots, not bytes. uint32_t length_written = diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 97fe2dce5..db5b371e2 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -34,6 +34,7 @@ #include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/audioio/RawSample.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: audioio //| @@ -219,7 +220,7 @@ STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) { raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); if (!common_hal_audioio_audioout_get_playing(self)) { - mp_raise_RuntimeError("Not playing"); + mp_raise_RuntimeError(translate("Not playing")); } common_hal_audioio_audioout_pause(self); return mp_const_none; diff --git a/shared-bindings/audioio/RawSample.c b/shared-bindings/audioio/RawSample.c index a66145931..28b6027c3 100644 --- a/shared-bindings/audioio/RawSample.c +++ b/shared-bindings/audioio/RawSample.c @@ -33,6 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: audioio //| @@ -94,13 +95,13 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a if (bufinfo.typecode == 'h' || bufinfo.typecode == 'H') { bytes_per_sample = 2; } else if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'"); + mp_raise_ValueError(translate("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'")); } common_hal_audioio_rawsample_construct(self, ((uint8_t*)bufinfo.buf), bufinfo.len, bytes_per_sample, signed_samples, args[ARG_channel_count].u_int, args[ARG_sample_rate].u_int); } else { - mp_raise_TypeError("buffer must be a bytes-like object"); + mp_raise_TypeError(translate("buffer must be a bytes-like object")); } return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c index 05768e14d..4ff0abdda 100644 --- a/shared-bindings/audioio/WaveFile.c +++ b/shared-bindings/audioio/WaveFile.c @@ -27,12 +27,11 @@ #include <stdint.h> #include "lib/utils/context_manager_helpers.h" -// #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" -// #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audioio/WaveFile.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: audioio //| @@ -76,7 +75,7 @@ STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar if (MP_OBJ_IS_TYPE(args[0], &mp_type_fileio)) { common_hal_audioio_wavefile_construct(self, MP_OBJ_TO_PTR(args[0])); } else { - mp_raise_TypeError("file must be a file opened in byte mode"); + mp_raise_TypeError(translate("file must be a file opened in byte mode")); } return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index a5c000ae5..7f42153ec 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -35,6 +35,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: bitbangio //| @@ -107,7 +108,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_i2c_obj___exit___obj, 4, 4, static void check_lock(bitbangio_i2c_obj_t *self) { if (!shared_module_bitbangio_i2c_has_lock(self)) { - mp_raise_RuntimeError("Function requires lock"); + mp_raise_RuntimeError(translate("Function requires lock")); } } @@ -191,7 +192,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a uint32_t length = bufinfo.len; normalize_buffer_bounds(&start, args[ARG_end].u_int, &length); if (length == 0) { - mp_raise_ValueError("Buffer must be at least length 1"); + mp_raise_ValueError(translate("Buffer must be at least length 1")); } uint8_t status = shared_module_bitbangio_i2c_read(self, args[ARG_address].u_int, diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 3e1a62d8e..5fcfcb120 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -37,6 +37,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: bitbangio //| @@ -117,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_obj___exit___obj, 4, 4, static void check_lock(bitbangio_spi_obj_t *self) { if (!shared_module_bitbangio_spi_has_lock(self)) { - mp_raise_RuntimeError("Function requires lock"); + mp_raise_RuntimeError(translate("Function requires lock")); } } @@ -147,15 +148,15 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args, uint8_t polarity = args[ARG_polarity].u_int; if (polarity != 0 && polarity != 1) { - mp_raise_ValueError("Invalid polarity"); + mp_raise_ValueError(translate("Invalid polarity")); } uint8_t phase = args[ARG_phase].u_int; if (phase != 0 && phase != 1) { - mp_raise_ValueError("Invalid phase"); + mp_raise_ValueError(translate("Invalid phase")); } uint8_t bits = args[ARG_bits].u_int; if (bits != 8 && bits != 9) { - mp_raise_ValueError("Invalid number of bits"); + mp_raise_ValueError(translate("Invalid number of bits")); } shared_module_bitbangio_spi_configure(self, args[ARG_baudrate].u_int, polarity, phase, bits); @@ -280,7 +281,7 @@ STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_ normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length); if (out_length != in_length) { - mp_raise_ValueError("buffer slices must be of equal length"); + mp_raise_ValueError(translate("buffer slices must be of equal length")); } if (out_length == 0) { diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 0d21d30f0..dedcc0150 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -34,6 +34,8 @@ #include "lib/utils/buffer_helper.h" #include "lib/utils/context_manager_helpers.h" #include "py/runtime.h" +#include "supervisor/shared/translate.h" + //| .. currentmodule:: busio //| //| :class:`I2C` --- Two wire serial protocol @@ -115,7 +117,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i static void check_lock(busio_i2c_obj_t *self) { asm(""); if (!common_hal_busio_i2c_has_lock(self)) { - mp_raise_RuntimeError("Function requires lock."); + mp_raise_RuntimeError(translate("Function requires lock.")); } } @@ -205,7 +207,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, uint32_t length = bufinfo.len; normalize_buffer_bounds(&start, args[ARG_end].u_int, &length); if (length == 0) { - mp_raise_ValueError("Buffer must be at least length 1"); + mp_raise_ValueError(translate("Buffer must be at least length 1")); } uint8_t status = common_hal_busio_i2c_read(self, args[ARG_address].u_int, ((uint8_t*)bufinfo.buf) + start, length); diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 52c145d6d..7983a3a56 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -38,6 +38,7 @@ #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: busio //| @@ -129,7 +130,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_spi_obj___exit___obj, 4, 4, bus static void check_lock(busio_spi_obj_t *self) { asm(""); if (!common_hal_busio_spi_has_lock(self)) { - mp_raise_RuntimeError("Function requires lock"); + mp_raise_RuntimeError(translate("Function requires lock")); } } @@ -164,15 +165,15 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_ uint8_t polarity = args[ARG_polarity].u_int; if (polarity != 0 && polarity != 1) { - mp_raise_ValueError("Invalid polarity"); + mp_raise_ValueError(translate("Invalid polarity")); } uint8_t phase = args[ARG_phase].u_int; if (phase != 0 && phase != 1) { - mp_raise_ValueError("Invalid phase"); + mp_raise_ValueError(translate("Invalid phase")); } uint8_t bits = args[ARG_bits].u_int; if (bits != 8 && bits != 9) { - mp_raise_ValueError("Invalid number of bits"); + mp_raise_ValueError(translate("Invalid number of bits")); } if (!common_hal_busio_spi_configure(self, args[ARG_baudrate].u_int, @@ -337,7 +338,7 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length); if (out_length != in_length) { - mp_raise_ValueError("buffer slices must be of equal length"); + mp_raise_ValueError(translate("buffer slices must be of equal length")); } if (out_length == 0) { diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 1b63d8d0e..359334e5c 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -36,6 +36,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "py/stream.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: busio @@ -94,7 +95,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si uint8_t bits = args[ARG_bits].u_int; if (bits < 7 || bits > 9) { - mp_raise_ValueError("bits must be 7, 8 or 9"); + mp_raise_ValueError(translate("bits must be 7, 8 or 9")); } uart_parity_t parity = PARITY_NONE; @@ -106,7 +107,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si uint8_t stop = args[ARG_stop].u_int; if (stop != 1 && stop != 2) { - mp_raise_ValueError("stop must be 1 or 2"); + mp_raise_ValueError(translate("stop must be 1 or 2")); } common_hal_busio_uart_construct(self, tx, rx, @@ -304,7 +305,7 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_baudrate), MP_ROM_PTR(&busio_uart_baudrate_obj) }, - + // Nested Enum-like Classes. { MP_ROM_QSTR(MP_QSTR_Parity), MP_ROM_PTR(&busio_uart_parity_type) }, }; diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 1270f84e4..2a1cd7761 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -41,6 +41,7 @@ #include "shared-bindings/digitalio/DriveMode.h" #include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: digitalio //| @@ -207,7 +208,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_direction(mp_obj_t self_in, mp_ob } else if (value == &digitalio_direction_output_obj) { common_hal_digitalio_digitalinout_switch_to_output(self, false, DRIVE_MODE_PUSH_PULL); } else { - mp_raise_ValueError("Invalid direction."); + mp_raise_ValueError(translate("Invalid direction.")); } return mp_const_none; } @@ -236,7 +237,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_value(mp_obj_t self_in, mp_obj_t digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { - mp_raise_AttributeError("Cannot set value when direction is input."); + mp_raise_AttributeError(translate("Cannot set value when direction is input.")); return mp_const_none; } common_hal_digitalio_digitalinout_set_value(self, mp_obj_is_true(value)); @@ -262,7 +263,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_get_drive_mode(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { - mp_raise_AttributeError("Drive mode not used when direction is input."); + mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); return mp_const_none; } digitalio_drive_mode_t drive_mode = common_hal_digitalio_digitalinout_get_drive_mode(self); @@ -277,7 +278,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_o digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { - mp_raise_AttributeError("Drive mode not used when direction is input."); + mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); return mp_const_none; } digitalio_drive_mode_t c_drive_mode = DRIVE_MODE_PUSH_PULL; @@ -310,7 +311,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_get_pull(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { - mp_raise_AttributeError("Pull not used when direction is output."); + mp_raise_AttributeError(translate("Pull not used when direction is output.")); return mp_const_none; } digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(self); @@ -327,7 +328,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t p digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { - mp_raise_AttributeError("Pull not used when direction is output."); + mp_raise_AttributeError(translate("Pull not used when direction is output.")); return mp_const_none; } digitalio_pull_t pull = PULL_NONE; @@ -336,7 +337,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t p } else if (pull_obj == &digitalio_pull_down_obj) { pull = PULL_DOWN; } else if (pull_obj != mp_const_none) { - mp_raise_ValueError("Unsupported pull value."); + mp_raise_ValueError(translate("Unsupported pull value.")); } common_hal_digitalio_digitalinout_set_pull(self, pull); return mp_const_none; diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 1e95776d7..21da4fab9 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -32,6 +32,7 @@ #include "shared-module/gamepad/GamePad.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" #include "GamePad.h" @@ -96,11 +97,11 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_args > 8) { - mp_raise_TypeError("too many arguments"); + mp_raise_TypeError(translate("too many arguments")); } for (size_t i = 0; i < n_args; ++i) { if (!MP_OBJ_IS_TYPE(args[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("expected a DigitalInOut")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(args[i]); raise_error_if_deinited( @@ -157,4 +158,3 @@ const mp_obj_type_t gamepad_type = { .make_new = gamepad_make_new, .locals_dict = (mp_obj_dict_t*)&gamepad_locals_dict, }; - diff --git a/shared-bindings/help.c b/shared-bindings/help.c index d8ffc13dd..78301a91a 100644 --- a/shared-bindings/help.c +++ b/shared-bindings/help.c @@ -35,10 +35,11 @@ //| prints general port information. //| +// TODO(tannewt): Figure out how to translate this. Its weird because its a global string. + const char circuitpython_help_text[] = "Welcome to Adafruit CircuitPython " MICROPY_GIT_TAG "!\r\n" "\r\n" "Please visit learn.adafruit.com/category/circuitpython for project guides.\r\n" "\r\n" "To list built-in modules please do `help(\"modules\")`.\r\n"; -; diff --git a/shared-bindings/math/__init__.c b/shared-bindings/math/__init__.c index 84827842f..0bf8047c9 100644 --- a/shared-bindings/math/__init__.c +++ b/shared-bindings/math/__init__.c @@ -27,7 +27,7 @@ #include "py/builtin.h" #include "py/runtime.h" -#include "py/runtime.h" +#include "supervisor/shared/translate.h" #if MICROPY_PY_BUILTINS_FLOAT @@ -50,7 +50,7 @@ //| STATIC NORETURN void math_error(void) { - mp_raise_ValueError("math domain error"); + mp_raise_ValueError(translate("math domain error")); } #define MATH_FUN_1(py_name, c_name) \ @@ -343,7 +343,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { #pragma GCC diagnostic ignored "-Wfloat-equal" } else if (base == (mp_float_t)1.0) { #pragma GCC diagnostic pop - mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero"); + mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero")); } return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); } diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index c456a030f..7ed95ba3b 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -31,6 +31,7 @@ #include "py/nlr.h" #include "py/obj.h" #include "py/runtime.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: microcontroller //| @@ -85,7 +86,7 @@ const mp_obj_type_t mcu_pin_type = { void assert_pin(mp_obj_t obj, bool none_ok) { if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) { - mp_raise_TypeError_varg("Expected a %q", mcu_pin_type.name); + mp_raise_TypeError_varg(translate("Expected a %q"), mcu_pin_type.name); } } diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c index 0c627cdf9..da8d0bd94 100644 --- a/shared-bindings/microcontroller/__init__.c +++ b/shared-bindings/microcontroller/__init__.c @@ -39,8 +39,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" - #include "py/runtime.h" +#include "supervisor/shared/translate.h" //| :mod:`microcontroller` --- Pin references and cpu functionality //| ================================================================ @@ -123,7 +123,7 @@ STATIC mp_obj_t mcu_on_next_reset(mp_obj_t run_mode_obj) { } else if (run_mode_obj == &mcu_runmode_bootloader_obj) { run_mode = RUNMODE_BOOTLOADER; } else { - mp_raise_ValueError("Invalid run mode."); + mp_raise_ValueError(translate("Invalid run mode.")); } common_hal_mcu_on_next_reset(run_mode); diff --git a/shared-bindings/multiterminal/__init__.c b/shared-bindings/multiterminal/__init__.c index 32dcdd75d..8de3c50d7 100644 --- a/shared-bindings/multiterminal/__init__.c +++ b/shared-bindings/multiterminal/__init__.c @@ -23,12 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "shared-bindings/multiterminal/__init__.h" #include "py/obj.h" #include "py/mphal.h" #include "py/runtime.h" - -#include "shared-bindings/multiterminal/__init__.h" +#include "supervisor/shared/translate.h" //| :mod:`multiterminal` --- Manage additional terminal sources //| =========================================================== @@ -65,7 +65,7 @@ STATIC mp_obj_t multiterminal_obj_set_secondary_terminal(mp_obj_t secondary_term mp_obj_t readinto_m[3]; mp_load_method_maybe(secondary_terminal, MP_QSTR_readinto, readinto_m); if (write_m[0] == MP_OBJ_NULL || readinto_m[0] == MP_OBJ_NULL) { - mp_raise_ValueError("Stream missing readinto() or write() method."); + mp_raise_ValueError(translate("Stream missing readinto() or write() method.")); return mp_const_none; } common_hal_multiterminal_set_secondary_terminal(secondary_terminal); diff --git a/shared-bindings/multiterminal/__init__.h b/shared-bindings/multiterminal/__init__.h index 91099a5df..7c2884263 100644 --- a/shared-bindings/multiterminal/__init__.h +++ b/shared-bindings/multiterminal/__init__.h @@ -27,6 +27,8 @@ #ifndef SHARED_BINDINGS_MULTITERMINAL___INIT___H #define SHARED_BINDINGS_MULTITERMINAL___INIT___H +#include "py/obj.h" + void common_hal_multiterminal_schedule_secondary_terminal_read(mp_obj_t socket); mp_obj_t common_hal_multiterminal_get_secondary_terminal(); void common_hal_multiterminal_set_secondary_terminal(mp_obj_t secondary_terminal); diff --git a/shared-bindings/neopixel_write/__init__.c b/shared-bindings/neopixel_write/__init__.c index c3c475c7c..05d6fd97a 100644 --- a/shared-bindings/neopixel_write/__init__.c +++ b/shared-bindings/neopixel_write/__init__.c @@ -23,13 +23,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "shared-bindings/neopixel_write/__init__.h" #include "py/obj.h" #include "py/mphal.h" #include "py/runtime.h" - #include "shared-bindings/digitalio/DigitalInOut.h" -#include "shared-bindings/neopixel_write/__init__.h" +#include "supervisor/shared/translate.h" //| :mod:`neopixel_write` --- Low-level neopixel implementation //| =========================================================== @@ -64,7 +64,7 @@ //| STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) { if (!MP_OBJ_IS_TYPE(digitalinout_obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError_varg("Expected a %q", digitalio_digitalinout_type.name); + mp_raise_TypeError_varg(translate("Expected a %q"), digitalio_digitalinout_type.name); } // Convert parameters into expected types. const digitalio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj); diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index 56337df40..22cd838b1 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -29,6 +29,7 @@ #include "py/runtime.h" #include "py/runtime0.h" #include "shared-bindings/nvm/ByteArray.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: nvm //| @@ -81,7 +82,7 @@ STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(common_hal_nvm_bytearray_get_length(self), index_in, &slice)) { - mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError(translate("only slices with step=1 (aka None) are supported")); } if (value != MP_OBJ_SENTINEL) { #if MICROPY_PY_ARRAY_SLICE_ASSIGN @@ -95,19 +96,19 @@ STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj mp_buffer_info_t bufinfo; mp_get_buffer_raise(value, &bufinfo, MP_BUFFER_READ); if (bufinfo.len != src_len) { - mp_raise_ValueError("Slice and value different lengths."); + mp_raise_ValueError(translate("Slice and value different lengths.")); } src_len = bufinfo.len; src_items = bufinfo.buf; if (1 != mp_binary_get_size('@', bufinfo.typecode, NULL)) { - mp_raise_ValueError("Array values should be single bytes."); + mp_raise_ValueError(translate("Array values should be single bytes.")); } } else { - mp_raise_NotImplementedError("array/bytes required on right side"); + mp_raise_NotImplementedError(translate("array/bytes required on right side")); } if (!common_hal_nvm_bytearray_set_bytes(self, slice.start, src_items, src_len)) { - mp_raise_RuntimeError("Unable to write to nvm."); + mp_raise_RuntimeError(translate("Unable to write to nvm.")); } return mp_const_none; #else @@ -133,11 +134,11 @@ STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj // store mp_int_t byte_value = mp_obj_get_int(value); if (byte_value > 0xff || byte_value < 0) { - mp_raise_ValueError("Bytes must be between 0 and 255."); + mp_raise_ValueError(translate("Bytes must be between 0 and 255.")); } uint8_t short_value = byte_value; if (!common_hal_nvm_bytearray_set_bytes(self, index, &short_value, 1)) { - mp_raise_RuntimeError("Unable to write to nvm."); + mp_raise_RuntimeError(translate("Unable to write to nvm.")); } return mp_const_none; } diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index 8f6c76680..9b7094b4e 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -33,6 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PWMOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: pulseio //| @@ -160,7 +161,7 @@ STATIC mp_obj_t pulseio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t dut raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); mp_int_t duty = mp_obj_get_int(duty_cycle); if (duty < 0 || duty > 0xffff) { - mp_raise_ValueError("PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)"); + mp_raise_ValueError(translate("PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)")); } common_hal_pulseio_pwmout_set_duty_cycle(self, duty); return mp_const_none; @@ -190,9 +191,9 @@ STATIC mp_obj_t pulseio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t freq pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); if (!common_hal_pulseio_pwmout_get_variable_frequency(self)) { - mp_raise_AttributeError( + mp_raise_AttributeError(translate( "PWM frequency not writeable when variable_frequency is False on " - "construction."); + "construction.")); } common_hal_pulseio_pwmout_set_frequency(self, mp_obj_get_int(frequency)); return mp_const_none; diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 862dbd99d..acf88b9fb 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -33,6 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PulseIn.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: pulseio //| @@ -271,25 +272,25 @@ STATIC mp_obj_t pulsein_unary_op(mp_unary_op_t op, mp_obj_t self_in) { STATIC mp_obj_t pulsein_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) { if (value == mp_const_none) { // delete item - mp_raise_AttributeError("Cannot delete values"); + mp_raise_AttributeError(translate("Cannot delete values")); } else { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { - mp_raise_NotImplementedError("Slices not supported"); + mp_raise_NotImplementedError(translate("Slices not supported")); } else { uint16_t index = 0; if (MP_OBJ_IS_SMALL_INT(index_obj)) { index = MP_OBJ_SMALL_INT_VALUE(index_obj); } else { - mp_raise_TypeError("index must be int"); + mp_raise_TypeError(translate("index must be int")); } if (value == MP_OBJ_SENTINEL) { // load return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pulsein_get_item(self, index)); } else { - mp_raise_AttributeError("Read-only"); + mp_raise_AttributeError(translate("Read-only")); } } } diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index dc3c02500..1c97c37c3 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -34,6 +34,7 @@ #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pulseio/PWMOut.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: pulseio //| @@ -71,7 +72,7 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar mp_obj_t carrier_obj = args[0]; if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) { - mp_raise_TypeError_varg("Expected a %q", pulseio_pwmout_type.name); + mp_raise_TypeError_varg(translate("Expected a %q"), pulseio_pwmout_type.name); } // create Pulse object from the given pin @@ -130,7 +131,7 @@ STATIC mp_obj_t pulseio_pulseout_obj_send(mp_obj_t self_in, mp_obj_t pulses) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(pulses, &bufinfo, MP_BUFFER_READ); if (bufinfo.typecode != 'H') { - mp_raise_TypeError("Array must contain halfwords (type 'H')"); + mp_raise_TypeError(translate("Array must contain halfwords (type 'H')")); } common_hal_pulseio_pulseout_send(self, (uint16_t *)bufinfo.buf, bufinfo.len / 2); return mp_const_none; diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c index cea437e98..83698eac5 100644 --- a/shared-bindings/random/__init__.c +++ b/shared-bindings/random/__init__.c @@ -31,6 +31,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "shared-bindings/random/__init__.h" +#include "supervisor/shared/translate.h" //| :mod:`random` --- psuedo-random numbers and choices //| ======================================================== @@ -88,7 +89,7 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { // range(stop) if (stop <= 0) { - mp_raise_ValueError("stop not reachable from start"); + mp_raise_ValueError(translate("stop not reachable from start")); } } else { start = stop; @@ -96,7 +97,7 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) { if (n_args == 2) { // range(start, stop) if (start >= stop) { - mp_raise_ValueError("stop not reachable from start"); + mp_raise_ValueError(translate("stop not reachable from start")); } } else { // range(start, stop, step) @@ -107,10 +108,10 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) { } else if (step < 0) { n = (stop - start + step + 1) / step; } else { - mp_raise_ValueError("step must be non-zero"); + mp_raise_ValueError(translate("step must be non-zero")); } if (n <= 0) { - mp_raise_ValueError("invalid step"); + mp_raise_ValueError(translate("invalid step")); } } } @@ -142,7 +143,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(random_randint_obj, random_randint); STATIC mp_obj_t random_choice(mp_obj_t seq) { mp_int_t len = mp_obj_get_int(mp_obj_len(seq)); if (len == 0) { - mp_raise_IndexError("empty sequence"); + mp_raise_IndexError(translate("empty sequence")); } return mp_obj_subscr(seq, mp_obj_new_int(shared_modules_random_randrange(0, len, 1)), MP_OBJ_SENTINEL); } diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index aeedad12d..a0e9be302 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -34,13 +34,14 @@ #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" +#include "supervisor/shared/translate.h" void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError("RTC is not supported on this board"); + mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError("RTC is not supported on this board"); + mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } int MP_WEAK common_hal_rtc_get_calibration(void) { @@ -48,7 +49,7 @@ int MP_WEAK common_hal_rtc_get_calibration(void) { } void MP_WEAK common_hal_rtc_set_calibration(int calibration) { - mp_raise_NotImplementedError("RTC calibration is not supported on this board"); + mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); } const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 1cfeea59c..3484b9af8 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -33,6 +33,7 @@ #include "py/objnamedtuple.h" #include "py/runtime.h" #include "shared-bindings/storage/__init__.h" +#include "supervisor/shared/translate.h" //| :mod:`storage` --- storage management //| ======================================================== @@ -73,7 +74,7 @@ mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg mp_obj_t dest[2]; mp_load_method_maybe(vfs_obj, MP_QSTR_mount, dest); if (dest[0] == MP_OBJ_NULL) { - mp_raise_ValueError("filesystem must provide mount method"); + mp_raise_ValueError(translate("filesystem must provide mount method")); } common_hal_storage_mount(vfs_obj, mnt_str, mp_obj_is_true(args[ARG_readonly].u_obj)); diff --git a/shared-bindings/struct/__init__.c b/shared-bindings/struct/__init__.c index 5be255971..093597785 100644 --- a/shared-bindings/struct/__init__.c +++ b/shared-bindings/struct/__init__.c @@ -36,6 +36,7 @@ #include "py/parsenum.h" #include "shared-bindings/struct/__init__.h" #include "shared-module/struct/__init__.h" +#include "supervisor/shared/translate.h" //| :mod:`struct` --- manipulation of c-style data //| ======================================================== @@ -85,7 +86,6 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack); - //| .. function:: pack_into(fmt, buffer, offset, v1, v2, ...) //| //| Pack the values v1, v2, ... according to the format string fmt into a buffer @@ -100,7 +100,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { // negative offsets are relative to the end of the buffer offset = (mp_int_t)bufinfo.len + offset; if (offset < 0) { - mp_raise_RuntimeError("buffer too small"); + mp_raise_RuntimeError(translate("buffer too small")); } } byte *p = (byte *)bufinfo.buf; @@ -142,7 +142,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { // negative offsets are relative to the end of the buffer offset = bufinfo.len + offset; if (offset < 0) { - mp_raise_RuntimeError("buffer too small"); + mp_raise_RuntimeError(translate("buffer too small")); } } p += offset; diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index b9bcc5544..2705c8e58 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -31,6 +31,7 @@ #include "supervisor/shared/autoreload.h" #include "supervisor/shared/rgb_led_status.h" #include "supervisor/shared/stack.h" +#include "supervisor/shared/translate.h" #include "shared-bindings/supervisor/__init__.h" #include "shared-bindings/supervisor/Runtime.h" @@ -89,7 +90,7 @@ STATIC mp_obj_t supervisor_set_rgb_status_brightness(mp_obj_t lvl){ // This must be int. If cast to uint8_t first, will never raise a ValueError. int brightness_int = mp_obj_get_int(lvl); if(brightness_int < 0 || brightness_int > 255){ - mp_raise_ValueError("Brightness must be between 0 and 255"); + mp_raise_ValueError(translate("Brightness must be between 0 and 255")); } set_rgb_status_brightness((uint8_t)brightness_int); return mp_const_none; @@ -115,7 +116,7 @@ STATIC mp_obj_t supervisor_set_next_stack_limit(mp_obj_t size_obj) { mp_int_t size = mp_obj_get_int(size_obj); if (size < 256) { - mp_raise_ValueError("Stack size must be at least 256"); + mp_raise_ValueError(translate("Stack size must be at least 256")); } set_next_stack_size(size); diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 6a4dc90e2..83bbbe2cd 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -34,6 +34,7 @@ #include "lib/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/time/__init__.h" +#include "supervisor/shared/translate.h" #define EPOCH1970_EPOCH2000_DIFF_SECS 946684800 @@ -76,7 +77,7 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { int seconds = mp_obj_get_int(seconds_o); #endif if (seconds < 0) { - mp_raise_ValueError("sleep length must be non-negative"); + mp_raise_ValueError(translate("sleep length must be non-negative")); } common_hal_time_delay_ms(1000 * seconds); return mp_const_none; @@ -86,10 +87,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); #if MICROPY_PY_COLLECTIONS mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_args != 1) { - mp_raise_TypeError("time.struct_time() takes exactly 1 argument"); + mp_raise_TypeError(translate("time.struct_time() takes exactly 1 argument")); } if (!MP_OBJ_IS_TYPE(args[0], &mp_type_tuple) || ((mp_obj_tuple_t*) MP_OBJ_TO_PTR(args[0]))->len != 9) { - mp_raise_TypeError("time.struct_time() takes a 9-sequence"); + mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence")); } mp_obj_tuple_t* tuple = MP_OBJ_TO_PTR(args[0]); @@ -167,12 +168,12 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) { size_t len; if (!MP_OBJ_IS_TYPE(t, &mp_type_tuple) && !MP_OBJ_IS_TYPE(t, MP_OBJ_FROM_PTR(&struct_time_type_obj))) { - mp_raise_TypeError("Tuple or struct_time argument required"); + mp_raise_TypeError(translate("Tuple or struct_time argument required")); } mp_obj_tuple_get(t, &len, &elems); if (len != 9) { - mp_raise_TypeError("function takes exactly 9 arguments"); + mp_raise_TypeError(translate("function takes exactly 9 arguments")); } tm->tm_year = mp_obj_get_int(elems[0]); @@ -188,7 +189,7 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) { #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE mp_obj_t MP_WEAK rtc_get_time_source_time(void) { - mp_raise_RuntimeError("RTC is not supported on this board"); + mp_raise_RuntimeError(translate("RTC is not supported on this board")); } //| .. method:: time() @@ -224,7 +225,7 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { mp_int_t secs = mp_obj_int_get_checked(args[0]); if (secs < EPOCH1970_EPOCH2000_DIFF_SECS) - mp_raise_msg(&mp_type_OverflowError, "timestamp out of range for platform time_t"); + mp_raise_msg(&mp_type_OverflowError, translate("timestamp out of range for platform time_t")); timeutils_struct_time_t tm; timeutils_seconds_since_2000_to_struct_time(secs - EPOCH1970_EPOCH2000_DIFF_SECS, &tm); @@ -248,16 +249,16 @@ STATIC mp_obj_t time_mktime(mp_obj_t t) { size_t len; if (!MP_OBJ_IS_TYPE(t, &mp_type_tuple) && !MP_OBJ_IS_TYPE(t, MP_OBJ_FROM_PTR(&struct_time_type_obj))) { - mp_raise_TypeError("Tuple or struct_time argument required"); + mp_raise_TypeError(translate("Tuple or struct_time argument required")); } mp_obj_tuple_get(t, &len, &elem); if (len != 9) { - mp_raise_TypeError("function takes exactly 9 arguments"); + mp_raise_TypeError(translate("function takes exactly 9 arguments")); } if (mp_obj_get_int(elem[0]) < 2000) - mp_raise_msg(&mp_type_OverflowError, "timestamp out of range for platform time_t"); + mp_raise_msg(&mp_type_OverflowError, translate("timestamp out of range for platform time_t")); mp_uint_t secs = timeutils_mktime(mp_obj_get_int(elem[0]), mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])); diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 710260faf..326b0212e 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -36,6 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/touchio/TouchIn.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: touchio //| @@ -169,7 +170,7 @@ STATIC mp_obj_t touchio_touchin_obj_set_threshold(mp_obj_t self_in, mp_obj_t thr uint32_t new_threshold = mp_obj_get_int(threshold_obj); if (new_threshold < 0 || new_threshold > UINT16_MAX) { // I would use MP_STRINGIFY(UINT16_MAX), but that prints "0xffff" instead of 65536. - mp_raise_ValueError("threshold must be in the range 0-65536"); + mp_raise_ValueError(translate("threshold must be in the range 0-65536")); } common_hal_touchio_touchin_set_threshold(self, new_threshold); return mp_const_none; diff --git a/shared-bindings/util.c b/shared-bindings/util.c index 3dadc4c18..80a0bdaeb 100644 --- a/shared-bindings/util.c +++ b/shared-bindings/util.c @@ -30,11 +30,12 @@ #include "py/runtime.h" #include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" // Check if pin is None. If so, deinit() has already been called on the object, so complain. void raise_error_if_deinited(bool deinited) { if (deinited) { - mp_raise_ValueError("Object has been deinitialized and can no longer be used. Create a new object."); + mp_raise_ValueError(translate("Object has been deinitialized and can no longer be used. Create a new object.")); } } |
