bug
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
|
||||
/// 语言常量定义
|
||||
KBLanguageCode const KBLanguageCodeEnglish = @"en";
|
||||
KBLanguageCode const KBLanguageCodeSimplifiedChinese = @"zh-Hans";
|
||||
KBLanguageCode const KBLanguageCodeTraditionalChinese = @"zh-Hant";
|
||||
KBLanguageCode const KBLanguageCodeSpanish = @"es";
|
||||
KBLanguageCode const KBLanguageCodePortuguese = @"pt-PT";
|
||||
@@ -22,11 +21,10 @@ NSArray<KBLanguageCode> *KBDefaultSupportedLanguageCodes(void) {
|
||||
dispatch_once(&onceToken, ^{
|
||||
codes = @[
|
||||
KBLanguageCodeEnglish,
|
||||
KBLanguageCodeSimplifiedChinese,
|
||||
KBLanguageCodeTraditionalChinese,
|
||||
KBLanguageCodeSpanish,
|
||||
KBLanguageCodeIndonesian,
|
||||
KBLanguageCodePortuguese,
|
||||
KBLanguageCodeIndonesian
|
||||
KBLanguageCodeTraditionalChinese
|
||||
];
|
||||
});
|
||||
return codes;
|
||||
@@ -125,7 +123,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
|
||||
if ([pLC isEqualToString:s.lowercaseString]) { return s; }
|
||||
}
|
||||
}
|
||||
// 2) 前缀匹配:如 zh-Hans-CN -> zh-Hans, en-GB -> en
|
||||
// 2) 前缀匹配:如 en-GB -> en, es-MX -> es
|
||||
for (NSString *p in preferred) {
|
||||
NSString *pLC = p.lowercaseString;
|
||||
for (NSString *s in self.supportedLanguageCodes) {
|
||||
@@ -139,6 +137,15 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2.5) 特殊处理葡语:pt-BR / pt-PT / pt -> pt-PT(若受支持)
|
||||
for (NSString *p in preferred) {
|
||||
NSString *pLC = p.lowercaseString;
|
||||
if ([pLC isEqualToString:@"pt"] || [pLC hasPrefix:@"pt-"] || [pLC hasPrefix:@"pt_"]) {
|
||||
for (NSString *s in self.supportedLanguageCodes) {
|
||||
if ([s.lowercaseString isEqualToString:@"pt-pt"]) { return s; }
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3) 特殊处理中文:将 zh-Hant/zh-TW/zh-HK 映射到 zh-Hant(若受支持)
|
||||
for (NSString *p in preferred) {
|
||||
NSString *pLC = p.lowercaseString;
|
||||
@@ -147,11 +154,6 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
|
||||
if ([s.lowercaseString isEqualToString:@"zh-hant"]) { return s; }
|
||||
}
|
||||
}
|
||||
if ([pLC hasPrefix:@"zh-hans"] || [pLC hasPrefix:@"zh-cn"]) {
|
||||
for (NSString *s in self.supportedLanguageCodes) {
|
||||
if ([s.lowercaseString isEqualToString:@"zh-hans"]) { return s; }
|
||||
}
|
||||
}
|
||||
}
|
||||
// 4) 兜底:取第一个受支持语言
|
||||
return self.supportedLanguageCodes.firstObject ?: KBLanguageCodeEnglish;
|
||||
@@ -161,9 +163,14 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
|
||||
|
||||
- (void)applyLanguage:(NSString *)code {
|
||||
NSString *normalizedCode = code;
|
||||
if ([normalizedCode.lowercaseString isEqualToString:@"pt"]) {
|
||||
NSString *lower = normalizedCode.lowercaseString;
|
||||
if ([lower isEqualToString:@"pt"] || [lower hasPrefix:@"pt-"] || [lower hasPrefix:@"pt_"]) {
|
||||
normalizedCode = @"pt-PT";
|
||||
}
|
||||
lower = normalizedCode.lowercaseString;
|
||||
if ([lower hasPrefix:@"zh-hant"] || [lower hasPrefix:@"zh_hant"] || [lower hasPrefix:@"zh-tw"] || [lower hasPrefix:@"zh_hk"]) {
|
||||
normalizedCode = KBLanguageCodeTraditionalChinese;
|
||||
}
|
||||
_currentLanguageCode = [normalizedCode copy];
|
||||
// 基于当前 Target(App 或扩展)的主 bundle 加载 .lproj 资源
|
||||
NSString *path = [NSBundle.mainBundle pathForResource:normalizedCode ofType:@"lproj"];
|
||||
|
||||
Reference in New Issue
Block a user