必要な言語で plist ファイルを作成します。すべてのローカライズされた文字列のデフォルトとして {LANG}_{CLASS NAME} と {CLASS NAME} を使用します。その後、適切なファイルが存在するかどうかをチェックするメソッドを作成し、欠落している場合はそれを取得し、デバイス言語に応じて NSDictionary オブジェクトを返し、クラス init で呼び出します。nib 名を文字列ファイルに追加してローカライズされた nib を実装する場合、この考え方も使用できます。
+ (NSDictionary *) getLocalized: (NSString *) contollerName andLang:(NSString *) lang {
NSString *fullPath = nil;
// You can use device lang if needed
NSString * curLang=[[NSLocale preferredLanguages] objectAtIndex:0];
fullPath = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat:@"%@_%@",contollerName,lang] ofType: @"plist"];
if (!fullPath) {
fullPath = [[NSBundle mainBundle] pathForResource:contollerName ofType:@"plist"];
}
return [NSDictionary dictionaryWithContentsOfFile:fullPath];
}
したがって、次のような方法で呼び出すことができます。
[tools getLocalized:[Controller.class description] andLang:@"XX"];