仕様なのかバグなのかわからないけど
"VR6-6g-rqx.text" = "翻訳";
みたいなのを頑張って書いても、UITextViewのテキストの値はうまく翻訳されてくれないようだ。
StackOverflow でいくつかワークアラウンドが紹介されている。
以下に自分のとった方法を紹介する。
例えばMain.storyboard上にあるHogeViewController上のFugaTextViewを日本語に翻訳したいとする
1. Main.Storyboard用の翻訳ファイルであるMain.stringsに翻訳を指定
Main.strings(Japanese)
"FUGA_TEXT" = "日本語翻訳";
2. 翻訳が存在すれば読み込むようなユーティリティメソッドを準備
QIUtils.m
+ (UITextView *)applyTranslationToUITextView:(UITextView *)target withKey:(NSString *)key andStoryBoardName:(NSString *)storyBoardName
{
NSString *translation = NSLocalizedStringFromTable(key, storyBoardName, @"");
if (![translation isEqualToString:key]) {
target.text = translation;
}
return target;
}
3. HogeViewControllerのviewDidLoadで翻訳を読み込む
HogeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[QIUtils applyTranslationToUITextView:self.fugaTextView
withKey:@"FUGA_TEXT"
andStoryBoardName:@"Main"];
}