cdts/xdts-ios 3/TreeHole/Code/Gategory/BRPickerView/Base/NSBundle+BRPickerView.m

69 lines
2.4 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// NSBundle+BRPickerView.m
// BRPickerViewDemo
//
// Created by renbo on 2019/10/30.
// Copyright © 2019 irenb. All rights reserved.
//
// https://github.com/91renb/BRPickerView
#import "NSBundle+BRPickerView.h"
#import "BRBaseView.h"
BRSYNTH_DUMMY_CLASS(NSBundle_BRPickerView)
@implementation NSBundle (BRPickerView)
#pragma mark - BRPickerView.bundle
+ (instancetype)br_pickerBundle {
static NSBundle *pickerBundle = nil;
if (!pickerBundle) {
/*
bundle
framework framework bundle
target client main bundle
BRPickerView bundle
*/
NSBundle *bundle = [NSBundle bundleForClass:[BRBaseView class]];
NSURL *url = [bundle URLForResource:@"BRPickerView" withExtension:@"bundle"];
pickerBundle = [NSBundle bundleWithURL:url];
}
return pickerBundle;
}
#pragma mark -
+ (NSString *)br_localizedStringForKey:(NSString *)key language:(NSString *)language {
return [self br_localizedStringForKey:key value:nil language:language];
}
+ (NSString *)br_localizedStringForKey:(NSString *)key value:(NSString *)value language:(NSString *)language {
static NSBundle *bundle = nil;
if (!bundle) {
//
if (!language) {
//
language = [NSLocale preferredLanguages].firstObject;
}
if ([language hasPrefix:@"en"]) {
language = @"en";
} else if ([language hasPrefix:@"zh"]) {
if ([language rangeOfString:@"Hans"].location != NSNotFound) {
language = @"zh-Hans"; //
} else { // zh-Hantzh-HKzh-TW
language = @"zh-Hant"; //
}
} else {
language = @"en";
}
// BRPickerView.bundle
bundle = [NSBundle bundleWithPath:[[self br_pickerBundle] pathForResource:language ofType:@"lproj"]];
}
value = [bundle localizedStringForKey:key value:value table:nil];
return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
}
@end