Skip to content

Commit

Permalink
Display language in QL preview
Browse files Browse the repository at this point in the history
The trick is how to get localized names for the language tags! The
NSLocale class can be initialized with one of the tags and can return
the localized value of the name.

Hopefully that means a book in "de" will be displayed as "German" for
an English user, and "Deutsch" for a German user.
  • Loading branch information
chrisridd committed Apr 11, 2012
1 parent e51ecd7 commit eba1657
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion epubQL/GeneratePreviewForURL.m
Expand Up @@ -115,7 +115,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,

/*
* Other metadata goes into a table
* TODO: localise labels
* TODO: avoid such intimate knowledge of the HTML
*/
NSMutableString *metadata = [NSMutableString string];
Expand Down Expand Up @@ -189,6 +188,22 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
table:nil],
[formatter stringFromDate:[epubFile expiryDate]]];
}
if ([[epubFile language] count] > 0) {
NSMutableArray *langs = [NSMutableArray array];
for (id l in [epubFile language]) {
NSLocale *loc = [[NSLocale alloc] initWithLocaleIdentifier:l];
[langs addObject:[loc displayNameForKey:NSLocaleIdentifier value:l]];
[loc release];
}
[metadata appendFormat:@"<tr><th>%@:</th><td>%@</td></tr>\n",
[[epubFile language] count] > 1 ? [pluginBundle localizedStringForKey:@"languages"
value:@"languages"
table:nil] :
[pluginBundle localizedStringForKey:@"language"
value:@"language"
table:nil],
[langs escapedComponentsJoinedByString:@", "]];
}
if (![metadata isEqualToString:@""]) {
[metadata insertString:@"<table>\n" atIndex:0];
[metadata appendString:@"</table>\n"];
Expand Down
2 changes: 2 additions & 0 deletions epubQL/en.lproj/Localizable.strings
Expand Up @@ -20,3 +20,5 @@
"publishers" = "Publishers";
"translator" = "Translator";
"translators" = "Translators";
"language" = "Language";
"languages" = "Languages";

0 comments on commit eba1657

Please sign in to comment.