Zeb99
Zeb99

Reputation: 103

Issue with importing korean localization text into xcode

I am completing the final part of localizations for a project. The translated text has come back to me split between .txt and .docx formats.

The .txt once entered into the localizable.strings works fine, but that copied from word document doesn't work.

This is what I've tried so far:

Have tried many options to convert to utf-16, but just can't seem to crack it. Any ideas would be much appreciated.

Here is the localized help view implementation:

helpText = [NSArray arrayWithObjects:
                [NSDictionary dictionaryWithObjectsAndKeys:
                 NSLocalizedString(@"    The Actions Tab", nil), kHelpTextKeyString,
                 @"Arial", kHelpTextKeyFontName,
                 [NSNumber numberWithInt:20], kHelpTextKeyFontSize,
                 [[UIColor blackColor] CGColor], kHelpTextKeyColor,
                 CGRectCreateDictionaryRepresentation(CGRectMake(30.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,
                 nil],
                [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSArray arrayWithObjects:
                  NSLocalizedString(@"

- (void)displaySelectedHelpImage:(UIImage *)orgImage withTextArray:(NSArray *)textArr {
CGImageRef cgImage = [orgImage CGImage];
int pixelsWide              = CGImageGetWidth(cgImage);
int pixelsHigh              = CGImageGetHeight(cgImage);
int bitsPerComponent        = CGImageGetBitsPerComponent(cgImage);//8; // fixed
int bitsPerPixel            = CGImageGetBitsPerPixel(cgImage);//bitsPerComponent * numberOfCompnent;
int bytesPerRow             = CGImageGetBytesPerRow(cgImage);//(pixelsWide * bitsPerPixel) // 8; // bytes
int byteCount               = (bytesPerRow * pixelsHigh);
CGColorSpaceRef colorSpace  = CGImageGetColorSpace(cgImage);//CGColorSpaceCreateDeviceRGB();

// Allocate data
NSMutableData *data = [NSMutableData dataWithLength:byteCount];
// Create a bitmap context
CGContextRef context = CGBitmapContextCreate([data mutableBytes], pixelsWide, pixelsHigh, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); //kCGImageAlphaPremultipliedLast);//kCGImageAlphaNoneSkipLast); //kCGImageAlphaOnly);
// Set the blend mode to copy to avoid any alteration of the source data or to invert to invert image
CGContextSetBlendMode(context, kCGBlendModeCopy);
// Set alpha
CGContextSetAlpha(context, 1.0);
// Color image
//CGContextSetRGBFillColor(context, 1 ,1, 1, 1.0);
//CGContextFillRect(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh));
// Draw the image to extract the alpha channel
CGContextDrawImage(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh), cgImage);

// add text to image
// Changes the origin of the user coordinate system in a context
//CGContextTranslateCTM (context, pixelsWide, pixelsHigh);
// Rotate context upright
//CGContextRotateCTM (context, -180. *  M_PI/180);
for (NSDictionary *dic in textArr) {

    CGContextSelectFont (context,
                         //todo
                         [[dic objectForKey:kHelpTextKeyFontName] UTF8String],
                         [[dic objectForKey:kHelpTextKeyFontSize] intValue],
                         kCGEncodingMacRoman);
    CGContextSetCharacterSpacing (context, 2);
    CGContextSetTextDrawingMode (context, kCGTextFillStroke);

    CGColorRef color = (CGColorRef)[dic objectForKey:kHelpTextKeyColor];
    CGRect rect;
    CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[dic objectForKey:kHelpTextKeyRect], &rect);

    CGContextSetFillColorWithColor(context, color);
    CGContextSetStrokeColorWithColor(context, color); 

    if ([[dic objectForKey:kHelpTextKeyString] isKindOfClass:[NSArray class]]) {
        for (NSString *str in [dic objectForKey:kHelpTextKeyString]) {
            CGContextShowTextAtPoint(context,
                                     rect.origin.x,
                                     pixelsHigh - rect.origin.y,
                                     [str cStringUsingEncoding:[NSString defaultCStringEncoding]],
                                     [str length]);
            rect.origin.y += [[dic objectForKey:kHelpTextKeyFontSize] intValue];
        }

Upvotes: 0

Views: 663

Answers (2)

Zeb99
Zeb99

Reputation: 103

For anyone facing this issue, it was solved by using the coretext foundation class.

Upvotes: 1

Clafou
Clafou

Reputation: 15400

What do the Word documents contain? What do you mean by "doesn't work?"

If they contain strings, couldn't you simply append them to the existing localizable.strings file? Since that works there is no encoding issue in this file, you could just copy/paste them from Word into the localizable.strings file in XCode.

Upvotes: 0

Related Questions