Skip to content

Commit

Permalink
set LC_CTYPE to en_US.UTF-8 if it is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Aug 20, 2023
1 parent f306829 commit 60ccb0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion radian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,16 @@ def run(self, options, cleanup=None):
# enable signal handlers
os.environ["RCHITECT_REGISTER_SIGNAL_HANDLERS"] = "1"

if sys.platform.startswith("win"):
# avoid "using locale code page other than 1252 may cause problems" warning
lc_ctype = os.environ.pop('LC_CTYPE', "en_US.UTF-8")
else:
lc_ctype = None

rchitect.init(args=args, register_signal_handlers=True)

rutils.set_lang()
if sys.platform.startswith("win"):
rutils.set_locale(lc_ctype = lc_ctype)

try:
rutils.source_radian_profile(options.profile)
Expand Down
4 changes: 3 additions & 1 deletion radian/rutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ def register_cleanup(cleanup):
onexit=True)


def set_lang():
def set_locale(lc_ctype):
if sys.platform.startswith("win"):
if not os.environ.get("LANG", ""):
if rcopy(reval(
'compareVersion(paste0(R.version$major, ".", R.version$minor), "4.2.0") >= 0')):
os.environ["LANG"] = "en_US.UTF-8"
if lc_ctype:
reval("suppressWarnings(Sys.setlocale(locale = '{}'))".format(lc_ctype))


def run_on_load_hooks():
Expand Down

0 comments on commit 60ccb0a

Please sign in to comment.