Skip to content

Commit a812255

Browse files
authored
Set the locale on app startup. (#58)
1 parent 813ceef commit a812255

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • {{ cookiecutter.format }}/{{ cookiecutter.class_name }}

{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ int main(int argc, char *argv[]) {
3838
PyObject *systemExit_code;
3939

4040
@autoreleasepool {
41+
// iOS doesn't export an LANG environment variable; that variable is
42+
// needed to set the locale correctly on startup.
43+
setenv("LANG", [[NSString stringWithFormat:@"%@.UTF-8", NSLocale.currentLocale.localeIdentifier] UTF8String], 1);
44+
4145
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
4246

4347
// Generate an isolated Python configuration.
@@ -49,6 +53,8 @@ int main(int argc, char *argv[]) {
4953
// Enforce UTF-8 encoding for stderr, stdout, file-system encoding and locale.
5054
// See https://docs.python.org/3/library/os.html#python-utf-8-mode.
5155
preconfig.utf8_mode = 1;
56+
// Ensure the locale is set (isolated interpreters won't by default)
57+
preconfig.configure_locale = 1;
5258
// Don't buffer stdio. We want output to appears in the log immediately
5359
config.buffered_stdio = 0;
5460
// Don't write bytecode; we can't modify the app bundle

0 commit comments

Comments
 (0)