Permalink
Browse files

Merge pull request #30 from chrisridd/master

Minor code improvements
  • Loading branch information...
2 parents 671f935 + eba1657 commit 6ee60aa1b07230e916046c04b989a6790e8f4b1e @jaketmp jaketmp committed Apr 23, 2012
Showing with 21 additions and 28 deletions.
  1. +1 −1 JTPepub/JTPepub.h
  2. +2 −26 JTPepub/JTPepub.m
  3. +16 −1 epubQL/GeneratePreviewForURL.m
  4. +2 −0 epubQL/en.lproj/Localizable.strings
View
@@ -61,6 +61,6 @@ typedef enum {
- (NSString *)isbn;
- (NSString *)drm;
- (NSDate *)expiryDate;
-- (NSMutableArray *)language;
+- (NSArray *)language;
@end
View
@@ -300,11 +300,6 @@ - (NSArray *)creatorsWithOPFRole:(NSString *)role
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:creator>s found
- return [NSArray array];
- }
NSMutableArray *results = [NSMutableArray array];
// Fast enumerate over meta elements
for(id item in metaElements)
@@ -340,11 +335,6 @@ - (NSArray *)contributorsWithOPFRole:(NSString *)role
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:contributor>s found
- return [NSArray array];
- }
NSMutableArray *results = [NSMutableArray array];
// Fast enumerate over meta elements
for (id item in metaElements)
@@ -570,11 +560,6 @@ - (NSDate *)publicationDate
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:date>s found
- return nil;
- }
// Find the date of publication.
// Fast enumerate over meta elements
for(id item in metaElements)
@@ -705,6 +690,7 @@ - (NSDate *)expiryDate
(void)[self drm];
return expiryDate;
}
+
/*
* Return an array of RFC5646 languange identifiers.
*/
@@ -714,20 +700,14 @@ - (NSArray *)language
return language;
}
- language = [[NSMutableArray alloc] initWithCapacity:1];
+ language = [[NSMutableArray alloc] init];
NSError *xmlError = nil;
NSArray *metaElements = [opfXML nodesForXPath:@"//dc:language"
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:language>s found - we should never get here in a valid epub!
- return language;
- }
-
// Enumerate over the elements we found.
for(id item in metaElements)
{
@@ -744,10 +724,6 @@ - (NSArray *)language
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- return language;
- }
// Enumerate over the elements we found.
for(id item in metaElements)
{
@@ -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];
@@ -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"];
@@ -20,3 +20,5 @@
"publishers" = "Publishers";
"translator" = "Translator";
"translators" = "Translators";
+"language" = "Language";
+"languages" = "Languages";

0 comments on commit 6ee60aa

Please sign in to comment.