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

Support relative path for ICU_DAT_FILE_PATH on iOS/tvOS/Catalyst #87813

Merged
merged 1 commit into from
Jun 20, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ FOR_ALL_ICU_FUNCTIONS
#define ucal_getTimeZoneIDForWindowsID_ptr ucal_getTimeZoneIDForWindowsID

#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path);
const char* GlobalizationNative_GetICUDataPathFallback(void);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ int32_t
GlobalizationNative_LoadICUData(const char* path)
{
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
if (path && path[0] != '/')
{
// if the path is relative, prepend the app bundle root
path = GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(path);
}
if (!path)
{
// fallback to icudt.dat in the app bundle root in case the path isn't set
// fallback to icudt.dat in the app bundle resources in case the path isn't set
path = GlobalizationNative_GetICUDataPathFallback();
}
#endif
Expand Down
14 changes: 11 additions & 3 deletions src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import <Foundation/NSFormatter.h>

char* DetectDefaultAppleLocaleName()
char* DetectDefaultAppleLocaleName(void)
{
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";
Expand Down Expand Up @@ -571,9 +571,17 @@ Returns time format information (in native format, it needs to be converted to .
#endif

#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path)
{
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]];

return strdup([dataPath UTF8String]);
}

const char* GlobalizationNative_GetICUDataPathFallback(void)
{
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"];
return strdup([bundlePath UTF8String]);
NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"];
return strdup([dataPath UTF8String]);
}
#endif