This might do the trick:
func localizations() -> [String] {
guard let contentsURLs = try? FileManager.default.contentsOfDirectory(at: Bundle.main.bundleURL, includingPropertiesForKeys: nil) else { return [] }
let identifiers = contentsURLs.compactMap { anURL -> String? in
guard anURL.pathExtension == "lproj" else { return nil }
return anURL.deletingPathExtension().lastPathComponent
}
let humanReadableNames = identifiers.compactMap { anIdentifier in
return Locale.current.localizedString(forIdentifier: anIdentifier)?.localizedCapitalized
}
return humanReadableNames
}
I even transformed them into human readable languages names, instead of having for instance "zh-Hans" for "Chinese (Simplified)".
Of course, if you handle yourself your locale, your might want to use a different Locale.current, but you get the idea...
FileManager.default.contentsOfDirectory(atPath: Bundle.main.bundlePath).filter { $0.hasSuffix(".lproj") }might be helpful...