AmendHub

Download:

jcs

/

wifi_da

/

amendments

/

35

*: Add localization of strings

Prompted by Jean-Michel Durand, this moves all strings into a 'STR#'
resource and based on the system's 'itlb' resource itlbLang value,
we will look for an 'STR#' resource with that ID before falling
back on the default English strings.
 
This also consolidates the SSID and password entry dialogs and makes
more room for longer strings (looking at you, German).

jcs made amendment 35 about 1 month ago
--- main.c Tue Dec 3 17:31:02 2024 +++ main.c Tue Dec 3 22:23:52 2024 @@ -17,6 +17,7 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <Script.h> #include "wi-fi.h" /* device control entry */ @@ -43,6 +44,7 @@ bool handle_menu(short i); void handle_event(EventRecord *e); void handle_timer(void); void logger_vprintf(const char *format, va_list ap); +void find_str_res_id(void); short main(cntrlParam *p, DCtlPtr d, short n) @@ -60,6 +62,7 @@ main(cntrlParam *p, DCtlPtr d, short n) if (dce == NULL) { util_init(d); SysEnvirons(1, &world); + find_str_res_id(); } dce = d; @@ -92,13 +95,14 @@ main(cntrlParam *p, DCtlPtr d, short n) void da_open(void) { + Str255 str; CursHandle h; Rect bounds; bool dispose; dce->dCtlFlags |= dNeedLock | dNeedTime | dNeedGoodBye; dce->dCtlDelay = 61; - + if (wifi_da.win) SelectWindow(wifi_da.win); @@ -121,7 +125,10 @@ da_open(void) dce->dCtlMenu = menuID = OwnedResourceID(MAIN_MENU_ID); menu = GetMenu(menuID); (**menu).menuID = menuID; - InsertMenu(menu = GetMenu(menuID), 0); + menu = GetMenu(menuID); + GetIndString(str, wifi_da.str_res_id, STR_ABOUT_WIFI_ID); + SetItem(menu, MAIN_MENU_ABOUT_ID, str); + InsertMenu(menu, 0); DrawMenuBar(); } @@ -302,4 +309,34 @@ logger_vprintf(const char *format, va_list ap) ValidRect(&wifi_da.logger->portRect); SetPort(savePort); -} +} + +void +find_str_res_id(void) +{ + Handle itlb_h, str_h; + ItlbRecord *itlb; + bool found_str = false; + + /* find language of this system */ + wifi_da.str_res_id = OwnedResourceID(STR_BASE_ID); + itlb_h = GetResource('itlb', 0); + if (itlb_h != NULL) { + HLock(itlb_h); + itlb = (ItlbRecord *)(*itlb_h); + ReleaseResource(itlb_h); + + str_h = GetResource('STR#', wifi_da.str_res_id + itlb->itlbLang); + if (str_h != NULL) { + wifi_da.str_res_id += itlb->itlbLang; + ReleaseResource(str_h); + found_str = true; + } + } + if (!found_str) { + str_h = GetResource('STR#', wifi_da.str_res_id); + if (str_h == NULL) + panic("Can't find STR# %d", wifi_da.str_res_id); + ReleaseResource(str_h); + } +} \ No newline at end of file --- wi-fi.h Tue Dec 3 16:51:15 2024 +++ wi-fi.h Tue Dec 3 22:10:25 2024 @@ -20,20 +20,36 @@ #include <stdlib.h> #include "util.h" +#define DA_HEIGHT 25 +#define DA_WIDTH 180 + #define MAIN_MENU_ID 1 #define MAIN_MENU_ABOUT_ID 1 #define MAIN_MENU_QUIT_ID 3 -#define ERROR_DIALOG_ID 0 +#define PROMPT_DIALOG_ID 1 +#define PROMPT_DIALOG_INPUT_FIELD_ID 3 +#define PROMPT_DIALOG_PASSWORD_STORAGE_ID 4 +#define PROMPT_DIALOG_INPUT_LABEL_ID 5 +#define PROMPT_DIALOG_TITLE_LABEL_ID 6 -#define PASSWORD_DIALOG_ID 1 -#define PASSWORD_DIALOG_PASSWORD_FIELD_ID 3 -#define PASSWORD_DIALOG_PASSWORD_STORAGE_ID 4 - #define ABOUT_DIALOG_ID 2 -#define SSID_DIALOG_ID 3 -#define SSID_DIALOG_NAME_FIELD_ID 3 +#define STR_BASE_ID 0 +#define STR_FINDING_WIFI_ID 1 +#define STR_NO_DEVICE_FOUND_ID 2 +#define STR_NO_NETWORK_ID 3 +#define STR_OTHER_NETWORK_ID 4 +#define STR_DEBUG_LOGS_ID 5 +#define STR_CONTINUE_ID 6 +#define STR_CANCEL_ID 7 +#define STR_SSID_DIALOG_TITLE_ID 8 +#define STR_ENTER_SSID_ID 9 +#define STR_SSID_ID 10 +#define STR_PASSWORD_DIALOG_TITLE_ID 11 +#define STR_REQUIRES_PASSWORD_ID 12 +#define STR_PASSWORD_ID 13 +#define STR_ABOUT_WIFI_ID 14 #define BLUESCSI_NETWORK_WIFI_CMD 0x1c #define BLUESCSI_NETWORK_WIFI_CMD_SCAN 0x01 @@ -68,6 +84,7 @@ enum signal_icon_id { struct wifi_da { short state; + short str_res_id; WindowPtr win; Rect bounds; ControlHandle ssid_list; --- Wi-Fi DA.π.r Tue Sep 17 20:45:37 2024 +++ Wi-Fi DA.π.r Tue Dec 3 22:29:31 2024 @@ -8,17 +8,16 @@ data 'DITL' (-16000) { $"5E30 5E31 5E32 5E33" /* ^0^1^2^3 */ }; -data 'DITL' (-15999, "PASSWORD") { - $"0005 0000 0000 0050 0136 0064 017F 0407" /* .......P.6.d.... */ - $"436F 6E6E 6563 745B 0000 0000 0050 00E6" /* Connect[.....P.. */ - $"0064 012F 0406 4361 6E63 656C 0000 0000" /* .d./..Cancel.... */ - $"0032 005A 0042 017D 1000 0000 0000 0078" /* .2.Z.B.}.......x */ +data 'DITL' (-15999, "PROMPT") { + $"0005 0000 0000 0041 0122 0055 0180 0407" /* .......A.".U.Ä.. */ + $"436F 6E6E 6563 745B 0000 0000 0041 00B9" /* Connect[.....A.π */ + $"0055 0117 0406 4361 6E63 656C 0000 0000" /* .U....Cancel.... */ + $"0023 0078 0033 017D 1000 0000 0000 0078" /* .#.x.3.}.......x */ $"005A 008E 0180 8803 2E2E 2E73 0000 0000" /* .Z.é.Äà....s.... */ - $"0032 000A 0042 0055 8809 5061 7373 776F" /* .2...B.Uà∆Passwo */ - $"7264 3A20 0000 0000 000A 000A 0029 0182" /* rd: .........).Ç */ - $"882B 5468 6520 5769 2D46 6920 6E65 7477" /* à+The Wi-Fi netw */ - $"6F72 6B20 225E 3022 2072 6571 7569 7265" /* ork "^0" require */ - $"7320 6120 7061 7373 776F 7264 2E00" /* s a password.. */ + $"0023 000A 0033 0073 8809 5061 7373 776F" /* .#...3.sà∆Passwo */ + $"7264 3A20 0000 0000 000A 000A 001B 0183" /* rd: ...........É */ + $"8819 225E 3022 2072 6571 7569 7265 7320" /* à."^0" requires */ + $"6120 7061 7373 776F 7264 3A00" /* a password:. */ }; data 'DITL' (-15998, "ABOUT", purgeable, preload) { @@ -28,17 +27,6 @@ data 'DITL' (-15998, "ABOUT", purgeable, preload) { $"0000 FFD8 0106 011E C002 C180" /* ...ÿ....¿.¡Ä */ }; -data 'DITL' (-15997, "SSID") { - $"0004 0000 0000 0041 0136 0055 017F 0408" /* .......A.6.U.... */ - $"436F 6E74 696E 7565 0000 0000 0041 00E6" /* Continue.....A.. */ - $"0055 012F 0406 4361 6E63 656C 0000 0000" /* .U./..Cancel.... */ - $"0023 005A 0033 017D 1000 0000 0000 0023" /* .#.Z.3.}.......# */ - $"000A 0033 0055 8805 5353 4944 3A00 0000" /* ...3.Uà.SSID:... */ - $"0000 000A 000A 001C 0105 881D 456E 7465" /* ..........à.Ente */ - $"7220 7468 6520 5769 2D46 6920 6E65 7477" /* r the Wi-Fi netw */ - $"6F72 6B20 5353 4944 3A00" /* ork SSID:. */ -}; - data 'MENU' (-15999) { $"C181 0000 0000 0000 0000 FFFF FFFF 0557" /* ¡Å.............W */ $"692D 4669 0E41 626F 7574 2057 692D 4669" /* i-Fi.About Wi-Fi */ @@ -46,7 +34,7 @@ data 'MENU' (-15999) { }; data 'DLOG' (-15999) { - $"0066 0036 00D6 01C3 0010 0000 0100 0000" /* .f.6.÷.√........ */ + $"0066 0036 00C8 01C2 0010 0000 0100 0000" /* .f.6.».¬........ */ $"0000 C181 0E57 692D 4669 2050 6173 7377" /* ..¡Å.Wi-Fi Passw */ $"6F72 641C 680A" /* ord.h. */ }; @@ -61,12 +49,6 @@ data 'DLOG' (-15998) { $"0000 C182 0000 280A" /* ..¡Ç..(. */ }; -data 'DLOG' (-15997) { - $"0076 0036 00D4 01C4 0010 0000 0100 0000" /* .v.6.‘.ƒ........ */ - $"0000 C183 0A57 692D 4669 2053 5349 4477" /* ..¡É.Wi-Fi SSIDw */ - $"680A" /* h. */ -}; - data 'SICN' (-16000) { $"0000 6006 700E 3FFC 1FF8 3E7C 67E6 4FF2" /* ..`.p.?...>|g.O. */ $"1BD8 17E8 0FF0 1C38 399C 718E 6006 0000" /* .ÿ.....89úqé`... */ @@ -109,7 +91,7 @@ data 'BNDL' (-16000) { }; data 'vers' (1) { - $"0120 8000 0000 0331 2E32 2B31 2E32 20A9" /* . Ä....1.2+1.2 © */ + $"0130 8000 0000 0331 2E33 2B31 2E33 20A9" /* .0Ä....1.3+1.3 © */ $"2032 3032 332D 3230 3234 2C20 6A6F 7368" /* 2023-2024, josh */ $"7561 2073 7465 696E 203C 6A63 7340 6A63" /* ua stein <jcs@jc */ $"732E 6F72 673E" /* s.org> */ @@ -554,5 +536,21 @@ data 'dast' (-16000) { $"2073 7465 696E 0D0D 5765 623A 2068 7474" /* stein¬¬Web: htt */ $"703A 2F2F 6A63 732E 6F72 672F 0D0D 4920" /* p://jcs.org/¬¬I */ $"6D69 7373 2079 6F75 2C20 4361 726C" /* miss you, Carl */ +}; + +data 'STR#' (-16000, "English (default)") { + $"000E 1046 696E 6469 6E67 2057 692D 4669" /* ...Finding Wi-Fi */ + $"2E2E 2E0F 4E6F 2044 6576 6963 6520 466F" /* ....No Device Fo */ + $"756E 640C 284E 6F20 4E65 7477 6F72 6B29" /* und.(No Network) */ + $"104F 7468 6572 204E 6574 776F 726B 2E2E" /* .Other Network.. */ + $"2E0A 4465 6275 6720 4C6F 6773 0843 6F6E" /* ..Debug Logs.Con */ + $"7469 6E75 6506 4361 6E63 656C 0A57 692D" /* tinue.Cancel.Wi- */ + $"4669 2053 5349 441D 456E 7465 7220 7468" /* Fi SSID.Enter th */ + $"6520 5769 2D46 6920 6E65 7477 6F72 6B20" /* e Wi-Fi network */ + $"5353 4944 3A05 5353 4944 3A0E 5769 2D46" /* SSID:.SSID:.Wi-F */ + $"6920 5061 7373 776F 7264 1922 5E30 2220" /* i Password."^0" */ + $"7265 7175 6972 6573 2061 2070 6173 7377" /* requires a passw */ + $"6F72 643A 0950 6173 7377 6F72 643A 0E41" /* ord:∆Password:.A */ + $"626F 7574 2057 692D 4669 2E2E 2E" /* bout Wi-Fi... */ }; --- window.c Tue Dec 3 17:37:52 2024 +++ window.c Tue Dec 3 22:11:09 2024 @@ -18,13 +18,6 @@ #include <string.h> #include "wi-fi.h" -#define NO_DEVICE_TEXT "\pNo Device Found" -#define NO_NETWORK_TEXT "(No Network)" -#define OTHER_NETWORK_TEXT "(Other Network)" - -#define DA_HEIGHT 25 -#define DA_WIDTH 180 - short nwifi_scan_networks = 0; struct wifi_network_entry wifi_menu_networks[nitems(wifi_scan_networks)] = { 0 }; short nwifi_menu_networks = 0; @@ -36,6 +29,7 @@ pascal Boolean WiFiPasswordDialogFieldFilter(DialogPtr void create_window(short ctlrefnum) { + Str255 str; GrafPtr savePort, tport; GetPort(&savePort); @@ -67,7 +61,8 @@ create_window(short ctlrefnum) SetRect(&wifi_da.icon_rect, 6, 4, 22, 20); /* ltrb */ wifi_da.ssid_menu = NewMenu(OwnedResourceID(10), "\p"); - InsMenuItem(wifi_da.ssid_menu, "\pFinding Wi-Fi...", 1); + GetIndString(str, wifi_da.str_res_id, STR_FINDING_WIFI_ID); + InsMenuItem(wifi_da.ssid_menu, str, 1); SetRect(&wifi_da.ssid_menu_rect, 30, 3, 170, 21); /* ltrb */ @@ -84,7 +79,8 @@ create_window(short ctlrefnum) if (wifi_scsi_id == WIFI_SCSI_ID_NONE) { wifi_da.state = STATE_IDLE; - SetItem(wifi_da.ssid_menu, 1, NO_DEVICE_TEXT); + GetIndString(str, wifi_da.str_res_id, STR_NO_DEVICE_FOUND_ID); + SetItem(wifi_da.ssid_menu, 1, str); update_window(true); } else { scsi_wifi_info(wifi_scsi_id, &wifi_cur_info); @@ -98,13 +94,15 @@ create_window(short ctlrefnum) void create_logger(void) { + Str255 str; Rect bounds; bounds.top = 150; bounds.bottom = 320; bounds.left = 20; bounds.right = 400; - wifi_da.logger = NewWindow(0L, &bounds, "\pLogger", true, rDocProc, 0L, + GetIndString(str, wifi_da.str_res_id, STR_DEBUG_LOGS_ID); + wifi_da.logger = NewWindow(0L, &bounds, str, true, rDocProc, 0L, false, 0L); ((WindowPeek)wifi_da.logger)->windowKind = dce->dCtlRefNum; } @@ -226,6 +224,7 @@ update_wifi_cur_info(void) void update_wifi_ssid_list(bool update_networks) { + Str255 str; char ssid[64] = { 0 }; short n, m, mitem; @@ -275,14 +274,18 @@ update_wifi_ssid_list(bool update_networks) nwifi_menu_networks = m; if (wifi_menu_networks[0].ssid[0] == '\0') { - strlcpy(wifi_menu_networks[0].ssid, NO_NETWORK_TEXT, + GetIndString(str, wifi_da.str_res_id, STR_NO_NETWORK_ID); + PtoCstr(str); + strlcpy(wifi_menu_networks[0].ssid, (char *)str, sizeof(wifi_menu_networks[0].ssid)); nwifi_menu_networks++; } /* keep "other network" as last entry */ + GetIndString(str, wifi_da.str_res_id, STR_OTHER_NETWORK_ID); + PtoCstr(str); strlcpy(wifi_menu_networks[nwifi_menu_networks - 1].ssid, - OTHER_NETWORK_TEXT, sizeof(wifi_menu_networks[0].ssid)); + (char *)str, sizeof(wifi_menu_networks[0].ssid)); wifi_menu_networks[nwifi_menu_networks - 1].flags = WIFI_NETWORK_FLAG_AUTH | WIFI_NETWORK_FLAG_HIDDEN; @@ -353,7 +356,7 @@ destroy_windows(void) void window_mousedown(Point p) { - Str255 password, ssid; + Str255 str, password, ssid; Rect menu_r, icon_r, r, irect; GrafPtr savePort; short mitems, n, selitem, hit, itype; @@ -416,12 +419,37 @@ window_mousedown(Point p) memset(&wjr, 0, sizeof(wjr)); if (net->flags & WIFI_NETWORK_FLAG_HIDDEN) { - dg = GetNewDialog(OwnedResourceID(SSID_DIALOG_ID), 0L, + dg = GetNewDialog(OwnedResourceID(PROMPT_DIALOG_ID), 0L, (WindowPtr)-1L); center_in_screen(((DialogPeek)dg)->window.port.portRect.right, ((DialogPeek)dg)->window.port.portRect.bottom, false, &r); MoveWindow(dg, r.left, r.top, false); - + + GetIndString(str, wifi_da.str_res_id, STR_SSID_DIALOG_TITLE_ID); + SetWTitle(dg, str); + + /* continue button */ + GetDItem(dg, ok, &itype, &ihandle, &irect); + GetIndString(str, wifi_da.str_res_id, STR_CONTINUE_ID); + SetCTitle(ihandle, str); + + /* cancel button */ + GetDItem(dg, cancel, &itype, &ihandle, &irect); + GetIndString(str, wifi_da.str_res_id, STR_CANCEL_ID); + SetCTitle(ihandle, str); + + /* "SSID:" */ + GetDItem(dg, PROMPT_DIALOG_INPUT_LABEL_ID, &itype, &ihandle, + &irect); + GetIndString(str, wifi_da.str_res_id, STR_SSID_ID); + SetIText(ihandle, str); + + /* "Enter the Wi-Fi network SSID:" */ + GetDItem(dg, PROMPT_DIALOG_TITLE_LABEL_ID, &itype, &ihandle, + &irect); + GetIndString(str, wifi_da.str_res_id, STR_ENTER_SSID_ID); + SetIText(ihandle, str); + ShowWindow(dg); SetPort(dg); @@ -443,7 +471,8 @@ window_mousedown(Point p) goto menu_done; } - GetDItem(dg, SSID_DIALOG_NAME_FIELD_ID, &itype, &ihandle, &irect); + GetDItem(dg, PROMPT_DIALOG_INPUT_FIELD_ID, &itype, &ihandle, + &irect); GetIText(ihandle, &ssid); PtoCstr(ssid); strlcpy(wjr.ssid, (char *)ssid, sizeof(wjr.ssid)); @@ -453,22 +482,46 @@ window_mousedown(Point p) strlcpy(wjr.ssid, net->ssid, sizeof(wjr.ssid)); if (net->flags & WIFI_NETWORK_FLAG_AUTH) { - strlcpy((char *)ssid, wjr.ssid, sizeof(ssid)); - CtoPstr(ssid); - ParamText(ssid, "\p", "\p", "\p"); - PtoCstr(ssid); - - dg = GetNewDialog(OwnedResourceID(PASSWORD_DIALOG_ID), 0L, + dg = GetNewDialog(OwnedResourceID(PROMPT_DIALOG_ID), 0L, (WindowPtr)-1L); center_in_screen(((DialogPeek)dg)->window.port.portRect.right, ((DialogPeek)dg)->window.port.portRect.bottom, false, &r); MoveWindow(dg, r.left, r.top, false); - + + GetIndString(str, wifi_da.str_res_id, STR_PASSWORD_DIALOG_TITLE_ID); + SetWTitle(dg, str); + + /* continue button */ + GetDItem(dg, ok, &itype, &ihandle, &irect); + GetIndString(str, wifi_da.str_res_id, STR_CONTINUE_ID); + SetCTitle(ihandle, str); + + /* cancel button */ + GetDItem(dg, cancel, &itype, &ihandle, &irect); + GetIndString(str, wifi_da.str_res_id, STR_CANCEL_ID); + SetCTitle(ihandle, str); + + /* "Password:" */ + GetDItem(dg, PROMPT_DIALOG_INPUT_LABEL_ID, &itype, &ihandle, + &irect); + GetIndString(str, wifi_da.str_res_id, STR_PASSWORD_ID); + SetIText(ihandle, str); + + /* "\"^0\" requires a password:" */ + GetDItem(dg, PROMPT_DIALOG_TITLE_LABEL_ID, &itype, &ihandle, + &irect); + GetIndString(str, wifi_da.str_res_id, STR_REQUIRES_PASSWORD_ID); + SetIText(ihandle, str); + + strlcpy((char *)ssid, wjr.ssid, sizeof(ssid)); + CtoPstr(ssid); + ParamText(ssid, "\p", "\p", "\p"); + ShowWindow(dg); SetPort(dg); - GetDItem(dg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, - &ihandle, &irect); + GetDItem(dg, PROMPT_DIALOG_PASSWORD_STORAGE_ID, &itype, &ihandle, + &irect); SetIText(ihandle, "\p"); /* outline ok button */ @@ -489,8 +542,8 @@ window_mousedown(Point p) goto menu_done; } - GetDItem(dg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, - &ihandle, &irect); + GetDItem(dg, PROMPT_DIALOG_PASSWORD_STORAGE_ID, &itype, &ihandle, + &irect); GetIText(ihandle, &password); PtoCstr(password); //DEBUG_LOG(("pass is \"%s\"", password)); @@ -535,7 +588,7 @@ WiFiPasswordDialogFieldFilter(DialogPtr dlg, EventReco return FALSE; } - GetDItem(dlg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, + GetDItem(dlg, PROMPT_DIALOG_PASSWORD_STORAGE_ID, &itype, &ihandle, &irect); GetIText(ihandle, &password); PtoCstr(password);