Skip to content

Commit 785ebe1

Browse files
authored
Merge pull request #7382 from jepler/translate-name-not-known
Make the "name or service not known" message translatable
2 parents b0a635a + 928fb0a commit 785ebe1

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,10 @@ msgstr ""
14031403
msgid "NVS Error"
14041404
msgstr ""
14051405

1406+
#: shared-bindings/socketpool/SocketPool.c
1407+
msgid "Name or service not known"
1408+
msgstr ""
1409+
14061410
#: py/qstr.c
14071411
msgid "Name too long"
14081412
msgstr ""

ports/espressif/common-hal/socketpool/Socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void common_hal_socketpool_socket_connect(socketpool_socket_obj_t *self,
369369
struct addrinfo *result_i;
370370
int error = lwip_getaddrinfo(host, NULL, &hints, &result_i);
371371
if (error != 0 || result_i == NULL) {
372-
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
372+
common_hal_socketpool_socketpool_raise_gaierror_noname();
373373
}
374374

375375
// Set parameters
@@ -550,7 +550,7 @@ mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t *self,
550550
struct addrinfo *result_i;
551551
int error = lwip_getaddrinfo(host, NULL, &hints, &result_i);
552552
if (error != 0 || result_i == NULL) {
553-
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
553+
common_hal_socketpool_socketpool_raise_gaierror_noname();
554554
}
555555

556556
// Set parameters

ports/raspberrypi/common-hal/socketpool/SocketPool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void socketpool_resolve_host_raise(socketpool_socketpool_obj_t *self, const char
9898
int result = socketpool_resolve_host(self, host, addr);
9999
if (result < 0) {
100100
printf("socket_resolve_host() returned %d\n", result);
101-
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
101+
common_hal_socketpool_socketpool_raise_gaierror_noname();
102102
mp_raise_OSError(-result);
103103
}
104104
}

shared-bindings/socketpool/SocketPool.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,21 @@ MP_WEAK
198198
mp_obj_t common_hal_socketpool_socketpool_gethostbyname_raise(socketpool_socketpool_obj_t *self, const char *host) {
199199
mp_obj_t ip_str = common_hal_socketpool_socketpool_gethostbyname(self, host);
200200
if (ip_str == mp_const_none) {
201-
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
201+
common_hal_socketpool_socketpool_raise_gaierror_noname();
202202
}
203203
return ip_str;
204204
}
205205

206206
MP_WEAK NORETURN
207-
void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name) {
208-
mp_obj_t exc_args[2] = {
209-
MP_OBJ_NEW_SMALL_INT(value),
210-
MP_OBJ_NEW_QSTR(name),
207+
void common_hal_socketpool_socketpool_raise_gaierror_noname(void) {
208+
vstr_t vstr;
209+
mp_print_t print;
210+
vstr_init_print(&vstr, 64, &print);
211+
mp_printf(&print, "%S", translate("Name or service not known"));
212+
213+
mp_obj_t exc_args[] = {
214+
MP_OBJ_NEW_SMALL_INT(SOCKETPOOL_EAI_NONAME),
215+
mp_obj_new_str_from_vstr(&mp_type_str, &vstr),
211216
};
212-
nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, 2, exc_args));
217+
nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, MP_ARRAY_SIZE(exc_args), exc_args));
213218
}

shared-bindings/socketpool/SocketPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ bool socketpool_socket(socketpool_socketpool_obj_t *self,
7373
socketpool_socketpool_addressfamily_t family, socketpool_socketpool_sock_t type,
7474
socketpool_socket_obj_t *sock);
7575

76-
NORETURN void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name);
76+
NORETURN void common_hal_socketpool_socketpool_raise_gaierror_noname(void);
7777

7878
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SOCKETPOOL_SOCKETPOOL_H

0 commit comments

Comments
 (0)