NSBundle+TZImagePicker.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // NSBundle+TZImagePicker.m
  3. // TZImagePickerController
  4. //
  5. // Created by 谭真 on 16/08/18.
  6. // Copyright © 2016年 谭真. All rights reserved.
  7. //
  8. #import "NSBundle+TZImagePicker.h"
  9. #import "TZImagePickerController.h"
  10. @implementation NSBundle (TZImagePicker)
  11. + (instancetype)tz_imagePickerBundle {
  12. static NSBundle *tzBundle = nil;
  13. if (tzBundle == nil) {
  14. NSString *path = [[NSBundle mainBundle] pathForResource:@"TZImagePickerController" ofType:@"bundle"];
  15. if (!path) {
  16. path = [[NSBundle mainBundle] pathForResource:@"TZImagePickerController" ofType:@"bundle" inDirectory:@"Frameworks/TZImagePickerController.framework/"];
  17. }
  18. tzBundle = [NSBundle bundleWithPath:path];
  19. }
  20. return tzBundle;
  21. }
  22. + (NSString *)tz_localizedStringForKey:(NSString *)key {
  23. return [self tz_localizedStringForKey:key value:@""];
  24. }
  25. + (NSString *)tz_localizedStringForKey:(NSString *)key value:(NSString *)value {
  26. static NSBundle *bundle = nil;
  27. if (bundle == nil) {
  28. NSString *language = [NSLocale preferredLanguages].firstObject;
  29. if ([language rangeOfString:@"zh-Hans"].location != NSNotFound) {
  30. language = @"zh-Hans";
  31. } else {
  32. language = @"en";
  33. }
  34. bundle = [NSBundle bundleWithPath:[[NSBundle tz_imagePickerBundle] pathForResource:language ofType:@"lproj"]];
  35. }
  36. NSString *value1 = [bundle localizedStringForKey:key value:value table:nil];
  37. return value1;
  38. }
  39. @end