Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor code improvements #30

Merged
merged 2 commits into from

2 participants

@chrisridd

There's no real need to handle the case of 0 elements (from the xpath
query) separately. The fast enumeration will just not fill anything in.

The languages method is corrected to return an NSArray.

The tests still run OK.

chrisridd added some commits
@chrisridd chrisridd Clean up methods returning arrays
There's no real need to handle the case of 0 elements (from the xpath
query) separately. The fast enumeration will just not fill anything in.

The languages method is corrected to return an NSArray.

The tests still run OK.
e51ecd7
@chrisridd chrisridd Display language in QL preview
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.
eba1657
@jaketmp jaketmp merged commit 6ee60aa into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 6, 2012
  1. @chrisridd

    Clean up methods returning arrays

    chrisridd authored
    There's no real need to handle the case of 0 elements (from the xpath
    query) separately. The fast enumeration will just not fill anything in.
    
    The languages method is corrected to return an NSArray.
    
    The tests still run OK.
Commits on Apr 11, 2012
  1. @chrisridd

    Display language in QL preview

    chrisridd authored
    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.
This page is out of date. Refresh to see the latest.
View
2  JTPepub/JTPepub.h
@@ -61,6 +61,6 @@ typedef enum {
- (NSString *)isbn;
- (NSString *)drm;
- (NSDate *)expiryDate;
-- (NSMutableArray *)language;
+- (NSArray *)language;
@end
View
28 JTPepub/JTPepub.m
@@ -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,7 +700,7 @@ - (NSArray *)language
return language;
}
- language = [[NSMutableArray alloc] initWithCapacity:1];
+ language = [[NSMutableArray alloc] init];
NSError *xmlError = nil;
@@ -722,12 +708,6 @@ - (NSArray *)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)
{
View
17 epubQL/GeneratePreviewForURL.m
@@ -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"];
View
2  epubQL/en.lproj/Localizable.strings
@@ -20,3 +20,5 @@
"publishers" = "Publishers";
"translator" = "Translator";
"translators" = "Translators";
+"language" = "Language";
+"languages" = "Languages";
Something went wrong with that request. Please try again.