36 lines
898 B
Objective-C
36 lines
898 B
Objective-C
//
|
|
// NSBundle+Localizable.m
|
|
// YuMi
|
|
//
|
|
// Created by YuMi on 2023/6/19.
|
|
//
|
|
|
|
#import "NSBundle+Localizable.h"
|
|
|
|
@implementation NSBundle (Localizable)
|
|
+(NSString *)ymLocalizedStringForKey:(NSString *)key
|
|
{
|
|
return [self ymLocalizedStringForKey:key value:nil];
|
|
}
|
|
|
|
+(NSString *)ymLocalizedStringForKey:(NSString *)key value:(NSString *)value
|
|
{
|
|
|
|
NSString *language = [NSLocale preferredLanguages].firstObject;
|
|
if ([language hasPrefix:@"zh"]) {
|
|
if ([language rangeOfString:@"Hans"].location != NSNotFound) {
|
|
language = @"zh-Hans"; // 简体中文
|
|
} else {
|
|
language = @"zh-Hant"; // 繁體中文
|
|
}
|
|
} else {
|
|
language = @"zh-Hant"; // 繁體中文
|
|
}
|
|
NSBundle * bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]];
|
|
value = [bundle localizedStringForKey:key value:value table:nil];
|
|
|
|
return value;
|
|
}
|
|
|
|
@end
|