ReactNative iOSパーミッションテキストのローカライズ方法


パーミッションリクエスト時のテキストを端末の言語に合わせて変更するときの設定について。

バージョン

ReactNative 0.63.3
Xcode 12.4

Info.plistにパーミッションを追加

アプリ内でカメラを使用するためにPrivacy - Camera Usage Descriptionがあるとして、このテキストをローカライズしたいとします。

PROJECTからLocalizationsで多言語化したい言語を追加する

まずLocalizationsから多言語化したい言語を追加します。今回は例として英語と中国語(簡体字)を追加しています。

InfoPlist.stringsファイルを作成する。



Infoplist.stringsとかLocalizable.stringsとかに名前を変えると反映されないので注意。ドキュメントにちゃんと書いてありました。

The values for many keys in an information property list file are human-readable strings that are displayed to the user by the Finder or your own app. When you localize your app, you should be sure to localize the values for these strings in addition to the rest of your app’s content.
Localized values are not stored in the Info.plist file itself. Instead, you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization. The contents of the InfoPlist.strings file are the individual keys you want localized and the appropriately translated value. The routines that look up key values in the Info.plist file take the user’s language preferences into account and return the localized version of the key (from the appropriate InfoPlist.strings file) when one exists. If a localized version of a key does not exist, the routines return the value stored in the Info.plist file.
About Information Property List Files

作成したInfoPlist.stringsをLocalizeして多言語化する

Xcodeの右側のカラムからLocalizeボタンを押して追加した言語を選択します。


en.lprojzh-Hans.lprojのように言語ごとにディレクトリが作成され、ディレクトリ内にInfoPlist.stringsが作成されているはずです。

以下のようにInfoPlist.stringsごとに言語ごとにパーミッションテキストで表示したいテキストを設定します。

"NSCameraUsageDescription" = "告诉用户为什么应用会请求访问设备的摄像头的信息。";

シミュレータで言語を変更して確認すると設定したテキストが表示されるはずです。

プッシュ通知パーミッションのローカライズ

プッシュ通知のパーミッションテキストは変更できないため端末の言語によって自動で切り替わる。
シミュレータだと言語を変更してもプッシュ通知のパーミッションダイアログ内のテキストは英語で表示されるため実機で確認すること。

Androidは?

Androidはパーミッションメッセージを変更できない。

注: launch() を呼び出したときに表示されるダイアログをアプリでカスタマイズすることはできません。ユーザーに詳細な情報やコンテキストを提供するには、アプリの UI を変更して、アプリの機能に特定の権限が必要な理由をユーザーにわかりやすく説明します。たとえば、機能を有効にするボタンのテキストを変更します。
Request app permissions | Android Developers

参考

Requesting Permission - App Architecture - iOS - Human Interface Guidelines - Apple Developer
Protected Resources - Apple Developer
インターナショナライゼーションとローカリゼーションのガイド
Handle Localization for iOS Native Messages
iOS10から必要になったユーザデータにアクセスする為に表示する文言をローカライズする