4thSpace
4thSpace

Reputation: 44352

iPhone localization with sqlite?

How is text in a database localized for the iPhone? The examples I've seen have hard coded strings in the .m file or .xib. For example:

NSString firstName = NSLocalizedString(@"First Name", @"This is the first name");

What happens if the strings you need to localize are in the database? I haven't found discussion of this type of localization. However, I imagine it is extremely common given that many iPhone apps use sqlite.

Upvotes: 1

Views: 1333

Answers (2)

Doug
Doug

Reputation:

I was just wondering the same thing and couldn't find any mention of how this was dealt with (and hence how I ended up at this post). OTTOMH, I was thinking that you may just have different databases for each supported language. Perhaps still follow the general internationalization/localization guidelines and create a separate dir for each support language such as en.lproj and it.lproj and the then name your dbs as "en_data.db" and "it_data.db" (or whatever naming convention you prefer) and place them in their respective dirs. The trick is to then detect the runtime language in the app and load the appropriate database for that language. Again, this is all just a guess, I've never done it in practice (like I said, I was wondering the same thing)

Upvotes: 0

Daniel Dickison
Daniel Dickison

Reputation: 21882

NSLocalizedString is simply a preprocessor macro that turns into a call to NSBundle's localizedStringForKey:value:table: -- so basically you can use strings fetched at runtime instead of a hardcoded string and pass that to NSBundle. The downside, of course, is that there's no quick way to compile a list of all the strings that a translator needs to localized.

Example:

NSString *key = fetchKeyFromDB(...);
NSString *localizedString = [[NSBundle mainBundle] localizedStringForKey:key value:@"default string" table:nil];

Upvotes: 2

Related Questions