Skip to content

Commit

Permalink
Minor improvement...
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshioka Tsuneo (吉岡 恒夫) committed Sep 22, 2011
1 parent ee5a084 commit 0f86501
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions CamLingual/CamLingualViewController.m
Expand Up @@ -314,7 +314,12 @@ -(void)startTranslate:(NSString*)ocrText
NSLog(@"%s: start", __FUNCTION__);
ocrTextView.text = self.ocrText = ocrText;

[aGoogleTranslateAPI translate:ocrText sourceLang:self.sourceLang destLang:self.destLang delegate:self];
NSString * sourceLang = self.sourceLang;
if([ocrText isEqual:@"No recognized text !"]){
sourceLang = @"ENGLISH";
}

[aGoogleTranslateAPI translate:ocrText sourceLang:sourceLang destLang:self.destLang delegate:self];
// [self showGoogleTranslatePage:ocrText];
destStartLang = self.destLang;
[activityIndicatorView startAnimating];
Expand All @@ -324,9 +329,22 @@ -(void)startTranslate:(NSString*)ocrText
NSLog(@"%s: end", __FUNCTION__);

}
/**
Sometimes, a words is splitted to multiple lines using "-"
*/
- adjustText: (NSString*)text
{
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"(\\p{Latin}\\p{Latin})-(\\p{Latin}\\p{Latin})" options:0 error:nil];
NSString *replaced = [regexp stringByReplacingMatchesInString:text options:0 range:NSMakeRange(0, text.length) withTemplate:@"$1$2"];
NSLog(@"%s: input: %@", __FUNCTION__, text);
NSLog(@"%s: output: %@", __FUNCTION__, replaced);
return replaced;
}

-(void)OCRWebServiceDidFinish:(OCRWebService *)aOCRWebService ocrText:(NSString*)ocrText;
{
[self startTranslate:ocrText];
NSString *adjustText = [self adjustText:ocrText];
[self startTranslate:adjustText];
}


Expand All @@ -343,10 +361,12 @@ - (void)translateProgress:(GoogleTranslateAPI *)aGoogleTranslateAPI message:(NSS
notificationLabel.hidden = NO;
progressView.hidden = NO;
}

- (void)translateDidFinished:(GoogleTranslateAPI *)aGoogleTranslateAPI text:(NSString *)text
{
sourceDoneLang = sourceStartLang;
destDoneLang = destStartLang;

translateTextView.text = self.translateText = text;
notificationLabel.hidden = YES;
progressView.hidden = YES;
Expand Down Expand Up @@ -576,7 +596,6 @@ - (IBAction)openAlbum:(id)sender {
}
}
}

- (void)didFinishOCRTextViewController:(NSString *)text
{
[self startTranslate:text];
Expand Down
1 change: 1 addition & 0 deletions README.txt
Expand Up @@ -7,6 +7,7 @@ Copyright:
License:
You can choose license for this source code from below
- GPL(GNU Public Licnese) version 2 or lator.
(Except the case other license is written in the beginning of source.)
- Other than GPL based on seperate agreement.
If you want to use for other than GPL license, contact me with details for negotiation.
!!!NOTE!!!
Expand Down

0 comments on commit 0f86501

Please sign in to comment.