0

Apologies if this has already been asked, but some google search could not find it.

Does anyone please know of any method to generate a random string in iOS which respects the current language of the device?

The idea is that a quick 'unlock code' can be generated using the function; the trouble is that for languages other than English entering the code using the keypad will not be quick or intuitive, particularly if the user does not have the English keyboard enabled.

questions
  • 115
  • 1
  • 12
  • Emoji seem to be international albeit rather clumsy. – zaph Mar 28 '15 at 15:06
  • Ha, nice thought! Are they unicode- i.e. do you know please if I could use them in string comparison? – questions Mar 28 '15 at 15:20
  • @Zaph but not everyone enables the Emoji keyboard. – rmaddy Mar 28 '15 at 15:47
  • Just use the digits 0-9 and show the standard number pad. – rmaddy Mar 28 '15 at 15:49
  • Of course.. that makes a lot of sense. Could you please put it as an answer and I'll accept it. – questions Mar 28 '15 at 15:50
  • @rmaddy I was half joking about emoji, digits are good but I have concerns about Chinese and Arabic, Japanese should be OK. Arabic is interesting since we are using Arabic Numerals but there are Arabic number glyphs. Emoji seem to be universal and one does not need to be literate (yeah, this is for a computer. ;-) The main issue presented here are the general restrictions on password characters, they are in general, to restrictive for international usage. – zaph Mar 28 '15 at 19:06

1 Answers1

0

One easy option would be to generate your string using just the digits 0-9. Then present the standard number pad.

However, you should verify that the standard number pad actually shows the digits 0-9 for all locales. Good ones to verify would be Arabic, Chinese, and Japanese locales, I don't recall for sure what shows in those cases.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks. In fact, I've deliberately kept the 'unlock' code in "English" digits, and then generate a localised version for display: `NSDecimalNumber *someNumber = [NSDecimalNumber decimalNumberWithString:code]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; NSString * localKey = [formatter stringFromNumber:someNumber]; // Prints in Current Locale - english version is saved as object property [e setLocalisedKey:localKey];` From here: http://stackoverflow.com/questions/11670330/how-to-display-arabic-numbers-inside-iphone-apps-without-localizing-each-digit – questions Mar 28 '15 at 17:52