Я пытаюсь добавить локализацию в свое приложение в SwiftUI, и оно работает нормально на чистом тексте ("..."). Но не работает с перечислениями.
Я использую значение перечисления, как показано ниже, header.name.text = HomeSection.allCases[indexPath.section].rawValue
. И я провел эксперимент на case1 - NowPlaying, однако он не работает, после запуска приложения отображается текст «NowPlayingSection».
Так что же мне делать, чтобы иметь дело с enum при локализации?
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionView.elementKindSectionHeader:
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: HeaderView.reuseId, for: indexPath) as? HeaderView else {
return UICollectionReusableView()
}
header.name.text = HomeSection.allCases[indexPath.section].rawValue
header.onSeeAllClicked = { [weak self] in
print("%%% Click %$$$$")
self?.parent.seeAllforSection(HomeSection.allCases[indexPath.section])
}
return header
default:
return UICollectionReusableView()
}
}
Enums
enum HomeSection: String, CaseIterable {
case NowPlaying = "NowPlayingSection"
case Popular
case Upcoming
case TopActor = "Hot Actors"
}
Localizable.strings
"NowPlayingSection" = "Now playing";