Skip to content

Commit

Permalink
Support relative path for ICU_DAT_FILE_PATH on iOS/tvOS/Catalyst (#87813
Browse files Browse the repository at this point in the history
)

We consider it relative to the app bundle root.

Required for xamarin/xamarin-macios#17877 and NativeAOT scenarios.
  • Loading branch information
akoeplinger authored Jun 20, 2023
1 parent af18709 commit f450f49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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

0 comments on commit f450f49

Please sign in to comment.