0

我正在完成一个项目本地化的最后一部分。翻译后的文本以 .txt 和 .docx 格式返回给我。

.txt 一旦进入localizable.strings工作正常,但从 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];
        }
4

2 回答 2

1

对于遇到此问题的任何人,都可以通过使用 coretext 基础类来解决。

于 2012-03-18T12:33:50.150 回答
0

Word 文档包含哪些内容?“不起作用”是什么意思?

如果它们包含字符串,您不能简单地将它们附加到现有的 localizable.strings 文件中吗?由于该文件有效,因此该文件中没有编码问题,您可以将它们从 Word 复制/粘贴到 XCode 中的 localizable.strings 文件中。

于 2012-03-05T11:27:28.477 回答