Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for locale files in main bundle on Android #485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Source/GSLocale.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,16 @@
GSLanguageFromLocale(NSString *locale)
{
NSString *language = nil;
NSString *aliases = nil;
NSBundle *gbundle;
NSDictionary *dict;

if (locale == nil || [locale isEqual: @"C"] || [locale isEqual: @"POSIX"]
|| [locale length] < 2)
return @"English";

ENTER_POOL
gbundle = [NSBundle bundleForLibrary: @"gnustep-base"];
aliases = [gbundle pathForResource: @"Locale"
ofType: @"aliases"
inDirectory: @"Languages"];
if (aliases != nil)
dict = GSPrivateLanguageAliases();
if (dict != nil)
{
NSDictionary *dict;

dict = [NSDictionary dictionaryWithContentsOfFile: aliases];
language = [[dict objectForKey: locale] copy];
if (language == nil && [locale pathExtension] != nil)
{
Expand Down
8 changes: 8 additions & 0 deletions Source/GSPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,5 +646,13 @@ void GSWeakInit() GS_ATTRIB_PRIVATE;
BOOL objc_delete_weak_refs(id obj);
#endif

/**
* Returns an unretained version of the language aliases,
* or nil if the NSBundle class is not initialised.
*
* Implementation in NSBundle.
*/
NSDictionary *GSPrivateLanguageAliases();

#endif /* _GSPrivate_h_ */

11 changes: 11 additions & 0 deletions Source/NSBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
static NSDictionary *langAliases = nil;
static NSDictionary *langCanonical = nil;

NSDictionary *GSPrivateLanguageAliases()
{
return langAliases;
}

/* Map a language name to any alternative versions. This function should
* return an array of alternative language/localisation directory names in
* the preferred order of precedence (ie resources in the directories named
Expand Down Expand Up @@ -1720,8 +1725,14 @@ + (void) initialize
if ((str = [env objectForKey: @"LIBRARY_COMBO"]) != nil)
library_combo = RETAIN(str);

#if defined(__ANDROID__)
// TODO: Improve the overall bundle and domain system for platforms
// without a traditional filesystem hierarchy like Android
_gnustep_bundle = RETAIN([NSBundle mainBundle]);
#else
_gnustep_bundle = RETAIN([self bundleForLibrary: @"gnustep-base"
version: _base_version]);
#endif

/* The Locale aliases map converts canonical names to old-style names
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/NSProcessInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ - (void) performExpiringActivityWithReason: (NSString *)reason
jstring localeListJava = (*env)->CallObjectMethod(env, localeListObj, localeListToLanguageTagsMethod);
GS_JNI_CHECK(env, localeListJava);

const char *localeListOrig = (*env)->GetStringUTFChars(env, localeIdJava, NULL);
const char *localeListOrig = (*env)->GetStringUTFChars(env, localeListJava, NULL);

// Some devices return with it enclosed in []'s so check if both exists before
// removing to ensure it is formatted correctly
Expand Down
Loading