Skip to content

Commit

Permalink
Fixed crash when accessing Locale.availableIdentifiers on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavkovac committed Sep 4, 2017
1 parent ba9e7b9 commit cfb9f66
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/Lingo/LocaleValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import Foundation

class LocaleValidator {

private static let validLocaleIdentifiers = Set(Locale.availableIdentifiers)

// On Linux `Locale.availableIdentifiers` throws an exception.
// Issue reported: https://bugs.swift.org/browse/SR-3634
// Pull request with fix: https://github.com/apple/swift-corelibs-foundation/pull/944
// This check can be removed when the changes are available in a new Swift version.
#if os(Linux)
private static let validLocaleIdentifiers = Set<String>()
#else
private static let validLocaleIdentifiers = Set(Locale.availableIdentifiers)
#endif

/// Checks if given locale is present in Locale.availableIdentifiers
func validate(locale: LocaleIdentifier) -> Bool {
return LocaleValidator.validLocaleIdentifiers.contains(locale)
Expand Down

0 comments on commit cfb9f66

Please sign in to comment.