Merge branch 'feature/improve_locale' into 'develop'
Improve locale See merge request BPHV_MIPS/mvm_core!149
This commit is contained in:
commit
c07a59ad2e
@ -7,7 +7,6 @@
|
|||||||
// Copyright © 2019 myverizon. All rights reserved.
|
// Copyright © 2019 myverizon. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
public struct ModelRegistry {
|
public struct ModelRegistry {
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,15 @@
|
|||||||
// 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;
|
||||||
|
|
||||||
|
// 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
|
// Returns true if the user's language is Spanish
|
||||||
+ (BOOL)userPrefersSpanish;
|
+ (BOOL)userPrefersSpanish;
|
||||||
|
|
||||||
|
|||||||
@ -18,20 +18,34 @@
|
|||||||
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 {
|
||||||
// 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 {
|
+ (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 the app language is not english... force load from the english file anyway.
|
||||||
if ([MVMCoreGetterUtility userPrefersSpanish]) {
|
NSString *languageCode = [MVMCoreGetterUtility userPrefersSpanish] ? @"es" : @"en";
|
||||||
return [[NSBundle bundleWithPath:[[MVMCoreGetterUtility bundleForMVMCore] pathForResource:@"es" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil];
|
return [[NSBundle bundleWithPath:[bundle pathForResource:languageCode ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil];
|
||||||
|
|
||||||
} else {
|
|
||||||
return [[NSBundle bundleWithPath:[[MVMCoreGetterUtility bundleForMVMCore] pathForResource:@"en" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil];
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString {
|
+ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user