This commit is contained in:
2026-03-04 19:49:07 +08:00
parent c42ccfbcdf
commit 7029209a4d
6 changed files with 293 additions and 25 deletions

View File

@@ -25,6 +25,8 @@
#define API_RESET_PWD @"/user/resetPassWord" // 重置密码
#define API_USER_FEEDBACK @"/user/feedback" // 提交反馈
#define API_APP_CHECK_UPDATE @"/appVersions/checkUpdate" // 检查更新
#define API_LOGOUT @"/user/logout" // 退出登录

View File

@@ -19,10 +19,10 @@ FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeEnglish; // @"en"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeSimplifiedChinese; // @"zh-Hans"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeTraditionalChinese; // @"zh-Hant"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeSpanish; // @"es"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodePortuguese; // @"pt"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodePortuguese; // @"pt-PT"
FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeIndonesian; // @"id"
/// 默认支持的语言列表当前en / zh-Hans / zh-Hant / es / pt / id
/// 默认支持的语言列表当前en / zh-Hans / zh-Hant / es / pt-PT / id
FOUNDATION_EXPORT NSArray<KBLanguageCode> *KBDefaultSupportedLanguageCodes(void);
/// 当前语言变更通知(不附带 userInfo

View File

@@ -12,7 +12,7 @@ KBLanguageCode const KBLanguageCodeEnglish = @"en";
KBLanguageCode const KBLanguageCodeSimplifiedChinese = @"zh-Hans";
KBLanguageCode const KBLanguageCodeTraditionalChinese = @"zh-Hant";
KBLanguageCode const KBLanguageCodeSpanish = @"es";
KBLanguageCode const KBLanguageCodePortuguese = @"pt";
KBLanguageCode const KBLanguageCodePortuguese = @"pt-PT";
KBLanguageCode const KBLanguageCodeIndonesian = @"id";
///
@@ -94,7 +94,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
if (code.length == 0) return; //
if ([code isEqualToString:self.currentLanguageCode]) return; //
[self applyLanguage:code];
if (persist) { [[self class] kc_write:code]; } // App/
if (persist) { [[self class] kc_write:self.currentLanguageCode]; } // App/
[[NSNotificationCenter defaultCenter] postNotificationName:KBLocalizationDidChangeNotification object:nil];
}
@@ -160,12 +160,16 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) {
#pragma mark -
- (void)applyLanguage:(NSString *)code {
_currentLanguageCode = [code copy];
NSString *normalizedCode = code;
if ([normalizedCode.lowercaseString isEqualToString:@"pt"]) {
normalizedCode = @"pt-PT";
}
_currentLanguageCode = [normalizedCode copy];
// TargetApp bundle .lproj
NSString *path = [NSBundle.mainBundle pathForResource:code ofType:@"lproj"];
NSString *path = [NSBundle.mainBundle pathForResource:normalizedCode ofType:@"lproj"];
if (!path) {
// en-GB -> en
NSString *shortCode = [[code componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]] firstObject];
NSString *shortCode = [[normalizedCode componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-_"]] firstObject];
if (shortCode.length > 0) {
path = [NSBundle.mainBundle pathForResource:shortCode ofType:@"lproj"];
}