KMOCLanguage.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KMOCLanguage.m
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2025/3/3.
  6. //
  7. #import "KMOCLanguage.h"
  8. @implementation KMOCLanguage
  9. + (KMOCLanguage *)defaults {
  10. static KMOCLanguage *__settings = nil;
  11. if (!__settings) {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. __settings = [[KMOCLanguage alloc] init];
  15. });
  16. }
  17. return __settings;
  18. }
  19. - (instancetype)init {
  20. self = [super init];
  21. if (self) {
  22. }
  23. return self;
  24. }
  25. - (NSString *)localizedString:(NSString *)key desc:(NSString *)desc {
  26. if (!key) {
  27. return @"";
  28. }
  29. NSInteger languageType = [[NSUserDefaults standardUserDefaults] integerForKey:@"settingsLanguageTypeKey"];
  30. if (languageType == 0) {
  31. return NSLocalizedString(key, desc);
  32. } else {
  33. NSString *bundlePath = nil;
  34. if (languageType == 2) {
  35. bundlePath = [[NSBundle mainBundle] pathForResource:@"zh-Hans" ofType:@"lproj"];
  36. } else if (languageType == 3) {
  37. bundlePath = [[NSBundle mainBundle] pathForResource:@"zh-Hant" ofType:@"lproj"];
  38. } else if (languageType == 4) {
  39. bundlePath = [[NSBundle mainBundle] pathForResource:@"nl" ofType:@"lproj"];
  40. } else if (languageType == 5) {
  41. bundlePath = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
  42. } else if (languageType == 6) {
  43. bundlePath = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
  44. } else if (languageType == 7) {
  45. bundlePath = [[NSBundle mainBundle] pathForResource:@"de" ofType:@"lproj"];
  46. } else if (languageType == 8) {
  47. bundlePath = [[NSBundle mainBundle] pathForResource:@"ru" ofType:@"lproj"];
  48. } else if (languageType == 9) {
  49. bundlePath = [[NSBundle mainBundle] pathForResource:@"it" ofType:@"lproj"];
  50. } else if (languageType == 10) {
  51. bundlePath = [[NSBundle mainBundle] pathForResource:@"ja" ofType:@"lproj"];
  52. } else if (languageType == 11) {
  53. bundlePath = [[NSBundle mainBundle] pathForResource:@"pl" ofType:@"lproj"];
  54. } else if (languageType == 12) {
  55. bundlePath = [[NSBundle mainBundle] pathForResource:@"pt" ofType:@"lproj"];
  56. } else if (languageType == 13) {
  57. bundlePath = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
  58. } else {
  59. bundlePath = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
  60. }
  61. NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
  62. return NSLocalizedStringFromTableInBundle(key, @"Localizable", bundle, desc);
  63. }
  64. }
  65. @end