0

How do I know if a language NSLocale uses spaces for delimiting words in a sentence (like English or other roman languages) or not (like Japanese)?

I expected to find this information under NSLocale Component Keys … no. Any idea? Do I really need to set my own dictionary for this. I'd appreciate any advice or related resource.

Bernd
  • 11,133
  • 11
  • 65
  • 98

2 Answers2

0

You can use NSLocal Components keys' NSLocaleExemplarCharacterSet to get the set of character in that language and then see if space is part of that language character set

NSLocale *jpLocale = [[NSLocal alloc] initWithLocalDentifier: @"ja_JP"];

NSCharacterSet *jpCharSet = (NSCharacterSet *)[jpLocale objectForKey: NSLocaleExemplarCharacterSet]; 

[jpCharSet characterIsMember: ' '] ? NSLog("Yeah it uses space"); : NSLog("Nope"); 
Ch0k0l8
  • 827
  • 6
  • 14
0

I still haven't found a great solution. As a workaround I am checking for spaces in fullStyle strings from a random date using the NSDateFormatter

NSDate* exampleDate = [NSDate dateWithTimeIntervalSince1970:0];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.locale = [NSLocale currentLocale];
dateFormatter.dateStyle = NSDateFormatterFullStyle;
NSString *testString = [dateFormatter stringFromDate:exampleDate];

BOOL localeLikelyUsesSpaceAsDelimitters = [testString rangeOfString:@" "].location == NSNotFound;

Better ideas?

Bernd
  • 11,133
  • 11
  • 65
  • 98