From 9a031eea079ba9b8f910d9c664db0ca283a576e0 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 6 Aug 2025 13:00:10 +0800 Subject: [PATCH] Set the locale on app startup. --- .../{{ cookiecutter.class_name }}/main.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m b/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m index c3cf9e5..2ffff79 100644 --- a/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m +++ b/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m @@ -38,6 +38,10 @@ int main(int argc, char *argv[]) { PyObject *systemExit_code; @autoreleasepool { + // iOS doesn't export an LANG environment variable; that variable is + // needed to set the locale correctly on startup. + setenv("LANG", [[NSString stringWithFormat:@"%@.UTF-8", NSLocale.currentLocale.localeIdentifier] UTF8String], 1); + NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; // Generate an isolated Python configuration. @@ -49,6 +53,8 @@ int main(int argc, char *argv[]) { // Enforce UTF-8 encoding for stderr, stdout, file-system encoding and locale. // See https://docs.python.org/3/library/os.html#python-utf-8-mode. preconfig.utf8_mode = 1; + // Ensure the locale is set (isolated interpreters won't by default) + preconfig.configure_locale = 1; // Don't buffer stdio. We want output to appears in the log immediately config.buffered_stdio = 0; // Don't write bytecode; we can't modify the app bundle