Merge branch 'feature/improve_locale' into 'develop'

Improve locale

See merge request BPHV_MIPS/mvm_core!149
This commit is contained in:
Pfeil, Scott Robert 2021-03-18 15:17:43 -04:00
commit c07a59ad2e
3 changed files with 32 additions and 10 deletions

View File

@ -7,7 +7,6 @@
// Copyright © 2019 myverizon. All rights reserved.
//
import Foundation
public struct ModelRegistry {

View File

@ -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;

View File

@ -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 {