 
 import Foundation
 
-extension NSLocale {
+final class AppLocale {
+	private(set) var original: Locale
+	private init() {
+		original = Locale.autoupdatingCurrent
+	}
+	static var shared = AppLocale()
+
 
 	///	Builds as specific LocaleIdentifier as your app needs
-	class var appIdentifier: String {
+	private var localeIdentifier: String {
 		//	start with whatever is used by iOS
-		let cur = NSLocale.autoupdatingCurrent
-		var comps = NSLocale.components(fromLocaleIdentifier: cur.identifier)
+		var comps = NSLocale.components(fromLocaleIdentifier: original.identifier)
+
+		//	Note: if customer has not yet chosen anything custom,
+		//	then it may make sense to default to primary language on his device
 
 		//	then load your app-level overrides
 //		for (key, value) in AppConfig.localeOverrides {

		//	then override the language with current in-app choice
		if let languageCode = UserDefaults.languageCode {
			comps[NSLocale.Key.languageCode.rawValue] = languageCode
		} else {
			//	if customer has not yet chosen anything custom, 
			//	then default to primary language on his device
			//	WARNING:
			//	user language must be one of the ones available in the app
			//	so make sure that whatever ends up as result, it actually has its own .lproj file
			if let userPreferredLanguage = cur.languageCode {
				comps[NSLocale.Key.languageCode.rawValue] = userPreferredLanguage
			}
		}

		//	finally return all of those settings combined
		let identifier = localeIdentifier(fromComponents: comps)
		return identifier
	}


	///	This is used to to override `current` and `autoupdatingCurrent`
	///	using `appIdentifier`
	class var app: Locale {
		return Locale(identifier: appIdentifier)
	}




	///	Call this as early as possible in application lifecycle, say in application(_:willFinishLaunchingWithOptions:)
	static func setupInitialLanguage() {
		let _ = AppLocale.shared

		if let languageCode = UserDefaults.languageCode {
			enforceLanguage(code: languageCode)

			//	override NSLocale.current
			NSLocale.swizzle(selector: #selector(getter: NSLocale.current))
			return;
		}

