Skip to content

Commit 773ca0c

Browse files
committed
新增RNI18N依赖
1 parent 4e9a9a4 commit 773ca0c

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

QIMReactNativeLibrary.podspec

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ Pod::Spec.new do |s|
206206
ss.dependency 'QIMReactNativeLibrary/Core'
207207
end
208208

209-
s.default_subspecs = 'Core', 'CxxBridge', 'DevSupport', 'jschelpers', 'jsinspector', 'PrivateDatabase', 'cxxreact', 'ART', 'RCTActionSheet', 'RCTAnimation', 'RCTBlob', 'RCTGeolocation', 'RCTImage', 'RCTNetwork', 'RCTSettings', 'RCTText', 'RCTVibration', 'RCTWebSocket', 'RCTLinkingIOS', 'RNSVG', 'react-native-image-picker', 'RNVectorIcons', 'yoga'
209+
s.subspec "RNI18n" do |ss|
210+
ss.source_files = 'react-native-i18n/ios/**/*.{h,m}'
211+
ss.requires_arc = true
212+
end
213+
214+
s.default_subspecs = 'Core', 'CxxBridge', 'DevSupport', 'jschelpers', 'jsinspector', 'PrivateDatabase', 'cxxreact', 'ART', 'RCTActionSheet', 'RCTAnimation', 'RCTBlob', 'RCTGeolocation', 'RCTImage', 'RCTNetwork', 'RCTSettings', 'RCTText', 'RCTVibration', 'RCTWebSocket', 'RCTLinkingIOS', 'RNSVG', 'react-native-image-picker', 'RNVectorIcons', 'RNI18n', 'yoga'
210215

211216
end

react-native-i18n/ios/.DS_Store

6 KB
Binary file not shown.

react-native-i18n/ios/RNI18n.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#if __has_include("RCTBridgeModule.h")
2+
#import "RCTBridgeModule.h"
3+
#else
4+
#import <React/RCTBridgeModule.h>
5+
#endif
6+
7+
@interface RNI18n : NSObject <RCTBridgeModule>
8+
@end

react-native-i18n/ios/RNI18n.m

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#import <UIKit/UIKit.h>
2+
#import "RNI18n.h"
3+
4+
@implementation RNI18n
5+
6+
RCT_EXPORT_MODULE();
7+
8+
+ (BOOL)requiresMainQueueSetup {
9+
return YES;
10+
}
11+
12+
- (NSMutableArray *)toLanguageTags:(NSArray *)languages {
13+
NSMutableArray *languageTags = [NSMutableArray array];
14+
15+
for (id l in languages) {
16+
[languageTags addObject:[l stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
17+
}
18+
19+
return languageTags;
20+
}
21+
22+
- (NSArray *)getPreferredLanguages {
23+
NSArray *preferredLanguages = [NSLocale preferredLanguages];
24+
25+
return [[[UIDevice currentDevice] systemVersion] floatValue] >= 9
26+
? preferredLanguages
27+
: [self toLanguageTags:preferredLanguages];
28+
}
29+
30+
- (NSDictionary *)constantsToExport {
31+
return @{ @"languages": [self getPreferredLanguages] };
32+
}
33+
34+
RCT_EXPORT_METHOD(getLanguages:(RCTPromiseResolveBlock)resolve
35+
rejecter:(__unused RCTPromiseRejectBlock)reject) {
36+
resolve([self getPreferredLanguages]);
37+
}
38+
39+
@end

0 commit comments

Comments
 (0)