Fix deprecation warnings on locale

This commit is contained in:
Angelo Stavrow 2024-01-22 07:33:10 -05:00
parent f0df99c1a8
commit 4f97eb5e93
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 20 additions and 6 deletions

View File

@ -94,9 +94,16 @@ extension WriteFreelyModel {
}
if post.language == nil {
if let languageCode = Locale.current.languageCode {
post.language = languageCode
post.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
if #available(iOS 16, macOS 13, *) {
if let languageCode = Locale.current.language.languageCode?.identifier {
post.language = languageCode
post.rtl = Locale.Language(identifier: languageCode).characterDirection == .rightToLeft
}
} else {
if let languageCode = Locale.current.languageCode {
post.language = languageCode
post.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
}
}
}

View File

@ -48,9 +48,16 @@ struct PostEditorModel {
default:
managedPost.appearance = "serif"
}
if let languageCode = Locale.current.languageCode {
managedPost.language = languageCode
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
if #available(iOS 16, macOS 13, *) {
if let languageCode = Locale.current.language.languageCode?.identifier {
managedPost.language = languageCode
managedPost.rtl = Locale.Language(identifier: languageCode).characterDirection == .rightToLeft
}
} else {
if let languageCode = Locale.current.languageCode {
managedPost.language = languageCode
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
}
}
return managedPost
}