IOS上對於字符串,提供能國際化支持,可以用NSLocalizedString來實現國際化,但是對於圖片,聲音等文件,就需要我們自己來控制了。下面IOS上多種語言資源文件加載的一種解決方案,如果大家有什麼更好的想法,歡迎留言告知。
[cpp]
//
//
// ResManager.h
//
// Created by 周海鋒 on 12-4-16.
// Copyright (c) 2012年 CJLU. All rights reserved.
//
#import <foundation h="" foundation="">
#import <uikit h="" uikit="">
typedef enum {
Chinese,
English,
Tradition,
}Language;
@interface ResManager : NSObject
{
Language language;
}
@property (nonatomic,assign) Language language;
+(ResManager *)ShareManager;
-(UIImage *) LoadImage:(NSString *) img;
@end
</uikit></foundation>
[cpp]
//
// ResManager.m
//
// Created by 周海鋒 on 12-4-16.
// Copyright (c) 2012年 CJLU. All rights reserved.
//
#import "ResManager.h"
@implementation ResManager
@synthesize language;
static ResManager * resManger = nil;
+(ResManager *)ShareManager
{
@synchronized(self) {
if (resManger == nil) {
resManger = [[self alloc] init];
}
}
return resManger;
}
//唯一一次alloc單例,之後均返回nil
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (resManger == nil) {
resManger = [super allocWithZone:zone];
return resManger;
}
}
return nil;
}
//copy返回單例本身
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
-(id) init
{
if (self = [super init]) {
language = Chinese;
}
return self;
}
-(UIImage *) LoadImage:(NSString *) name
{
switch (language) {
case Chinese:
name = [name stringByAppendingString:@"_c.png"];
break;
case English:
name = [name stringByAppendingString:@"_e.png"];
break;
case Tradition:
name = [name stringByAppendingString:@"_t.png"];
break;
default:
break;
}
UIImage *image = [UIImage imageNamed:name];
return image;
}
@end