views:

262

answers:

1

If I want to create a entity in Core Data that has attributes with values that should be localizable I'm wondering how the most efficient way would look like?

As a example let's assume the following structure:

Book
    name (localizable)
    description (localizable)
    author

An localized book entry would look like this:

name:   "A great novel" (en/international),
        "Ein großartiger Roman" (de), 
        "Un grand roman" (fr)

description:
        "Great!" (en/international),
        "Großartig!" (de), 
        "Grand!" (fr)

author: "John Smith"

In a SQL/SQLite implementation I would use two tables. A books table containing the book information (author, the english/international name and description) and the localizationBooks table that is related using the primary key of the corresponding book. This second table contains the localized name and description values as well as the languageCode. This would allow to have a scalable number of localizations.

For fetching the data I would use a

SELECT COALESCE(localizationBooks.name, books.name)

to get the actual values for the given language code. This allows to use the international english value as fallback for unsupported languages.

Would this require a separate entity in Core Data (e.g. BookLocalization) that has a relation to the Book or is there another recommended way of doing this?

+4  A: 
iKenndac