//
// MJRefreshLocalization.m
// Project
//
// Created by haibara on 1/3/17.
//
//

#import "MJRefreshLocalization.h"
#import "SDK.h"
#import <JRSwizzle/JRSwizzle.h>
#import <MJRefresh/MJRefresh.h>

@implementation MJRefreshLocalization

+ (NSString *)localizedStringForKey:(NSString *)key {
	NSString *language = [IMLocalization sharedInstance].language;
	NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]];;
	return [bundle localizedStringForKey:key value:nil table:nil];
}

@end

@interface MJRefreshStateHeader (Localization)
@end

@implementation MJRefreshStateHeader (Localization)

+ (void)load {
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		[self jr_swizzleMethod:@selector(prepare) withMethod:@selector(l_prepare) error:NULL];
	});
}

- (void)l_prepare {
	[self l_prepare];

	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshHeaderRefreshingText] forState:MJRefreshStateRefreshing];
}

@end

@interface MJRefreshBackStateFooter (Localization)
@end

@implementation MJRefreshBackStateFooter (Localization)

+ (void)load {
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		[self jr_swizzleMethod:@selector(prepare) withMethod:@selector(l_prepare) error:NULL];
	});
}

- (void)l_prepare {
	[self l_prepare];

	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData];
}

@end

@interface MJRefreshAutoStateFooter (Localization)
@end

@implementation MJRefreshAutoStateFooter (Localization)

+ (void)load {
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		[self jr_swizzleMethod:@selector(prepare) withMethod:@selector(l_prepare) error:NULL];
	});
}

- (void)l_prepare {
	[self l_prepare];

	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing];
	[self setTitle:[MJRefreshLocalization localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData];
}

@end



