任意の言語に対して複数の文字列テーブル (つまり、複数の.strings
ファイル) を持つことができます。ローカライズされた文字列が必要な場合は、次の方法で取得できます。
NSString *str;
// Look up string in Full.strings
str = [[NSBundle mainBundle] localizedStringForKey:@"SomeKey"
value:@"DefaultValue"
table:@"Full"];
// Look up strings in Lite.strings
str = [[NSBundle mainBundle] localizedStringForKey:@"SomeKey"
value:@"DefaultValue"
table:@"Lite"];
このメソッドのテーブルは変数にできるため、実行時に切り替えることもできます。上記は、Full.strings
テーブルとテーブルがあることを前提としていLite.strings
ます。
Full.strings
"SomeKey" = "This string appears in the full version";
Lite.strings
"SomeKey" = "This string appears in the lite version";
それらを一緒に出荷したくない場合があります。その場合は、Info.plist を構成して、特定のターゲットに使用するテーブルの名前を含めることができます ( というエントリを追加すると"TableToUse"
、 経由で取得できます[[[NSBundle mainBundle] infoDictionary] objectForKey:@"TableToUse"]
) 。