Merge branch 'feature/improve_locale' into 'develop'
refactoring See merge request BPHV_MIPS/mvm_core_ui!691
This commit is contained in:
commit
7a8a28a121
@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
//Returns localized imageName
|
||||
// Returns localized imageName
|
||||
+ (nullable NSString *)localizedImageName:(nullable NSString *)imageName;
|
||||
|
||||
// The bundle for this framework
|
||||
|
||||
@ -23,24 +23,14 @@
|
||||
return [NSBundle bundleWithIdentifier:@"com.vzw.MVMCoreUI"];
|
||||
}
|
||||
|
||||
+ (BOOL)userPrefersSpanish {
|
||||
// This should be enough for us to look at what the user prefers.
|
||||
NSString *preference = [[[[NSLocale preferredLanguages] objectAtIndex:0] substringToIndex:2] lowercaseString];
|
||||
return [preference isEqualToString:@"es"] || [preference isEqualToString:@"es-mx"];
|
||||
}
|
||||
|
||||
+ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key {
|
||||
// If the app language is not english... force load from the english file anyway.
|
||||
if ([MVMCoreUIUtility userPrefersSpanish]) {
|
||||
return [[NSBundle bundleWithPath:[[MVMCoreUIUtility bundleForMVMCoreUI] pathForResource:@"es" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil];
|
||||
} else {
|
||||
return [[NSBundle bundleWithPath:[[MVMCoreUIUtility bundleForMVMCoreUI] pathForResource:@"en" ofType:@"lproj"]] localizedStringForKey:key value:@"" table:nil];
|
||||
}
|
||||
// Redirect key with relevant module.
|
||||
return [MVMCoreGetterUtility hardcodedStringWithKey:key bundle:[MVMCoreUIUtility bundleForMVMCoreUI]];
|
||||
}
|
||||
|
||||
+ (nullable NSString *)localizedImageName:(nullable NSString *)imageName {
|
||||
if (imageName.length > 0) {
|
||||
if ([MVMCoreUIUtility userPrefersSpanish]) {
|
||||
if ([MVMCoreGetterUtility userPrefersSpanish]) {
|
||||
imageName = [NSString stringWithFormat:@"%@_es", imageName];
|
||||
} else {
|
||||
imageName = [NSString stringWithFormat:@"%@_en", imageName];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user