i need a multilingual coredata db in my iphone app. I could create different database for each language but i hope that in iphone sdk exist an automatically way to manage data in different language core data like for resources and string.
Someone have some hints?
I’ve done something similar to Shortseller, but without the use of categories.
InternationalBookandLocalizedBookare both custom managed objects with a one-to-many relationship (one international book to many localised books).In the implementation of
InternationalBook, I’ve added a custom accessor fortitle:[DataManager localeString]is a class method which returns the user’s language and country code:en_US,fr_FR, etc. See documentation onNSLocalefor details.See the “Custom Attribute and To-One Relationship Accessor Methods” section of the Core Data Programming Guide for an explanation of
willAccessValueForKey:anddidAccessValueForKey:.When populating the data, I grab a string representing the user’s current locale (
[DataManager localeString]), and store that along the with localised book title in a newLocalizedBookobject. EachLocalizedBookinstance is added to anNSMutableSet, which represents the one-to-many relationship.Since the localised titles are being stored in the
LocalizedBookmanaged object, you can make thetitleattribute a transient, but if you do that you can’t usetitlein a predicate.The nice thing about this approach is that the implementation of the to-many relationship is transparent to any consumers. You simply request
internationalBook.titleand the custom accessor returns the appropriate value based on the user’s locale behind the scenes.