Help us understand the problem. What is going on with this article?

Storyboard上のUITextViewを.stringsでローカライズしたときにテキストが反映されない

More than 5 years have passed since last update.

仕様なのかバグなのかわからないけど

"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"];
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした