From 38c7dce84a4dc65514d121f5f0965045a43cf7cd Mon Sep 17 00:00:00 2001 From: Cole Ramos Date: Tue, 25 Mar 2025 16:39:02 -0500 Subject: [PATCH] Generalize locale checker to support more UTF-8 types (#623) Signed-off-by: coleramos425 --- src/utils/utils.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index d89926a944..af92be9403 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1163,13 +1163,25 @@ def print_status(msg): def set_locale_encoding(): try: + # Attempt to set the locale to 'C.UTF-8' locale.setlocale(locale.LC_ALL, "C.UTF-8") - except locale.Error as error: - console_error( - "Please ensure that the 'C.UTF-8' locale is available on your system.", - exit=False, - ) - console_error(error) + except locale.Error: + # If 'C.UTF-8' is not available, check if the current locale is UTF-8 based + current_locale = locale.getdefaultlocale() + if current_locale and "UTF-8" in current_locale[1]: + try: + locale.setlocale(locale.LC_ALL, current_locale[0]) + except locale.Error as error: + console_error( + "Failed to set locale to the current UTF-8-based locale.", + exit=False, + ) + console_error(error) + else: + console_error( + "Please ensure that a UTF-8-based locale is available on your system.", + exit=False, + ) def reverse_multi_index_df_pmc(final_df):