Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sat, 12 Oct 2019 13:26:49 UTC Commit: 63d8c3deab74dc960994d6f5a55cb16b86afe058 https://github.com/geany/geany-osx/commit/63d8c3deab74dc960994d6f5a55cb16b86...
Log Message: ----------- Improve locale detection by checking what locales we have available
Modified Paths: -------------- LauncherGtk3/geany/geany/main.m
Modified: LauncherGtk3/geany/geany/main.m 50 lines changed, 43 insertions(+), 7 deletions(-) =================================================================== @@ -1,23 +1,59 @@ #import <Foundation/Foundation.h>
+NSString *get_locale(NSString *bundle_data) +{ + NSString *fallback = @"en_US.UTF-8"; + + BOOL ignore_locale = [[NSFileManager defaultManager] fileExistsAtPath: [@"~/.config/geany/ignore_locale" stringByExpandingTildeInPath]]; + if (ignore_locale) + { + return fallback; + } + + NSArray<NSString *> *langs = [NSLocale preferredLanguages]; + for (NSString *lng in langs) + { + BOOL found = NO; + NSString *lang; + NSArray<NSString *> *comps = [lng componentsSeparatedByString:@"-"]; + if (comps.count > 1) + { + lang = [NSString stringWithFormat:@"%@_%@", comps[0], comps[1]]; + NSString *path = [NSString stringWithFormat:@"%@/locale/%@", bundle_data, lang]; + found = [[NSFileManager defaultManager] fileExistsAtPath:path]; + } + if (!found && comps.count > 0) + { + NSString *lng = comps[0]; + NSString *path = [NSString stringWithFormat:@"%@/locale/%@", bundle_data, lng]; + found = [[NSFileManager defaultManager] fileExistsAtPath:path]; + if (found && comps.count == 1) + { + lang = lng; + } + } + if (found) + { + return [lang stringByAppendingString:@".UTF-8"]; + } + } + + return fallback; +} + + int run_geany() { NSString *bundle_dir = [[NSBundle mainBundle] bundlePath];
NSString *bundle_contents = [bundle_dir stringByAppendingPathComponent: @"Contents"]; NSString *bundle_res = [bundle_contents stringByAppendingPathComponent: @"Resources"]; NSString *bundle_lib = [bundle_res stringByAppendingPathComponent: @"lib"]; - //NSString *bundle_bin = [bundle_res stringByAppendingPathComponent: @"bin"]; NSString *bundle_data = [bundle_res stringByAppendingPathComponent: @"share"]; NSString *bundle_etc = [bundle_res stringByAppendingPathComponent: @"etc"];
- NSString *lang = @"en_US.UTF-8"; - bool ignore_locale = [[NSFileManager defaultManager] fileExistsAtPath: [@"~/.config/geany/ignore_locale" stringByExpandingTildeInPath]]; - if (!ignore_locale) - { - lang = [[[NSLocale currentLocale] localeIdentifier] stringByAppendingString:@".UTF-8"]; - } + NSString *lang = get_locale(bundle_data);
//set environment variables //see https://developer.gnome.org/gtk3/stable/gtk-running.html
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).