Skip to content

Commit 58138db

Browse files
MJ LeeMJ Lee
MJ Lee
authored and
MJ Lee
committed
本地化修改
1.删除不必要的lproj 2.简化本地化代码
1 parent 62cb56c commit 58138db

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

Diff for: MJRefresh/Base/MJRefreshComponent.m

+9-15
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,20 @@ - (NSString *)localizedStringForKey:(NSString *)key{
140140
- (NSString *)localizedStringForKey:(NSString *)key withDefault:(NSString *)defaultString
141141
{
142142
static NSBundle *bundle = nil;
143-
if (bundle == nil)
144-
{
145-
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"MJRefresh" ofType:@"bundle"];
146-
147-
bundle = [NSBundle bundleWithPath:bundlePath];
148-
NSString *language = [[NSLocale preferredLanguages] count]? [NSLocale preferredLanguages][0]: @"en";
143+
if (bundle == nil) {
144+
// 获得设备的语言
145+
NSString *language = [NSLocale preferredLanguages].firstObject;
146+
// 如果是iOS9以上,截取前面的语言标识
149147
if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0) {
150148
NSRange range = [language rangeOfString:@"-" options:NSBackwardsSearch];
151149
language = [language substringToIndex:range.location];
152150
}
153-
if (![[bundle localizations] containsObject:language])
154-
{
155-
language = [language componentsSeparatedByString:@"-"][0];
156-
}
157-
if ([[bundle localizations] containsObject:language])
158-
{
159-
bundlePath = [bundle pathForResource:language ofType:@"lproj"];
151+
152+
// 先从MJRefresh.bundle中查找资源
153+
NSBundle *refreshBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MJRefresh" ofType:@"bundle"]];
154+
if ([refreshBundle.localizations containsObject:language]) {
155+
bundle = [NSBundle bundleWithPath:[refreshBundle pathForResource:language ofType:@"lproj"]];
160156
}
161-
162-
bundle = [NSBundle bundleWithPath:bundlePath] ?: [NSBundle mainBundle];
163157
}
164158
defaultString = [bundle localizedStringForKey:key value:defaultString table:nil];
165159
return [[NSBundle mainBundle] localizedStringForKey:key value:defaultString table:nil];

Diff for: MJRefresh/MJRefresh.bundle/ru.lproj/Localizable.strings

-16
This file was deleted.

0 commit comments

Comments
 (0)