updating func

This commit is contained in:
Kevin G Christiano 2021-03-17 13:52:20 -04:00
parent 63abf3d35e
commit e13530f5b4
2 changed files with 20 additions and 2 deletions

View File

@ -19,6 +19,12 @@
// Returns the hardcoded string from the string file. // Returns the hardcoded string from the string file.
+ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key; + (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key;
// Return current system language
+ (nullable NSString *)getSystemLanguage;
// Return current preferred system language
+ (nullable NSString *)getPreferredAvailableLanguage;
// Returns true if the user's language is Spanish // Returns true if the user's language is Spanish
+ (BOOL)userPrefersSpanish; + (BOOL)userPrefersSpanish;

View File

@ -18,9 +18,10 @@
return [NSBundle bundleWithIdentifier:@"com.vzw.MVMCore"]; return [NSBundle bundleWithIdentifier:@"com.vzw.MVMCore"];
} }
// Confirms that the preferred user language is for spanish users.
+ (BOOL)userPrefersSpanish { + (BOOL)userPrefersSpanish {
// Gets language code based on what the user prefers and the app provides.
NSString *languageCode = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]; NSString *languageCode = [MVMCoreGetterUtility getPreferredAvailableLanguage];
if (languageCode && [languageCode length] > 2) { if (languageCode && [languageCode length] > 2) {
return [[[languageCode substringToIndex:2] lowercaseString] isEqualToString:@"es"]; return [[[languageCode substringToIndex:2] lowercaseString] isEqualToString:@"es"];
} else { } else {
@ -28,6 +29,17 @@
} }
} }
// Gets language code based on what the user prefers and the app provides.
+ (NSString *)getPreferredAvailableLanguage {
return [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
}
+ (NSString *)getSystemLanguage {
return [[NSLocale preferredLanguages] objectAtIndex:0];
}
+ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key { + (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key {
// If the app language is not english... force load from the english file anyway. // If the app language is not english... force load from the english file anyway.
if ([MVMCoreGetterUtility userPrefersSpanish]) { if ([MVMCoreGetterUtility userPrefersSpanish]) {