From 0f8650123d5deb5874c600c6e31023aa1dd90ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoshioka=20Tsuneo=20=28=E5=90=89=E5=B2=A1=20=E6=81=92?= =?UTF-8?q?=E5=A4=AB=29?= Date: Thu, 22 Sep 2011 17:13:31 +0300 Subject: [PATCH] Minor improvement... --- CamLingual/CamLingualViewController.m | 25 ++++++++++++++++++++++--- README.txt | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CamLingual/CamLingualViewController.m b/CamLingual/CamLingualViewController.m index 58acfca..4b6e81d 100644 --- a/CamLingual/CamLingualViewController.m +++ b/CamLingual/CamLingualViewController.m @@ -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]; @@ -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]; } @@ -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; @@ -576,7 +596,6 @@ - (IBAction)openAlbum:(id)sender { } } } - - (void)didFinishOCRTextViewController:(NSString *)text { [self startTranslate:text]; diff --git a/README.txt b/README.txt index 5c6cea9..5b0c20d 100644 --- a/README.txt +++ b/README.txt @@ -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!!!