Posts

Post not yet marked as solved
3 Replies
453 Views
I'm trying to display an Int in Hebrew. so for example 123 should display אבג 1 = א 2 = ב 3 = ג I have tried specifying the locale based on a the answer to a different post of mine where the solution was to specify the numbering system in the locale Locale(identifier: "he-IL@numbers=hebr") print(123.formatted(.number.locale(Locale(identifier: "en@numbers=hebr")))) // Output: 123 When setting the same locale for dates it formats properly with Hebrew numbers. However if I do Arabic instead of Hebrew the numbers display properly in arabic the result for this is `` print(123.formatted(.number.locale(Locale(identifier: "en@numbers=Arab")))) // Output: ١٢٣ Below is the code I've tried running in a playground: This is the code I ran in the playground
Posted
by Timapp.
Last updated
.
Post not yet marked as solved
2 Replies
562 Views
Is there a way using Date.FormatStyle to make the numbers also show in Hebrew the same way DateFormatter does? For some reason using Date.FormatStyle doesn't seem to have the ability to show the numbers locally. Here's some sample code, you can see that using DateFormatter the locale is respected and it displays properly but using Date.FormatStyle the numbers are still regular numbers. Update: Here's a modified version of DateFormatter. The goal is using Date.FormatStyle and getting the same result as DateFormatter import SwiftUI struct ContentView: View { let date = Date.now var body: some View { List{ Text(date.formatted(formatStyle.attributed)) .environment(\.locale, Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel)) .environment(\.calendar, Calendar(identifier: .hebrew)) Text(date, format: formattttttt) .environment(\.locale, Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel)) .environment(\.calendar, Calendar(identifier: .hebrew)) Text(dateFormatted(date: date)) } } func dateFormatted(date: Date) -> String{ let dateFormatter = DateFormatter() dateFormatter.calendar = Calendar(identifier: .hebrew) dateFormatter.locale = Locale(identifier: "he") dateFormatter.dateStyle = .full return dateFormatter.string(from: date) } let formatStyle = Date.FormatStyle( date: .complete, time: .omitted, locale: Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel), calendar: Calendar(identifier: .hebrew) ) let formattttttt = Date.FormatStyle( date: .complete, time: .omitted, locale: Locale(identifier: "he"), calendar: Calendar(identifier: .hebrew)).locale(Locale(identifier: "he")) }
Posted
by Timapp.
Last updated
.