diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index deeb6ed..b36edf3 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -7,7 +7,6 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation public struct ModelRegistry { diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h index 262cc75..64feae8 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h @@ -19,6 +19,15 @@ // Returns the hardcoded string from the string file. + (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key; +// Returns the hardcoded string from the string file based on module. ++ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key bundle:(nullable NSBundle *)bundle; + +// Return current system language ++ (nullable NSString *)getSystemLanguage; + +// Return current preferred system language ++ (nullable NSString *)getPreferredAvailableLanguage; + // Returns true if the user's language is Spanish + (BOOL)userPrefersSpanish; diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m index b48f34e..c5a8570 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m @@ -18,20 +18,34 @@ return [NSBundle bundleWithIdentifier:@"com.vzw.MVMCore"]; } +// Confirms that the preferred user language is for spanish users. + (BOOL)userPrefersSpanish { - // This should be enough for us to look at what the user prefers. - return [[[[[NSLocale preferredLanguages] objectAtIndex:0] substringToIndex:2] lowercaseString] isEqualToString:@"es"]; + + return [[[MVMCoreGetterUtility getPreferredAvailableLanguage] lowercaseString] hasPrefix:@"es"]; +} + +// Gets language code based on what the user prefers and the app provides. ++ (NSString *)getPreferredAvailableLanguage { + + return [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]; +} + +// Returns the preferred language set system wide. ++ (NSString *)getSystemLanguage { + + return [[NSLocale preferredLanguages] objectAtIndex:0]; } + (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key { + // Redirect key with relevant module. + return [MVMCoreGetterUtility hardcodedStringWithKey:key bundle:[MVMCoreGetterUtility bundleForMVMCore]]; +} + ++ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key bundle:(nullable NSBundle *)bundle { + // If the app language is not english... force load from the english file anyway. - if ([MVMCoreGetterUtility userPrefersSpanish]) { - return [[NSBundle bundleWithPath:[[MVMCoreGetterUtility bundleForMVMCore] pathForResource:@"es" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil]; - - } else { - return [[NSBundle bundleWithPath:[[MVMCoreGetterUtility bundleForMVMCore] pathForResource:@"en" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil]; - - } + NSString *languageCode = [MVMCoreGetterUtility userPrefersSpanish] ? @"es" : @"en"; + return [[NSBundle bundleWithPath:[bundle pathForResource:languageCode ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil]; } + (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString {