// 該当のメッセージを出しているBundleを取得
guard let bundle = Bundle(path: "/System/Library/PrivateFrameworks/TCC.framework") else {
return
}
// Bundleに含まれる各言語を取得
for localization in bundle.localizations {
print("===== \(localization)")
// 各言語のLocalizable.stringsファイルのパスを取得
let fileUrl = bundle.url(
forResource: "Localizable",
withExtension: "strings",
subdirectory: nil,
localization: localization
)
guard let fileUrl = fileUrl, let data = try? Data(contentsOf: fileUrl) else {
continue
}
// Localizable.stringsをプロパティリストからDictionaryにして
// 読みやすく出力
let decoder = PropertyListDecoder()
guard let plist = try? decoder.decode(Dictionary<String, String>.self, from: data) else {
continue
}
print(plist.keys.map { #""\#($0)" = "\#(plist[$0]!);"# }.joined(separator: "\n"))
}
上記のコードで、
...
"REQUEST_ACCESS_SERVICE_kTCCServiceCamera" = "“%@”がカメラへのアクセスを求めています;
"REQUEST_ACCESS_ALLOW_kTCCServiceFallDetection" = "データを共有;
"REQUEST_ACCESS_SERVICE_kTCCServiceMediaLibrary" = "“%@”がApple Music、ミュージックとビデオの履歴、およびメディアライブラリにアクセスを求めています;
"REQUEST_ACCESS_ALLOW_kTCCServicePhotos" = "すべての写真へのアクセスを許可;
"REQUEST_ACCESS_DENY_kTCCServiceExposureNotification" = "有効にしない;
"REQUEST_ACCESS_DENY_kTCCServiceFocusStatus" = "許可しない;
...
"REQUEST_ACCESS_ALLOW_kTCCServicePhotos" = "Allow Access to All Photos;
"REQUEST_ACCESS_DENY" = "Don’t Allow;
"REQUEST_ACCESS_ALLOW_kTCCServiceFocusStatus" = "OK;
"REQUEST_ACCESS_SERVICE_kTCCServiceContactsFull" = "“%@” Would Like to Access All Your Contacts Information;
"REQUEST_ACCESS_LIMITED_kTCCServicePhotos" = "Select Photos…;
"REQUEST_ACCESS_INFO_SERVICE_kTCCServiceExposureNotification" = "Your iPhone can securely collect and share random IDs with nearby devices. The app can use these IDs to notify you if you may have been exposed to COVID-19. The date, duration and signal strength of an exposure will be shared with “%@”.;
"REQUEST_ACCESS_INFO_SERVICE_kTCCServiceFallDetection" = "If you choose to share, “%@” can receive data from Apple Watch if a fall is detected and follow-up in case help is needed.;
"REQUEST_ACCESS_SERVICE_kTCCServiceBluetoothAlways" = "“%@” Would Like to Use Bluetooth;
"REQUEST_ACCESS_DENY_kTCCServiceFocusStatus" = "Don’t Allow;
...
このような出力が得られます。これでOSが表示する各言語ごとのテキストがわかります。
問題は目的のテキストがどのBundle(=Framework)に入っているのかというところですが、それは
/System/Library/Frameworks/
と/System/Library/PrivateFrameworks/
の中に含まれる各Frameworkに対してLocalizable.stringsがあるかどうかを調べてすべてのFrameworkのLocalizable.stringsを出力するようなコードを書くと調べられます。
下記のコードは上記のコードに特定のディレクトリ以下のFrameworkをすべて処理するコードを追加したものです。
このメソッドを
dumpStrings(in: "/System/Library/Frameworks")
dumpStrings(in: "/System/Library/PrivateFrameworks")
のように呼び出すとOSが出力するほぼすべてのメッセージテキストを調べることができます。
func dumpStrings(in frameworkPath: String) {
let fm = FileManager()
guard let frameworks = try? fm.contentsOfDirectory(atPath: frameworkPath) else {
return
}
for framework in frameworks {
guard let bundle = Bundle(path: "\(frameworkPath)/\(framework)") else {
continue
}
for localization in bundle.localizations {
guard localization == "ja" else {
continue
}
guard
let localizedFiles = try? fm.contentsOfDirectory(
atPath: "\(bundle.bundlePath)/\(localization).lproj")
else {
continue
}
for localizedFile in localizedFiles {
guard localizedFile.hasSuffix("strings") else {
continue
}
print("===== \(localization)/\(localizedFile) in \(bundle.bundlePath)")
let fileUrl = bundle.url(
forResource: localizedFile,
withExtension: nil,
subdirectory: nil,
localization: localization
)
guard let fileUrl = fileUrl, let data = try? Data(contentsOf: fileUrl) else {
continue
}
let decoder = PropertyListDecoder()
guard let plist = try? decoder.decode(Dictionary<String, String>.self, from: data) else {
continue
}
print(plist.keys.map { #""\#($0)" = "\#(plist[$0]!);"# }.joined(separator: "\n"))
}
}
}
}