Skip to content

Commit

Permalink
Improve locale detection by checking what locales we have available
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed Oct 12, 2019
1 parent bf446b0 commit 63d8c3d
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions LauncherGtk3/geany/geany/main.m
@@ -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
Expand Down

0 comments on commit 63d8c3d

Please sign in to comment.