3

I'm trying to get a localized index like Contacts by using UILocalizedIndexedCollation. In Contacts when I change the language the index changes to match the language. However sectionIndexTitles always returns an english index.

I have tried this with a demo app I created and with 3_SimpleIndexedTableView, which is a demo app from Apple and neither app have a localized index.

I have tried creating a localization folder for the current locale (I used [[NSLocale autoupdatingCurrentLocale] localeIdentifier] to determine the current locale). This does not affect the index.

I've had a look for relevant plist settings by found nothing.

Am I missing something or does UILocalizedIndexedCollation only return an English collation?

Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67

2 Answers2

8

You can also set Localized resources can be mixed = YES in Info.plist. If the key is missing right click and choose Add Row.

axel22
  • 32,045
  • 9
  • 125
  • 137
emreberge
  • 621
  • 1
  • 5
  • 5
  • This worked perfect for me. I don't have Swedish localization in my app, but I still generate a localized section header and index based on the data provided by the user. Now if I could only find a similar UILocalizedIndexedCollation for Mac! – Tap Forms Oct 28 '15 at 00:18
2

Solved!

I didn't have a localization folder in my app bundle for the target language. I added sv.lproj (Swedish) and the collation worked as expected. The folder is empty, it's presence is all that's required for it to work.

Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
  • I'm having the exact same problem, but I don't follow your solution. Please elaborate. :-) – MdaG Jun 14 '11 at 13:53
  • @MdaG An app is considered localized if there's a folder for the localization in the app bundle. Xcode creates the localization folders automatically when a bundle resource (e.g. a nib, image or a .strings file) is localized. (It's possible to manually create these folders within the app bundle too. I created them manually when I was playing with `UILocalizedIndexedCollation` in the simulator). – Benedict Cohen Jun 17 '11 at 16:17
  • Are you saying that if I create sv.lproj in parallel to en.lproj, my app will automatically detect my locale (Swedish) and make sure the section list returns an array containing A - Ö ? (tested it and it doesn't seem to work like that) If I figure out how it works I'm gonna write a tutorial for n00bs like me. :-) – MdaG Jun 20 '11 at 14:51
  • @MdaG did u come up with a solution. This one doesnt work for me either :( – Bushra Shahid Dec 15 '11 at 09:21
  • I had forgotten all about this Stack Question. Thanks for reminding me. What I did was localize my application for the relevant languages. I.e. create and localize Localization.strings (using genstrings) in my case, but as far as I see you could just localize an image in your application and the relevant folders that @BenedictCohen mention will be created. You can use the Interface Builder to localize an image view. – MdaG Dec 15 '11 at 11:07