2012-03-04 51 views
0

我正在完成項目本地化的最後部分。翻譯後的文本已經回到了我的分割.txt和.docx格式之間。將韓文本地化文本導入到xcode中的問題

一旦進入localizable.strings的.txt文件工作正常,但是從Word文檔複製的文件不起作用。

這是我到目前爲止已經試過:

  • .DOCX另存爲.txt和讓字編碼
  • .TXT保存爲韓國鍵(Mac OS X),然後 這個文本複製到Xcode和重新解釋爲朝鮮鍵(Mac OS X),然後 轉換爲UTF-16

已經嘗試了許多選項來轉換爲UTF-16,但似乎就是無法破解它。 任何想法將不勝感激。

這裏是本地化的幫助視圖實現:

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]; 
     } 

回答

0

什麼Word文檔包含哪些內容?你是什​​麼意思「不起作用?」

如果它們包含字符串,難道你不能簡單地將它們追加到現有的localizable.strings文件?由於該工作原理在該文件中沒有編碼問題,因此您可以將它們從Word複製/粘貼到XCode中的localizable.strings文件中。

+0

感謝您的回覆。是的,這就是我一直在嘗試的。我從此發現它與單詞無關。它的自定義視圖有顯示非西方字符的問題。 – Zeb99 2012-03-06 15:34:10

+0

我會在這裏發佈解決方案,以防其他人偶然遇到此問題.. – Zeb99 2012-03-06 15:34:33

+0

我將韓文文本轉換爲UTF-16,但並未解決問題。本地化的幫助屏幕是由我以外的人開發的。它們顯示的方式似乎是導致非西方字符的問題: – Zeb99 2012-03-11 17:39:36

1

對於任何面臨這個問題的人來說,它是通過使用coretext基礎類來解決的。