Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve node parser for accent texts #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions MSTranslateVendor/MSTranslateVendor.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ @implementation MSTranslateVendor
REQUEST_BREAKSENTENCE_TAG
}ParserTag;

#pragma mark - Class properties
NSMutableString *nodeValue;

#pragma mark - C functions

NSString * generateSchema(NSString *);
Expand Down Expand Up @@ -384,14 +387,15 @@ - (void)parserDidEndDocument:(NSXMLParser *)parser
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
_elementString = [elementName copy];
nodeValue = [[NSMutableString alloc] init];
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(parser.tag == REQUEST_TRANSLATE_TAG)
{
if([_elementString isEqualToString:@"string"])
[[NSNotificationCenter defaultCenter] postNotificationName:kRequestTranslate object:@{@"result" : string, @"isSuccessful": @YES}];
[nodeValue appendString:string];
else if([_elementString isEqualToString:@"h1"])
{
if([string isEqualToString:@"Argument Exception"])
Expand Down Expand Up @@ -420,13 +424,13 @@ - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if([_elementString isEqualToString:@"TranslatedText"])
{
[_translatedArray addObject:string];
[nodeValue appendString:string];
}
}
else if(parser.tag == REQUEST_DETECT_TEXT_TAG)
{
if([_elementString isEqualToString:@"string"])
[[NSNotificationCenter defaultCenter] postNotificationName:kRequestDetectLanguage object:@{@"result" : string, @"isSuccessful": @YES}];
[nodeValue appendString:string];
else if([_elementString isEqualToString:@"h1"])
{
if([string isEqualToString:@"Argument Exception"])
Expand Down Expand Up @@ -461,4 +465,22 @@ - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
}
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(parser.tag == REQUEST_TRANSLATE_TAG)
{
[[NSNotificationCenter defaultCenter] postNotificationName:kRequestTranslate object:@{@"result" : nodeValue, @"isSuccessful": @YES}];
}
else if(parser.tag == REQUEST_DETECT_TEXT_TAG)
{
[[NSNotificationCenter defaultCenter] postNotificationName:kRequestDetectLanguage object:@{@"result" : nodeValue, @"isSuccessful": @YES}];
}
else if(parser.tag == REQUEST_TRANSLATE_ARRAY_TAG)
{
if([_elementString isEqualToString:@"TranslatedText"]) {
[_translatedArray addObject:nodeValue];
}
}
}

@end