├── .gitignore ├── LICENSE ├── README.md ├── RNI18n.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── RNI18n ├── RNI18n.h └── RNI18n.m ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── i18n │ └── reactnativei18n │ ├── ReactNativeI18n.java │ └── ReactNativeI18nLocale.java ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/**/* 2 | 3 | # Xcode 4 | # 5 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | 27 | ## Obj-C/Swift specific 28 | *.hmap 29 | *.ipa 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | #Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Dylan Vann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-locale-detector 2 | 3 | Detects the locale of a user's phone. 4 | Based on [react-native-i18n](https://github.com/AlexanderZaytsev/react-native-i18n), but this just exports the device's locale. This isn't particularly useful on it's own and you'll probably want to use it with an i18n library like [i18next](https://github.com/i18next/i18next). 5 | 6 | ## Installation 7 | 8 | ``` 9 | npm install react-native-locale-detector --save 10 | react-native link 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```javascript 16 | // Import the locale. 17 | import locale from 'react-native-locale-detector' 18 | 19 | // We could log it. Maybe it's en-US... 20 | console.log(locale) 21 | 22 | // Or if you're using a localization library. 23 | yourLocalizationLibrary.setLocale(locale) 24 | ``` 25 | -------------------------------------------------------------------------------- /RNI18n.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CDD7BF7C1B2D5125006FDA75 /* RNI18n.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDD7BF7B1B2D5125006FDA75 /* RNI18n.h */; }; 11 | CDD7BF7E1B2D5125006FDA75 /* RNI18n.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD7BF7D1B2D5125006FDA75 /* RNI18n.m */; }; 12 | CDD7BF841B2D5126006FDA75 /* libRNI18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD7BF781B2D5125006FDA75 /* libRNI18n.a */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXContainerItemProxy section */ 16 | CDD7BF851B2D5126006FDA75 /* PBXContainerItemProxy */ = { 17 | isa = PBXContainerItemProxy; 18 | containerPortal = CDD7BF701B2D5125006FDA75 /* Project object */; 19 | proxyType = 1; 20 | remoteGlobalIDString = CDD7BF771B2D5125006FDA75; 21 | remoteInfo = RNI18n; 22 | }; 23 | /* End PBXContainerItemProxy section */ 24 | 25 | /* Begin PBXCopyFilesBuildPhase section */ 26 | CDD7BF761B2D5125006FDA75 /* CopyFiles */ = { 27 | isa = PBXCopyFilesBuildPhase; 28 | buildActionMask = 2147483647; 29 | dstPath = "include/$(PRODUCT_NAME)"; 30 | dstSubfolderSpec = 16; 31 | files = ( 32 | CDD7BF7C1B2D5125006FDA75 /* RNI18n.h in CopyFiles */, 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXCopyFilesBuildPhase section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | CDD7BF781B2D5125006FDA75 /* libRNI18n.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNI18n.a; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | CDD7BF7B1B2D5125006FDA75 /* RNI18n.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNI18n.h; sourceTree = ""; }; 41 | CDD7BF7D1B2D5125006FDA75 /* RNI18n.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNI18n.m; sourceTree = ""; }; 42 | CDD7BF831B2D5126006FDA75 /* RNI18nTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNI18nTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | CDD7BF751B2D5125006FDA75 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | CDD7BF801B2D5126006FDA75 /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | CDD7BF841B2D5126006FDA75 /* libRNI18n.a in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | /* End PBXFrameworksBuildPhase section */ 62 | 63 | /* Begin PBXGroup section */ 64 | CDD7BF6F1B2D5125006FDA75 = { 65 | isa = PBXGroup; 66 | children = ( 67 | CDD7BF7A1B2D5125006FDA75 /* RNI18n */, 68 | CDD7BF791B2D5125006FDA75 /* Products */, 69 | ); 70 | sourceTree = ""; 71 | }; 72 | CDD7BF791B2D5125006FDA75 /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | CDD7BF781B2D5125006FDA75 /* libRNI18n.a */, 76 | CDD7BF831B2D5126006FDA75 /* RNI18nTests.xctest */, 77 | ); 78 | name = Products; 79 | sourceTree = ""; 80 | }; 81 | CDD7BF7A1B2D5125006FDA75 /* RNI18n */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | CDD7BF7B1B2D5125006FDA75 /* RNI18n.h */, 85 | CDD7BF7D1B2D5125006FDA75 /* RNI18n.m */, 86 | ); 87 | path = RNI18n; 88 | sourceTree = ""; 89 | }; 90 | /* End PBXGroup section */ 91 | 92 | /* Begin PBXNativeTarget section */ 93 | CDD7BF771B2D5125006FDA75 /* RNI18n */ = { 94 | isa = PBXNativeTarget; 95 | buildConfigurationList = CDD7BF8C1B2D5126006FDA75 /* Build configuration list for PBXNativeTarget "RNI18n" */; 96 | buildPhases = ( 97 | CDD7BF741B2D5125006FDA75 /* Sources */, 98 | CDD7BF751B2D5125006FDA75 /* Frameworks */, 99 | CDD7BF761B2D5125006FDA75 /* CopyFiles */, 100 | ); 101 | buildRules = ( 102 | ); 103 | dependencies = ( 104 | ); 105 | name = RNI18n; 106 | productName = RNI18n; 107 | productReference = CDD7BF781B2D5125006FDA75 /* libRNI18n.a */; 108 | productType = "com.apple.product-type.library.static"; 109 | }; 110 | CDD7BF821B2D5126006FDA75 /* RNI18nTests */ = { 111 | isa = PBXNativeTarget; 112 | buildConfigurationList = CDD7BF8F1B2D5126006FDA75 /* Build configuration list for PBXNativeTarget "RNI18nTests" */; 113 | buildPhases = ( 114 | CDD7BF7F1B2D5126006FDA75 /* Sources */, 115 | CDD7BF801B2D5126006FDA75 /* Frameworks */, 116 | CDD7BF811B2D5126006FDA75 /* Resources */, 117 | ); 118 | buildRules = ( 119 | ); 120 | dependencies = ( 121 | CDD7BF861B2D5126006FDA75 /* PBXTargetDependency */, 122 | ); 123 | name = RNI18nTests; 124 | productName = RNI18nTests; 125 | productReference = CDD7BF831B2D5126006FDA75 /* RNI18nTests.xctest */; 126 | productType = "com.apple.product-type.bundle.unit-test"; 127 | }; 128 | /* End PBXNativeTarget section */ 129 | 130 | /* Begin PBXProject section */ 131 | CDD7BF701B2D5125006FDA75 /* Project object */ = { 132 | isa = PBXProject; 133 | attributes = { 134 | LastUpgradeCheck = 0630; 135 | ORGANIZATIONNAME = "Alexander Zaytsev"; 136 | TargetAttributes = { 137 | CDD7BF771B2D5125006FDA75 = { 138 | CreatedOnToolsVersion = 6.3.2; 139 | }; 140 | CDD7BF821B2D5126006FDA75 = { 141 | CreatedOnToolsVersion = 6.3.2; 142 | }; 143 | }; 144 | }; 145 | buildConfigurationList = CDD7BF731B2D5125006FDA75 /* Build configuration list for PBXProject "RNI18n" */; 146 | compatibilityVersion = "Xcode 3.2"; 147 | developmentRegion = English; 148 | hasScannedForEncodings = 0; 149 | knownRegions = ( 150 | en, 151 | ); 152 | mainGroup = CDD7BF6F1B2D5125006FDA75; 153 | productRefGroup = CDD7BF791B2D5125006FDA75 /* Products */; 154 | projectDirPath = ""; 155 | projectRoot = ""; 156 | targets = ( 157 | CDD7BF771B2D5125006FDA75 /* RNI18n */, 158 | CDD7BF821B2D5126006FDA75 /* RNI18nTests */, 159 | ); 160 | }; 161 | /* End PBXProject section */ 162 | 163 | /* Begin PBXResourcesBuildPhase section */ 164 | CDD7BF811B2D5126006FDA75 /* Resources */ = { 165 | isa = PBXResourcesBuildPhase; 166 | buildActionMask = 2147483647; 167 | files = ( 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXSourcesBuildPhase section */ 174 | CDD7BF741B2D5125006FDA75 /* Sources */ = { 175 | isa = PBXSourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | CDD7BF7E1B2D5125006FDA75 /* RNI18n.m in Sources */, 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | }; 182 | CDD7BF7F1B2D5126006FDA75 /* Sources */ = { 183 | isa = PBXSourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | /* End PBXSourcesBuildPhase section */ 190 | 191 | /* Begin PBXTargetDependency section */ 192 | CDD7BF861B2D5126006FDA75 /* PBXTargetDependency */ = { 193 | isa = PBXTargetDependency; 194 | target = CDD7BF771B2D5125006FDA75 /* RNI18n */; 195 | targetProxy = CDD7BF851B2D5126006FDA75 /* PBXContainerItemProxy */; 196 | }; 197 | /* End PBXTargetDependency section */ 198 | 199 | /* Begin XCBuildConfiguration section */ 200 | CDD7BF8A1B2D5126006FDA75 /* Debug */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 205 | CLANG_CXX_LIBRARY = "libc++"; 206 | CLANG_ENABLE_MODULES = YES; 207 | CLANG_ENABLE_OBJC_ARC = YES; 208 | CLANG_WARN_BOOL_CONVERSION = YES; 209 | CLANG_WARN_CONSTANT_CONVERSION = YES; 210 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 211 | CLANG_WARN_EMPTY_BODY = YES; 212 | CLANG_WARN_ENUM_CONVERSION = YES; 213 | CLANG_WARN_INT_CONVERSION = YES; 214 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_DYNAMIC_NO_PIC = NO; 222 | GCC_NO_COMMON_BLOCKS = YES; 223 | GCC_OPTIMIZATION_LEVEL = 0; 224 | GCC_PREPROCESSOR_DEFINITIONS = ( 225 | "DEBUG=1", 226 | "$(inherited)", 227 | ); 228 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 236 | MTL_ENABLE_DEBUG_INFO = YES; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = iphoneos; 239 | }; 240 | name = Debug; 241 | }; 242 | CDD7BF8B1B2D5126006FDA75 /* Release */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BOOL_CONVERSION = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_UNREACHABLE_CODE = YES; 258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 259 | COPY_PHASE_STRIP = NO; 260 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 261 | ENABLE_NS_ASSERTIONS = NO; 262 | ENABLE_STRICT_OBJC_MSGSEND = YES; 263 | GCC_C_LANGUAGE_STANDARD = gnu99; 264 | GCC_NO_COMMON_BLOCKS = YES; 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 272 | MTL_ENABLE_DEBUG_INFO = NO; 273 | SDKROOT = iphoneos; 274 | VALIDATE_PRODUCT = YES; 275 | }; 276 | name = Release; 277 | }; 278 | CDD7BF8D1B2D5126006FDA75 /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | HEADER_SEARCH_PATHS = ( 282 | "$(inherited)", 283 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 284 | "$(SRCROOT)/node_modules/react-native/React/**", 285 | "$(SRCROOT)/../react-native/React/**", 286 | ); 287 | OTHER_LDFLAGS = "-ObjC"; 288 | PRODUCT_NAME = "$(TARGET_NAME)"; 289 | SKIP_INSTALL = YES; 290 | }; 291 | name = Debug; 292 | }; 293 | CDD7BF8E1B2D5126006FDA75 /* Release */ = { 294 | isa = XCBuildConfiguration; 295 | buildSettings = { 296 | HEADER_SEARCH_PATHS = ( 297 | "$(inherited)", 298 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 299 | "$(SRCROOT)/node_modules/react-native/React/**", 300 | "$(SRCROOT)/../react-native/React/**", 301 | ); 302 | OTHER_LDFLAGS = "-ObjC"; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SKIP_INSTALL = YES; 305 | }; 306 | name = Release; 307 | }; 308 | CDD7BF901B2D5126006FDA75 /* Debug */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 312 | FRAMEWORK_SEARCH_PATHS = ( 313 | "$(SDKROOT)/Developer/Library/Frameworks", 314 | "$(inherited)", 315 | ); 316 | GCC_PREPROCESSOR_DEFINITIONS = ( 317 | "DEBUG=1", 318 | "$(inherited)", 319 | ); 320 | INFOPLIST_FILE = RNI18nTests/Info.plist; 321 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | }; 324 | name = Debug; 325 | }; 326 | CDD7BF911B2D5126006FDA75 /* Release */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 330 | FRAMEWORK_SEARCH_PATHS = ( 331 | "$(SDKROOT)/Developer/Library/Frameworks", 332 | "$(inherited)", 333 | ); 334 | INFOPLIST_FILE = RNI18nTests/Info.plist; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 336 | PRODUCT_NAME = "$(TARGET_NAME)"; 337 | }; 338 | name = Release; 339 | }; 340 | /* End XCBuildConfiguration section */ 341 | 342 | /* Begin XCConfigurationList section */ 343 | CDD7BF731B2D5125006FDA75 /* Build configuration list for PBXProject "RNI18n" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | CDD7BF8A1B2D5126006FDA75 /* Debug */, 347 | CDD7BF8B1B2D5126006FDA75 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | CDD7BF8C1B2D5126006FDA75 /* Build configuration list for PBXNativeTarget "RNI18n" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | CDD7BF8D1B2D5126006FDA75 /* Debug */, 356 | CDD7BF8E1B2D5126006FDA75 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | CDD7BF8F1B2D5126006FDA75 /* Build configuration list for PBXNativeTarget "RNI18nTests" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | CDD7BF901B2D5126006FDA75 /* Debug */, 365 | CDD7BF911B2D5126006FDA75 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | /* End XCConfigurationList section */ 371 | }; 372 | rootObject = CDD7BF701B2D5125006FDA75 /* Project object */; 373 | } 374 | -------------------------------------------------------------------------------- /RNI18n.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RNI18n/RNI18n.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNI18n.h 3 | // RNI18n 4 | // 5 | // Created by Alexander Zaytsev on 14/06/15. 6 | // Copyright (c) 2015 Alexander Zaytsev. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RCTBridgeModule.h" 11 | #import "RCTLog.h" 12 | 13 | @interface RNI18n : NSObject 14 | @end 15 | -------------------------------------------------------------------------------- /RNI18n/RNI18n.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNI18n.m 3 | // RNI18n 4 | // 5 | // Created by Alexander Zaytsev on 14/06/15. 6 | // Copyright (c) 2015 Alexander Zaytsev. All rights reserved. 7 | // 8 | 9 | #import "RNI18n.h" 10 | 11 | @interface RNI18n () 12 | -(NSString*) getCurrentLocale; 13 | @end 14 | 15 | @implementation RNI18n 16 | RCT_EXPORT_MODULE(); 17 | 18 | -(NSString*) getCurrentLocale{ 19 | NSString *localeString=[[NSLocale preferredLanguages] objectAtIndex:0]; 20 | return localeString; 21 | } 22 | 23 | - (NSDictionary *)constantsToExport 24 | { 25 | return @{ @"locale": [self getCurrentLocale] }; 26 | } 27 | @end 28 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.1.3' 8 | } 9 | } 10 | 11 | apply plugin: 'com.android.library' 12 | 13 | android { 14 | compileSdkVersion 23 15 | buildToolsVersion "23.0.1" 16 | 17 | defaultConfig { 18 | minSdkVersion 16 19 | targetSdkVersion 22 20 | versionCode 1 21 | versionName "1.0" 22 | } 23 | lintOptions { 24 | abortOnError false 25 | } 26 | } 27 | 28 | repositories { 29 | mavenCentral() 30 | } 31 | 32 | dependencies { 33 | compile 'com.facebook.react:react-native:0.12.+' 34 | } -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/i18n/reactnativei18n/ReactNativeI18n.java: -------------------------------------------------------------------------------- 1 | package com.i18n.reactnativei18n; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Collections; 12 | 13 | 14 | public class ReactNativeI18n implements ReactPackage { 15 | 16 | @Override 17 | public List createNativeModules(ReactApplicationContext reactContext) { 18 | List modules = new ArrayList<>(); 19 | modules.add(new ReactNativeI18nLocale(reactContext)); 20 | return modules; 21 | } 22 | 23 | @Override 24 | public List> createJSModules() { 25 | return Collections.emptyList(); 26 | } 27 | 28 | @Override 29 | public List createViewManagers(ReactApplicationContext reactContext) { 30 | return Collections.emptyList(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /android/src/main/java/com/i18n/reactnativei18n/ReactNativeI18nLocale.java: -------------------------------------------------------------------------------- 1 | package com.i18n.reactnativei18n; 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext; 4 | import com.facebook.react.bridge.ReactContext; 5 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | 11 | public class ReactNativeI18nLocale extends ReactContextBaseJavaModule { 12 | 13 | ReactContext reactContext; 14 | 15 | public ReactNativeI18nLocale(ReactApplicationContext reactContext) { 16 | super(reactContext); 17 | this.reactContext = reactContext; 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return "RNI18n"; 23 | } 24 | 25 | @Override 26 | public Map getConstants() { 27 | HashMap constants = new HashMap(); 28 | constants.put("locale", reactContext.getResources().getConfiguration().locale.toString()); 29 | return constants; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { NativeModules } = require('react-native') 2 | const { RNI18n } = NativeModules 3 | 4 | export default (RNI18n) ? RNI18n.locale.replace(/_/, '-') : '' 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-locale-detector", 3 | "version": "1.0.0", 4 | "description": "Detects the locale of a user's phone.", 5 | "keywords": [ 6 | "android", 7 | "i18n", 8 | "ios", 9 | "react-native" 10 | ], 11 | "license": "MIT", 12 | "author": "Dylan Vann (dylanvann.com)", 13 | "main": "index.js", 14 | "repository": "DylanVann/react-native-locale-detector" 15 | } 16 | --------------------------------------------------------------------------------