开发者

How to deliver a multilingual FAQ within an app?

I want to ship my app with a built-in FAQ on the settings page. The FAQ is simple:

1) We have a table view which lists all the questions. One per cell.

2) When the user taps one of those questions, we slide over to a detail view controller which shows the question in bold letters and then the answer. Very simple.

The hard part: What would be the optimal way to feed the table view 开发者_Python百科and detail view controller with the strings?

Bad ideas (from my point of view):

  • Hardcode all strings and work with giant if or switch monsters.

  • Rely on NSLocalizedString() to fetch the localized version of an answer. Those strings files don't look like they were intended for very large strings. Just for a few sentences or words per line. With tons of FAQ text those strings files would become horrifying.

This is how I'd attempt to do it, but you may suggest a better way:

Solution 1)

  • Create an JSON file where entities have three fields: ID, Question and Answer. ID will help us track down which Answer we have to load after the user tapped a cell.

  • Localize that JSON file.

  • When the table view loads, read it into memory and parse it, just to read out the questions and ID's (yes, less than ideal, right?)

  • When the user taps a cell, either pass the ID just to re-fetch the whole thing again, or maybe better: Pass the ID, question and answer strings to the details view controller.

Solution 2)

Like 1, but use Core Data instead. Probably better for memory and performance, but probably harder to maintain (must mess around with a SQLite3 file to build the FAQ, needs at least a good IDE to do that to not go crazy). Caveat: Can't pass it to translators easily. Tons of manual work just to create that SQLite3 file. Files localized in localization folders.

Solution 4)

Two splitted JSON files: One with all the ID's and Questions. Another with all the ID's and Answers. Files localized in localization folders.

Solution 5)

An JSON file with all the IDs and Questions. For every ID, there's a matching Answer text file. So we don't end up loading tons of data into memory just to extract some tiny fraction of it.

Solution 6)

Use something that already exists, or a different approach. Suggestions?


Normally, you would localize a localizedStrings-file, so that they can get translated when you run NSLocalizedString. What you may not know is that this basically works for all kinds of files, so plists too:

  1. Create a localized faq plist-file.
  2. Request it (from in the app) with [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"faq" ofType:@"plist"]];
  3. Implement it in your UITableView. (- (NSInteger)numberOf... => return [faq count];).

Oh, and I use a plist-file instead of JSON or XML since Apple uses it, since it's really easy to implement (NSArray - arrayWithContentsOfFile is built in) and you can maintain it very easily in Xcode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜