├── .nvmrc
├── .watchmanconfig
├── example
├── .watchmanconfig
├── jest.config.js
├── app.json
├── .bundle
│ └── config
├── babel.config.js
├── android
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── values
│ │ │ │ │ │ ├── strings.xml
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ │ ├── xml
│ │ │ │ │ │ └── locales_config.xml
│ │ │ │ │ └── drawable
│ │ │ │ │ │ └── rn_edit_text_material.xml
│ │ │ │ ├── java
│ │ │ │ │ └── com
│ │ │ │ │ │ └── example
│ │ │ │ │ │ ├── MainActivity.kt
│ │ │ │ │ │ └── MainApplication.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── debug
│ │ │ │ └── AndroidManifest.xml
│ │ ├── debug.keystore
│ │ ├── proguard-rules.pro
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── settings.gradle
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradlew.bat
│ └── gradlew
├── ios
│ ├── example
│ │ ├── Images.xcassets
│ │ │ ├── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.h
│ │ ├── main.m
│ │ ├── AppDelegate.mm
│ │ ├── PrivacyInfo.xcprivacy
│ │ ├── Info.plist
│ │ └── LaunchScreen.storyboard
│ ├── Localizable.xcstrings
│ ├── example.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── .xcode.env
│ ├── exampleTests
│ │ ├── Info.plist
│ │ └── exampleTests.m
│ ├── Podfile
│ └── example.xcodeproj
│ │ └── xcshareddata
│ │ └── xcschemes
│ │ └── example.xcscheme
├── index.js
├── Gemfile
├── package.json
├── .gitignore
├── metro.config.js
├── App.tsx
├── Gemfile.lock
└── README.md
├── src
├── __tests__
│ └── index.test.tsx
├── index.tsx
├── NativeLocalizationSettings.ts
├── api.ts
└── languageDetector.ts
├── app.plugin.js
├── example-expo
├── android
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── values-night
│ │ │ │ │ │ └── colors.xml
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ ├── ic_launcher.webp
│ │ │ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ │ │ └── ic_launcher_foreground.webp
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ ├── ic_launcher.webp
│ │ │ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ │ │ └── ic_launcher_foreground.webp
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ ├── ic_launcher.webp
│ │ │ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ │ │ └── ic_launcher_foreground.webp
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ ├── ic_launcher.webp
│ │ │ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ │ │ └── ic_launcher_foreground.webp
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ ├── ic_launcher.webp
│ │ │ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ │ │ └── ic_launcher_foreground.webp
│ │ │ │ │ ├── drawable-hdpi
│ │ │ │ │ │ └── splashscreen_logo.png
│ │ │ │ │ ├── drawable-mdpi
│ │ │ │ │ │ └── splashscreen_logo.png
│ │ │ │ │ ├── drawable-xhdpi
│ │ │ │ │ │ └── splashscreen_logo.png
│ │ │ │ │ ├── drawable-xxhdpi
│ │ │ │ │ │ └── splashscreen_logo.png
│ │ │ │ │ ├── drawable-xxxhdpi
│ │ │ │ │ │ └── splashscreen_logo.png
│ │ │ │ │ ├── xml
│ │ │ │ │ │ └── locales_config.xml
│ │ │ │ │ ├── values
│ │ │ │ │ │ ├── colors.xml
│ │ │ │ │ │ ├── strings.xml
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ ├── drawable
│ │ │ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ │ │ └── rn_edit_text_material.xml
│ │ │ │ │ └── mipmap-anydpi-v26
│ │ │ │ │ │ ├── ic_launcher.xml
│ │ │ │ │ │ └── ic_launcher_round.xml
│ │ │ │ ├── AndroidManifest.xml
│ │ │ │ └── java
│ │ │ │ │ └── pl
│ │ │ │ │ └── jakubgrzywacz
│ │ │ │ │ └── exampleexpo
│ │ │ │ │ ├── MainApplication.kt
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── debug
│ │ │ │ └── AndroidManifest.xml
│ │ ├── debug.keystore
│ │ ├── proguard-rules.pro
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ ├── settings.gradle
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradlew.bat
│ └── gradlew
├── assets
│ ├── icon.png
│ ├── splash.png
│ ├── favicon.png
│ └── adaptive-icon.png
├── ios
│ ├── exampleexpo
│ │ ├── Images.xcassets
│ │ │ ├── Contents.json
│ │ │ ├── SplashScreenLogo.imageset
│ │ │ │ ├── image.png
│ │ │ │ ├── image@2x.png
│ │ │ │ ├── image@3x.png
│ │ │ │ └── Contents.json
│ │ │ ├── AppIcon.appiconset
│ │ │ │ ├── App-Icon-1024x1024@1x.png
│ │ │ │ └── Contents.json
│ │ │ └── SplashScreenBackground.colorset
│ │ │ │ └── Contents.json
│ │ ├── exampleexpo-Bridging-Header.h
│ │ ├── noop-file.swift
│ │ ├── AppDelegate.h
│ │ ├── exampleexpo.entitlements
│ │ ├── main.m
│ │ ├── Supporting
│ │ │ └── Expo.plist
│ │ ├── PrivacyInfo.xcprivacy
│ │ ├── Info.plist
│ │ ├── AppDelegate.mm
│ │ └── SplashScreen.storyboard
│ ├── Podfile.properties.json
│ ├── exampleexpo.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── Localizable.xcstrings
│ ├── .gitignore
│ ├── .xcode.env
│ ├── Podfile
│ └── exampleexpo.xcodeproj
│ │ └── xcshareddata
│ │ └── xcschemes
│ │ └── exampleexpo.xcscheme
├── babel.config.js
├── .gitignore
├── App.js
├── package.json
└── app.json
├── .gitattributes
├── tsconfig.build.json
├── babel.config.js
├── docs
├── cover.png
├── configuration-xcode-1.png
├── configuration-xcode-2.png
└── configuration-xcode-3.png
├── .yarnrc
├── android
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── localizationsettings
│ │ │ ├── LocalizationSettingsPackage.kt
│ │ │ └── LocalizationSettingsModule.kt
│ ├── newarch
│ │ └── LocalizationSettingsSpec.kt
│ └── oldarch
│ │ └── LocalizationSettingsSpec.kt
├── gradle.properties
└── build.gradle
├── plugin
├── tsconfig.json
└── src
│ ├── index.ts
│ ├── android.ts
│ └── ios.ts
├── ios
├── LocalizationSettings.h
├── LocalizationSettings.mm
└── LocalizationSettings.xcodeproj
│ └── project.pbxproj
├── .editorconfig
├── lefthook.yml
├── .github
├── actions
│ └── setup
│ │ └── action.yml
└── workflows
│ └── ci.yml
├── tsconfig.json
├── react-native-localization-settings.podspec
├── scripts
└── bootstrap.js
├── .gitignore
├── LICENSE
├── package.json
├── README.md
├── CONTRIBUTING.md
└── CODE_OF_CONDUCT.md
/.nvmrc:
--------------------------------------------------------------------------------
1 | 21.5.0
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/src/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | it.todo('write a test');
2 |
--------------------------------------------------------------------------------
/app.plugin.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./plugin/build');
2 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/values-night/colors.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'react-native',
3 | };
4 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | export * from './api';
2 | export * from './languageDetector';
3 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "displayName": "example"
4 | }
5 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 | # specific for windows script files
3 | *.bat text eol=crlf
--------------------------------------------------------------------------------
/example/.bundle/config:
--------------------------------------------------------------------------------
1 | BUNDLE_PATH: "vendor/bundle"
2 | BUNDLE_FORCE_RUBY_PLATFORM: 1
3 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig",
3 | "exclude": ["example", "plugin"]
4 | }
5 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/docs/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/docs/cover.png
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:@react-native/babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example-expo/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/assets/icon.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | example
3 |
4 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | # Override Yarn command so we can automatically setup the repo on running `yarn`
2 |
3 | yarn-path "scripts/bootstrap.js"
4 |
--------------------------------------------------------------------------------
/docs/configuration-xcode-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/docs/configuration-xcode-1.png
--------------------------------------------------------------------------------
/docs/configuration-xcode-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/docs/configuration-xcode-2.png
--------------------------------------------------------------------------------
/docs/configuration-xcode-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/docs/configuration-xcode-3.png
--------------------------------------------------------------------------------
/example-expo/assets/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/assets/splash.png
--------------------------------------------------------------------------------
/example/ios/example/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/example-expo/assets/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/assets/favicon.png
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "expo"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/example/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/debug.keystore
--------------------------------------------------------------------------------
/example-expo/assets/adaptive-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/assets/adaptive-icon.png
--------------------------------------------------------------------------------
/example-expo/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/debug.keystore
--------------------------------------------------------------------------------
/example/ios/example/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | @interface AppDelegate : RCTAppDelegate
5 |
6 | @end
7 |
--------------------------------------------------------------------------------
/example-expo/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = function (api) {
2 | api.cache(true);
3 | return {
4 | presets: ['babel-preset-expo'],
5 | };
6 | };
7 |
--------------------------------------------------------------------------------
/example-expo/ios/Podfile.properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo.jsEngine": "hermes",
3 | "EX_DEV_CLIENT_NETWORK_INSPECTOR": "true",
4 | "newArchEnabled": "false"
5 | }
6 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/exampleexpo-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Use this file to import your target's public headers that you would like to expose to Swift.
3 | //
4 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/noop-file.swift:
--------------------------------------------------------------------------------
1 | //
2 | // @generated
3 | // A blank Swift file must be created for native modules with Swift files to work correctly.
4 | //
5 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example-expo/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/ios/Localizable.xcstrings:
--------------------------------------------------------------------------------
1 | {
2 | "sourceLanguage" : "en",
3 | "strings" : {
4 | "Key" : {
5 | "extractionState" : "manual"
6 | }
7 | },
8 | "version" : "1.0"
9 | }
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import
4 |
5 | @interface AppDelegate : EXAppDelegateWrapper
6 |
7 | @end
8 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import { AppRegistry } from 'react-native';
2 | import App from './App';
3 | import { name as appName } from './app.json';
4 |
5 | AppRegistry.registerComponent(appName, () => App);
6 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable-hdpi/splashscreen_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/drawable-hdpi/splashscreen_logo.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable-mdpi/splashscreen_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/drawable-mdpi/splashscreen_logo.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable-xhdpi/splashscreen_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/drawable-xhdpi/splashscreen_logo.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable-xxhdpi/splashscreen_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/drawable-xxhdpi/splashscreen_logo.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable-xxxhdpi/splashscreen_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/drawable-xxxhdpi/splashscreen_logo.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image.png
--------------------------------------------------------------------------------
/example-expo/android/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Android/IntelliJ
6 | #
7 | build/
8 | .idea
9 | .gradle
10 | local.properties
11 | *.iml
12 | *.hprof
13 | .cxx/
14 |
15 | # Bundle artifacts
16 | *.jsbundle
17 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image@2x.png
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/image@3x.png
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | LocalizationSettings_kotlinVersion=1.7.0
2 | LocalizationSettings_minSdkVersion=21
3 | LocalizationSettings_targetSdkVersion=31
4 | LocalizationSettings_compileSdkVersion=31
5 | LocalizationSettings_ndkversion=21.4.7075529
6 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/exampleexpo.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakex7/react-native-localization-settings/HEAD/example-expo/ios/exampleexpo/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/xml/locales_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/plugin/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "expo-module-scripts/tsconfig.plugin",
3 | "compilerOptions": {
4 | "outDir": "build",
5 | "rootDir": "src"
6 | },
7 | "include": ["./src"],
8 | "exclude": ["**/__mocks__/*", "**/__tests__/*"]
9 | }
10 |
--------------------------------------------------------------------------------
/example/ios/example/main.m:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | #import "AppDelegate.h"
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | @autoreleasepool {
8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/main.m:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | #import "AppDelegate.h"
4 |
5 | int main(int argc, char * argv[]) {
6 | @autoreleasepool {
7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 | #ffffff
3 | #ffffff
4 | #023c69
5 | #ffffff
6 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/xml/locales_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android/src/newarch/LocalizationSettingsSpec.kt:
--------------------------------------------------------------------------------
1 | package com.localizationsettings
2 |
3 | import com.facebook.react.bridge.ReactApplicationContext
4 |
5 | abstract class LocalizationSettingsSpec internal constructor(context: ReactApplicationContext) :
6 | NativeLocalizationSettingsSpec(context) {
7 | }
8 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | example-expo
3 | contain
4 | false
5 |
--------------------------------------------------------------------------------
/example/ios/example.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/example-expo/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ios/LocalizationSettings.h:
--------------------------------------------------------------------------------
1 |
2 | #ifdef RCT_NEW_ARCH_ENABLED
3 | #import "RNLocalizationSettingsSpec.h"
4 |
5 | @interface LocalizationSettings : NSObject
6 | #else
7 | #import
8 |
9 | @interface LocalizationSettings : NSObject
10 | #endif
11 |
12 | @end
13 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "filename": "App-Icon-1024x1024@1x.png",
5 | "idiom": "universal",
6 | "platform": "ios",
7 | "size": "1024x1024"
8 | }
9 | ],
10 | "info": {
11 | "version": 1,
12 | "author": "expo"
13 | }
14 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | indent_style = space
10 | indent_size = 2
11 |
12 | end_of_line = lf
13 | charset = utf-8
14 | trim_trailing_whitespace = true
15 | insert_final_newline = true
16 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
2 | plugins { id("com.facebook.react.settings") }
3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
4 | rootProject.name = 'example'
5 | include ':app'
6 | includeBuild('../node_modules/@react-native/gradle-plugin')
7 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
--------------------------------------------------------------------------------
/example/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4 | ruby ">= 2.6.10"
5 |
6 | # Exclude problematic versions of cocoapods and activesupport that causes build failures.
7 | gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
8 | gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
9 | gem 'xcodeproj', '< 1.26.0'
10 |
--------------------------------------------------------------------------------
/example-expo/ios/Localizable.xcstrings:
--------------------------------------------------------------------------------
1 | {
2 | "sourceLanguage" : "en",
3 | "strings" : {
4 | "react-native-localization-settings" : {
5 | "extractionState" : "manual",
6 | "localizations" : {
7 | "en" : {"stringUnit" : {"state" : "translated","value" : ""}},
8 | "pl" : {"stringUnit" : {"state" : "translated","value" : ""}},
9 | }
10 | }
11 | },
12 | "version" : "1.0"
13 | }
--------------------------------------------------------------------------------
/src/NativeLocalizationSettings.ts:
--------------------------------------------------------------------------------
1 | import type { TurboModule } from 'react-native';
2 | import { TurboModuleRegistry } from 'react-native';
3 |
4 | export interface Spec extends TurboModule {
5 | getLanguage(): Promise;
6 | setLanguage(lang: string): void;
7 | getConstants(): {
8 | language: string;
9 | };
10 | }
11 |
12 | export default TurboModuleRegistry.getEnforcing('LocalizationSettings');
13 |
--------------------------------------------------------------------------------
/lefthook.yml:
--------------------------------------------------------------------------------
1 | pre-commit:
2 | parallel: true
3 | commands:
4 | lint:
5 | files: git diff --name-only @{push}
6 | glob: "*.{js,ts,jsx,tsx}"
7 | run: npx eslint {files}
8 | types:
9 | files: git diff --name-only @{push}
10 | glob: "*.{js,ts, jsx, tsx}"
11 | run: npx tsc --noEmit
12 | commit-msg:
13 | parallel: true
14 | commands:
15 | commitlint:
16 | run: npx commitlint --edit
17 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Supporting/Expo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | EXUpdatesCheckOnLaunch
6 | ALWAYS
7 | EXUpdatesEnabled
8 |
9 | EXUpdatesLaunchWaitMs
10 | 0
11 |
12 |
--------------------------------------------------------------------------------
/example-expo/ios/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 | .xcode.env.local
25 |
26 | # Bundle artifacts
27 | *.jsbundle
28 |
29 | # CocoaPods
30 | /Pods/
31 |
--------------------------------------------------------------------------------
/example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenBackground.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors": [
3 | {
4 | "color": {
5 | "components": {
6 | "alpha": "1.000",
7 | "blue": "1.00000000000000",
8 | "green": "1.00000000000000",
9 | "red": "1.00000000000000"
10 | },
11 | "color-space": "srgb"
12 | },
13 | "idiom": "universal"
14 | }
15 | ],
16 | "info": {
17 | "version": 1,
18 | "author": "expo"
19 | }
20 | }
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Images.xcassets/SplashScreenLogo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "idiom": "universal",
5 | "filename": "image.png",
6 | "scale": "1x"
7 | },
8 | {
9 | "idiom": "universal",
10 | "filename": "image@2x.png",
11 | "scale": "2x"
12 | },
13 | {
14 | "idiom": "universal",
15 | "filename": "image@3x.png",
16 | "scale": "3x"
17 | }
18 | ],
19 | "info": {
20 | "version": 1,
21 | "author": "expo"
22 | }
23 | }
--------------------------------------------------------------------------------
/example/ios/.xcode.env:
--------------------------------------------------------------------------------
1 | # This `.xcode.env` file is versioned and is used to source the environment
2 | # used when running script phases inside Xcode.
3 | # To customize your local environment, you can create an `.xcode.env.local`
4 | # file that is not versioned.
5 |
6 | # NODE_BINARY variable contains the PATH to the node executable.
7 | #
8 | # Customize the NODE_BINARY variable here.
9 | # For example, to use nvm with brew, add the following line
10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use
11 | export NODE_BINARY=$(command -v node)
12 |
--------------------------------------------------------------------------------
/example-expo/ios/.xcode.env:
--------------------------------------------------------------------------------
1 | # This `.xcode.env` file is versioned and is used to source the environment
2 | # used when running script phases inside Xcode.
3 | # To customize your local environment, you can create an `.xcode.env.local`
4 | # file that is not versioned.
5 |
6 | # NODE_BINARY variable contains the PATH to the node executable.
7 | #
8 | # Customize the NODE_BINARY variable here.
9 | # For example, to use nvm with brew, add the following line
10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use
11 | export NODE_BINARY=$(command -v node)
12 |
--------------------------------------------------------------------------------
/example-expo/.gitignore:
--------------------------------------------------------------------------------
1 | # Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2 |
3 | # dependencies
4 | node_modules/
5 |
6 | # Expo
7 | .expo/
8 | dist/
9 | web-build/
10 |
11 | # Native
12 | *.orig.*
13 | *.jks
14 | *.p8
15 | *.p12
16 | *.key
17 | *.mobileprovision
18 |
19 | # Metro
20 | .metro-health-check*
21 |
22 | # debug
23 | npm-debug.*
24 | yarn-debug.*
25 | yarn-error.*
26 |
27 | # macOS
28 | .DS_Store
29 | *.pem
30 |
31 | # local env files
32 | .env*.local
33 |
34 | # typescript
35 | *.tsbuildinfo
36 |
--------------------------------------------------------------------------------
/example-expo/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { StatusBar } from 'expo-status-bar';
3 | import { StyleSheet, Text, View } from 'react-native';
4 |
5 | export default function App() {
6 | return (
7 |
8 | Open up App.js to start working on your app!
9 |
10 |
11 | );
12 | }
13 |
14 | const styles = StyleSheet.create({
15 | container: {
16 | flex: 1,
17 | backgroundColor: '#fff',
18 | alignItems: 'center',
19 | justifyContent: 'center',
20 | },
21 | });
22 |
--------------------------------------------------------------------------------
/plugin/src/index.ts:
--------------------------------------------------------------------------------
1 | import { ConfigPlugin } from '@expo/config-plugins';
2 | import { withAndroidLanguages } from './android';
3 | import { withIosLanguages } from './ios';
4 |
5 | const withReactNativeLocalizationSettings: ConfigPlugin<{
6 | defaultLanguage?: string;
7 | languages?: string[];
8 | }> = (config, { defaultLanguage, languages = [] } = {}) => {
9 | config = withAndroidLanguages(config, { languages });
10 | config = withIosLanguages(config, { defaultLanguage, languages });
11 |
12 | return config;
13 | };
14 |
15 | export default withReactNativeLocalizationSettings;
16 |
--------------------------------------------------------------------------------
/example-expo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example-expo",
3 | "version": "1.0.0",
4 | "main": "expo/AppEntry.js",
5 | "scripts": {
6 | "start": "expo start",
7 | "android": "expo run:android",
8 | "ios": "expo run:ios",
9 | "web": "expo start --web"
10 | },
11 | "dependencies": {
12 | "expo": "^52.0.37",
13 | "expo-status-bar": "~2.0.1",
14 | "react": "18.3.1",
15 | "react-native": "0.76.7",
16 | "react-native-localization-settings": "link:.."
17 | },
18 | "devDependencies": {
19 | "@babel/core": "^7.20.0"
20 | },
21 | "private": true
22 | }
23 |
--------------------------------------------------------------------------------
/example-expo/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # react-native-reanimated
11 | -keep class com.swmansion.reanimated.** { *; }
12 | -keep class com.facebook.react.turbomodule.** { *; }
13 |
14 | # Add any project specific keep options here:
15 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | buildToolsVersion = "35.0.0"
4 | minSdkVersion = 24
5 | compileSdkVersion = 35
6 | targetSdkVersion = 34
7 | ndkVersion = "26.1.10909125"
8 | kotlinVersion = "1.9.24"
9 | }
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | dependencies {
15 | classpath("com.android.tools.build:gradle")
16 | classpath("com.facebook.react:react-native-gradle-plugin")
17 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
18 | }
19 | }
20 |
21 | apply plugin: "com.facebook.react.rootproject"
22 |
--------------------------------------------------------------------------------
/android/src/oldarch/LocalizationSettingsSpec.kt:
--------------------------------------------------------------------------------
1 | package com.localizationsettings
2 |
3 | import com.facebook.react.bridge.ReactApplicationContext
4 | import com.facebook.react.bridge.ReactContextBaseJavaModule
5 | import com.facebook.react.bridge.Promise
6 |
7 | abstract class LocalizationSettingsSpec internal constructor(context: ReactApplicationContext) :
8 | ReactContextBaseJavaModule(context) {
9 |
10 | abstract fun getLanguage(promise: Promise)
11 | abstract fun setLanguage(language: String)
12 | abstract fun getTypedExportedConstants(): Map?
13 | override fun getConstants(): Map? {
14 | return getTypedExportedConstants()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.github/actions/setup/action.yml:
--------------------------------------------------------------------------------
1 | name: Setup
2 | description: Setup Node.js and install dependencies
3 |
4 | runs:
5 | using: composite
6 | steps:
7 | - name: Setup Node.js
8 | uses: actions/setup-node@v3
9 | with:
10 | node-version-file: .nvmrc
11 |
12 | - name: Cache dependencies
13 | id: yarn-cache
14 | uses: actions/cache@v3
15 | with:
16 | path: |
17 | **/node_modules
18 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
19 | restore-keys: |
20 | ${{ runner.os }}-yarn-
21 |
22 | - name: Install dependencies
23 | if: steps.yarn-cache.outputs.cache-hit != 'true'
24 | run: |
25 | yarn install --cwd example --frozen-lockfile
26 | yarn install --frozen-lockfile
27 | shell: bash
28 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": "./",
4 | "paths": {
5 | "react-native-localization-settings": ["./src/index"]
6 | },
7 | "allowUnreachableCode": false,
8 | "allowUnusedLabels": false,
9 | "esModuleInterop": true,
10 | "forceConsistentCasingInFileNames": true,
11 | "jsx": "react",
12 | "lib": ["esnext"],
13 | "module": "esnext",
14 | "moduleResolution": "node",
15 | "noFallthroughCasesInSwitch": true,
16 | "noImplicitReturns": true,
17 | "noImplicitUseStrict": false,
18 | "noStrictGenericChecks": false,
19 | "noUncheckedIndexedAccess": true,
20 | "noUnusedLocals": true,
21 | "noUnusedParameters": true,
22 | "resolveJsonModule": true,
23 | "skipLibCheck": true,
24 | "strict": true,
25 | "target": "esnext"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/example/ios/exampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/react-native-localization-settings.podspec:
--------------------------------------------------------------------------------
1 | require "json"
2 |
3 | package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4 |
5 | Pod::Spec.new do |s|
6 | s.name = "react-native-localization-settings"
7 | s.version = package["version"]
8 | s.summary = package["description"]
9 | s.homepage = package["homepage"]
10 | s.license = package["license"]
11 | s.authors = package["author"]
12 |
13 | s.platforms = { :ios => "11.0" }
14 | s.source = { :git => "https://github.com/jakex7/react-native-localization-settings.git", :tag => "#{s.version}" }
15 |
16 | s.source_files = "ios/**/*.{h,m,mm}"
17 |
18 | s.dependency "React-Core"
19 |
20 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
21 | install_modules_dependencies(s)
22 | else
23 | s.dependency 'React-Core'
24 | end
25 |
26 | end
27 |
--------------------------------------------------------------------------------
/scripts/bootstrap.js:
--------------------------------------------------------------------------------
1 | const os = require('os');
2 | const path = require('path');
3 | const child_process = require('child_process');
4 |
5 | const root = path.resolve(__dirname, '..');
6 | const args = process.argv.slice(2);
7 | const options = {
8 | cwd: process.cwd(),
9 | env: process.env,
10 | stdio: 'inherit',
11 | encoding: 'utf-8',
12 | };
13 |
14 | if (os.type() === 'Windows_NT') {
15 | options.shell = true;
16 | }
17 |
18 | let result;
19 |
20 | if (process.cwd() !== root || args.length) {
21 | // We're not in the root of the project, or additional arguments were passed
22 | // In this case, forward the command to `yarn`
23 | result = child_process.spawnSync('yarn', args, options);
24 | } else {
25 | // If `yarn` is run without arguments, perform bootstrap
26 | result = child_process.spawnSync('yarn', ['bootstrap'], options);
27 | }
28 |
29 | process.exitCode = result.status;
30 |
--------------------------------------------------------------------------------
/example/ios/example/AppDelegate.mm:
--------------------------------------------------------------------------------
1 | #import "AppDelegate.h"
2 |
3 | #import
4 |
5 | @implementation AppDelegate
6 |
7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
8 | {
9 | self.moduleName = @"example";
10 | // You can add your custom initial props in the dictionary below.
11 | // They will be passed down to the ViewController used by React Native.
12 | self.initialProps = @{};
13 |
14 | return [super application:application didFinishLaunchingWithOptions:launchOptions];
15 | }
16 |
17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
18 | {
19 | return [self bundleURL];
20 | }
21 |
22 | - (NSURL *)bundleURL
23 | {
24 | #if DEBUG
25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
26 | #else
27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
28 | #endif
29 | }
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
17 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example
2 |
3 | import com.facebook.react.ReactActivity
4 | import com.facebook.react.ReactActivityDelegate
5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
6 | import com.facebook.react.defaults.DefaultReactActivityDelegate
7 |
8 | class MainActivity : ReactActivity() {
9 |
10 | /**
11 | * Returns the name of the main component registered from JavaScript. This is used to schedule
12 | * rendering of the component.
13 | */
14 | override fun getMainComponentName(): String = "example"
15 |
16 | /**
17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
19 | */
20 | override fun createReactActivityDelegate(): ReactActivityDelegate =
21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
22 | }
23 |
--------------------------------------------------------------------------------
/example-expo/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "name": "example-expo",
4 | "slug": "example-expo",
5 | "version": "1.0.0",
6 | "orientation": "portrait",
7 | "icon": "./assets/icon.png",
8 | "userInterfaceStyle": "light",
9 | "splash": {
10 | "image": "./assets/splash.png",
11 | "resizeMode": "contain",
12 | "backgroundColor": "#ffffff"
13 | },
14 | "ios": {
15 | "supportsTablet": true,
16 | "bundleIdentifier": "pl.jakubgrzywacz.exampleexpo"
17 | },
18 | "android": {
19 | "adaptiveIcon": {
20 | "foregroundImage": "./assets/adaptive-icon.png",
21 | "backgroundColor": "#ffffff"
22 | },
23 | "package": "pl.jakubgrzywacz.exampleexpo"
24 | },
25 | "web": {
26 | "favicon": "./assets/favicon.png"
27 | },
28 | "plugins": [
29 | [
30 | "../app.plugin.js",
31 | {
32 | "languages": ["en", "pl"]
33 | }
34 | ]
35 | ]
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # XDE
6 | .expo/
7 |
8 | # VSCode
9 | .vscode/
10 | jsconfig.json
11 |
12 | # Xcode
13 | #
14 | build/
15 | *.pbxuser
16 | !default.pbxuser
17 | *.mode1v3
18 | !default.mode1v3
19 | *.mode2v3
20 | !default.mode2v3
21 | *.perspectivev3
22 | !default.perspectivev3
23 | xcuserdata
24 | *.xccheckout
25 | *.moved-aside
26 | DerivedData
27 | *.hmap
28 | *.ipa
29 | *.xcuserstate
30 | project.xcworkspace
31 |
32 | # Android/IJ
33 | #
34 | .classpath
35 | .cxx
36 | .gradle
37 | .idea
38 | .project
39 | .settings
40 | local.properties
41 | android.iml
42 |
43 | # Cocoapods
44 | #
45 | example/ios/Pods
46 |
47 | # Ruby
48 | example/vendor/
49 |
50 | # node.js
51 | #
52 | node_modules/
53 | npm-debug.log
54 | yarn-debug.log
55 | yarn-error.log
56 |
57 | # BUCK
58 | buck-out/
59 | \.buckd/
60 | android/app/libs
61 | android/keystores/debug.keystore
62 |
63 | # Expo
64 | .expo/
65 | tsconfig.tsbuildinfo
66 |
67 | # Turborepo
68 | .turbo/
69 |
70 | # generated by bob
71 | lib/
72 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | push:
4 | branches:
5 | - main
6 | pull_request:
7 | branches:
8 | - main
9 |
10 | jobs:
11 | lint:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - name: Checkout
15 | uses: actions/checkout@v3
16 |
17 | - name: Setup
18 | uses: ./.github/actions/setup
19 |
20 | - name: Lint files
21 | run: yarn lint
22 |
23 | - name: Typecheck files
24 | run: yarn typecheck
25 |
26 | test:
27 | runs-on: ubuntu-latest
28 | steps:
29 | - name: Checkout
30 | uses: actions/checkout@v3
31 |
32 | - name: Setup
33 | uses: ./.github/actions/setup
34 |
35 | - name: Run unit tests
36 | run: yarn test --maxWorkers=2 --coverage
37 |
38 | build:
39 | runs-on: ubuntu-latest
40 | steps:
41 | - name: Checkout
42 | uses: actions/checkout@v3
43 |
44 | - name: Setup
45 | uses: ./.github/actions/setup
46 |
47 | - name: Build package
48 | run: yarn prepack
49 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "android": "react-native run-android",
7 | "ios": "react-native run-ios",
8 | "start": "react-native start",
9 | "pods": "pod-install --quiet"
10 | },
11 | "dependencies": {
12 | "i18next": "23.16.5",
13 | "react": "18.3.1",
14 | "react-i18next": "15.1.1",
15 | "react-native": "0.76.1",
16 | "react-native-localization-settings": "link:.."
17 | },
18 | "devDependencies": {
19 | "@babel/core": "^7.25.2",
20 | "@babel/preset-env": "^7.25.3",
21 | "@babel/runtime": "^7.25.0",
22 | "@react-native-community/cli": "15.0.0",
23 | "@react-native-community/cli-platform-android": "15.0.0",
24 | "@react-native-community/cli-platform-ios": "15.0.0",
25 | "@react-native/babel-preset": "0.76.1",
26 | "@react-native/metro-config": "0.76.1",
27 | "@react-native/typescript-config": "0.76.1",
28 | "@types/react": "^18.2.6",
29 | "prettier": "2.8.8",
30 | "typescript": "5.0.4"
31 | },
32 | "engines": {
33 | "node": ">=18"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Jakub Grzywacz
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
--------------------------------------------------------------------------------
/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "scale" : "1x",
46 | "size" : "1024x1024"
47 | }
48 | ],
49 | "info" : {
50 | "author" : "xcode",
51 | "version" : 1
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/ios/example/PrivacyInfo.xcprivacy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrivacyAccessedAPITypes
6 |
7 |
8 | NSPrivacyAccessedAPIType
9 | NSPrivacyAccessedAPICategoryFileTimestamp
10 | NSPrivacyAccessedAPITypeReasons
11 |
12 | C617.1
13 |
14 |
15 |
16 | NSPrivacyAccessedAPIType
17 | NSPrivacyAccessedAPICategoryUserDefaults
18 | NSPrivacyAccessedAPITypeReasons
19 |
20 | CA92.1
21 |
22 |
23 |
24 | NSPrivacyAccessedAPIType
25 | NSPrivacyAccessedAPICategorySystemBootTime
26 | NSPrivacyAccessedAPITypeReasons
27 |
28 | 35F9.1
29 |
30 |
31 |
32 | NSPrivacyCollectedDataTypes
33 |
34 | NSPrivacyTracking
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Resolve react_native_pods.rb with node to allow for hoisting
2 | require Pod::Executable.execute_command('node', ['-p',
3 | 'require.resolve(
4 | "react-native/scripts/react_native_pods.rb",
5 | {paths: [process.argv[1]]},
6 | )', __dir__]).strip
7 |
8 | platform :ios, min_ios_version_supported
9 | prepare_react_native_project!
10 |
11 | linkage = ENV['USE_FRAMEWORKS']
12 | if linkage != nil
13 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
14 | use_frameworks! :linkage => linkage.to_sym
15 | end
16 |
17 | target 'example' do
18 | config = use_native_modules!
19 |
20 | use_react_native!(
21 | :path => config[:reactNativePath],
22 | # An absolute path to your application root.
23 | :app_path => "#{Pod::Config.instance.installation_root}/.."
24 | )
25 |
26 | target 'exampleTests' do
27 | inherit! :complete
28 | # Pods for testing
29 | end
30 |
31 | post_install do |installer|
32 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
33 | react_native_post_install(
34 | installer,
35 | config[:reactNativePath],
36 | :mac_catalyst_enabled => false,
37 | # :ccache_enabled => true
38 | )
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | **/.xcode.env.local
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 | *.hprof
33 | .cxx/
34 | *.keystore
35 | !debug.keystore
36 |
37 | # node.js
38 | #
39 | node_modules/
40 | npm-debug.log
41 | yarn-error.log
42 |
43 | # fastlane
44 | #
45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
46 | # screenshots whenever they are needed.
47 | # For more information about the recommended setup visit:
48 | # https://docs.fastlane.tools/best-practices/source-control/
49 |
50 | **/fastlane/report.xml
51 | **/fastlane/Preview.html
52 | **/fastlane/screenshots
53 | **/fastlane/test_output
54 |
55 | # Bundle artifact
56 | *.jsbundle
57 |
58 | # Ruby / CocoaPods
59 | **/Pods/
60 | /vendor/bundle/
61 |
62 | # Temporary files created by Metro to check the health of the file watcher
63 | .metro-health-check*
64 |
65 | # testing
66 | /coverage
67 |
68 | # Yarn
69 | .yarn/*
70 | !.yarn/patches
71 | !.yarn/plugins
72 | !.yarn/releases
73 | !.yarn/sdks
74 | !.yarn/versions
75 |
--------------------------------------------------------------------------------
/plugin/src/android.ts:
--------------------------------------------------------------------------------
1 | import {
2 | AndroidConfig,
3 | ConfigPlugin,
4 | withAndroidManifest,
5 | } from '@expo/config-plugins';
6 | import path from 'path';
7 | import fs from 'fs';
8 |
9 | export const withAndroidLanguages: ConfigPlugin<{
10 | languages?: string[];
11 | }> = (config, { languages = [] } = {}) => {
12 | config = withAndroidManifest(config, (config) => {
13 | const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(
14 | config.modResults
15 | );
16 |
17 | // Add the `android:localeConfig` attribute to the `` tag
18 | mainApplication.$['android:localeConfig'] = '@xml/locales_config';
19 |
20 | const localesConfigPath = path.join(
21 | config.modRequest.platformProjectRoot,
22 | 'app/src/main/res/xml/locales_config.xml'
23 | );
24 | // Ensure the `res/xml` directory exists
25 | fs.mkdirSync(path.dirname(localesConfigPath), { recursive: true });
26 |
27 | // Prepare locales_config.xml content
28 | const xmlContent = `
29 |
30 | ${languages.map((lang) => ``).join('\n ')}
31 | `;
32 |
33 | // Write the `res/xml/locales_config.xml` file
34 | fs.writeFileSync(localesConfigPath, xmlContent);
35 |
36 | return config;
37 | });
38 |
39 | return config;
40 | };
41 |
--------------------------------------------------------------------------------
/android/src/main/java/com/localizationsettings/LocalizationSettingsPackage.kt:
--------------------------------------------------------------------------------
1 | package com.localizationsettings
2 |
3 | import com.facebook.react.TurboReactPackage
4 | import com.facebook.react.bridge.ReactApplicationContext
5 | import com.facebook.react.bridge.NativeModule
6 | import com.facebook.react.module.model.ReactModuleInfoProvider
7 | import com.facebook.react.module.model.ReactModuleInfo
8 | import java.util.HashMap
9 |
10 | class LocalizationSettingsPackage : TurboReactPackage() {
11 | override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12 | return if (name == LocalizationSettingsModule.NAME) {
13 | LocalizationSettingsModule(reactContext)
14 | } else {
15 | null
16 | }
17 | }
18 |
19 | override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20 | return ReactModuleInfoProvider {
21 | val moduleInfos: MutableMap = HashMap()
22 | val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
23 | moduleInfos[LocalizationSettingsModule.NAME] = ReactModuleInfo(
24 | LocalizationSettingsModule.NAME,
25 | LocalizationSettingsModule.NAME,
26 | false, // canOverrideExistingModule
27 | false, // needsEagerInit
28 | true, // hasConstants
29 | false, // isCxxModule
30 | isTurboModule // isTurboModule
31 | )
32 | moduleInfos
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
2 | const exclusionList = require('metro-config/src/defaults/exclusionList');
3 | const path = require('path');
4 | const escape = require('escape-string-regexp');
5 | const pack = require('../package.json');
6 |
7 | const root = path.resolve(__dirname, '..');
8 | const projectNodeModules = path.join(__dirname, 'node_modules');
9 |
10 | const modules = [...Object.keys(pack.peerDependencies)];
11 |
12 | const config = {
13 | projectRoot: __dirname,
14 | watchFolders: [root],
15 |
16 | // We need to make sure that only one version is loaded for peerDependencies
17 | // So we exclude them at the root, and alias them to the versions in example's node_modules
18 | resolver: {
19 | blacklistRE: exclusionList(
20 | modules.map(
21 | (m) =>
22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
23 | )
24 | ),
25 | nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../')],
26 | extraNodeModules: modules.reduce((acc, name) => {
27 | acc[name] = path.join(__dirname, 'node_modules', name);
28 | return acc;
29 | }, {}),
30 | },
31 |
32 | transformer: {
33 | getTransformOptions: async () => ({
34 | transform: {
35 | experimentalImportSupport: false,
36 | inlineRequires: true,
37 | },
38 | }),
39 | },
40 | };
41 |
42 | module.exports = mergeConfig(getDefaultConfig(__dirname), config);
43 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/PrivacyInfo.xcprivacy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrivacyAccessedAPITypes
6 |
7 |
8 | NSPrivacyAccessedAPIType
9 | NSPrivacyAccessedAPICategoryUserDefaults
10 | NSPrivacyAccessedAPITypeReasons
11 |
12 | CA92.1
13 |
14 |
15 |
16 | NSPrivacyAccessedAPIType
17 | NSPrivacyAccessedAPICategoryFileTimestamp
18 | NSPrivacyAccessedAPITypeReasons
19 |
20 | 0A2A.1
21 | 3B52.1
22 | C617.1
23 |
24 |
25 |
26 | NSPrivacyAccessedAPIType
27 | NSPrivacyAccessedAPICategoryDiskSpace
28 | NSPrivacyAccessedAPITypeReasons
29 |
30 | E174.1
31 | 85F4.1
32 |
33 |
34 |
35 | NSPrivacyAccessedAPIType
36 | NSPrivacyAccessedAPICategorySystemBootTime
37 | NSPrivacyAccessedAPITypeReasons
38 |
39 | 35F9.1
40 |
41 |
42 |
43 | NSPrivacyCollectedDataTypes
44 |
45 | NSPrivacyTracking
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/plugin/src/ios.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ConfigPlugin,
3 | IOSConfig,
4 | withXcodeProject,
5 | } from '@expo/config-plugins';
6 |
7 | const generateLocalizableContent = (
8 | languages: string[],
9 | defaultLanguage?: string
10 | ) => `{
11 | "sourceLanguage" : "${defaultLanguage || languages[0]}",
12 | "strings" : {
13 | "react-native-localization-settings" : {
14 | "extractionState" : "manual",
15 | "localizations" : {
16 | ${languages
17 | .map(
18 | (lang) =>
19 | `"${lang}" : {"stringUnit" : {"state" : "translated","value" : ""}},`
20 | )
21 | .join('\n ')}
22 | }
23 | }
24 | },
25 | "version" : "1.0"
26 | }`;
27 |
28 | export const withIosLanguages: ConfigPlugin<{
29 | defaultLanguage?: string;
30 | languages?: string[];
31 | }> = (config, { defaultLanguage, languages = [] } = {}) => {
32 | config = withXcodeProject(config, (config) => {
33 | const project = config.modResults;
34 | const projectObject =
35 | project.pbxProjectSection()[project.getFirstProject().uuid];
36 | if (projectObject) {
37 | // Add known regions to the project
38 | projectObject.knownRegions = languages;
39 |
40 | // Write the Localizable.xcstrings file
41 | IOSConfig.XcodeProjectFile.createBuildSourceFile({
42 | project,
43 | nativeProjectRoot: config.modRequest.platformProjectRoot,
44 | filePath: 'Localizable.xcstrings',
45 | fileContents: generateLocalizableContent(languages, defaultLanguage),
46 | overwrite: true,
47 | });
48 | }
49 | return config;
50 | });
51 | return config;
52 | };
53 |
--------------------------------------------------------------------------------
/example-expo/android/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().toString())
3 | }
4 | plugins { id("com.facebook.react.settings") }
5 |
6 | extensions.configure(com.facebook.react.ReactSettingsExtension) { ex ->
7 | if (System.getenv('EXPO_USE_COMMUNITY_AUTOLINKING') == '1') {
8 | ex.autolinkLibrariesFromCommand()
9 | } else {
10 | def command = [
11 | 'node',
12 | '--no-warnings',
13 | '--eval',
14 | 'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
15 | 'react-native-config',
16 | '--json',
17 | '--platform',
18 | 'android'
19 | ].toList()
20 | ex.autolinkLibrariesFromCommand(command)
21 | }
22 | }
23 |
24 | rootProject.name = 'example-expo'
25 |
26 | dependencyResolutionManagement {
27 | versionCatalogs {
28 | reactAndroidLibs {
29 | from(files(new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../gradle/libs.versions.toml")))
30 | }
31 | }
32 | }
33 |
34 | apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle");
35 | useExpoModules()
36 |
37 | include ':app'
38 | includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile())
39 |
--------------------------------------------------------------------------------
/example-expo/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext {
5 | buildToolsVersion = findProperty('android.buildToolsVersion') ?: '35.0.0'
6 | minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '24')
7 | compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '35')
8 | targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
9 | kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.25'
10 |
11 | ndkVersion = "26.1.10909125"
12 | }
13 | repositories {
14 | google()
15 | mavenCentral()
16 | }
17 | dependencies {
18 | classpath('com.android.tools.build:gradle')
19 | classpath('com.facebook.react:react-native-gradle-plugin')
20 | classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')
21 | }
22 | }
23 |
24 | apply plugin: "com.facebook.react.rootproject"
25 |
26 | allprojects {
27 | repositories {
28 | maven {
29 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
30 | url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
31 | }
32 | maven {
33 | // Android JSC is installed from npm
34 | url(new File(['node', '--print', "require.resolve('jsc-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), '../dist'))
35 | }
36 |
37 | google()
38 | mavenCentral()
39 | maven { url 'https://www.jitpack.io' }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/example/ios/example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(MARKETING_VERSION)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(CURRENT_PROJECT_VERSION)
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 |
30 | NSAllowsArbitraryLoads
31 |
32 | NSAllowsLocalNetworking
33 |
34 |
35 | NSLocationWhenInUseUsageDescription
36 |
37 | UILaunchStoryboardName
38 | LaunchScreen
39 | UIRequiredDeviceCapabilities
40 |
41 | arm64
42 |
43 | UISupportedInterfaceOrientations
44 |
45 | UIInterfaceOrientationPortrait
46 | UIInterfaceOrientationLandscapeLeft
47 | UIInterfaceOrientationLandscapeRight
48 |
49 | UIViewControllerBasedStatusBarAppearance
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/MainApplication.kt:
--------------------------------------------------------------------------------
1 | package com.example
2 |
3 | import android.app.Application
4 | import com.facebook.react.PackageList
5 | import com.facebook.react.ReactApplication
6 | import com.facebook.react.ReactHost
7 | import com.facebook.react.ReactNativeHost
8 | import com.facebook.react.ReactPackage
9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
11 | import com.facebook.react.defaults.DefaultReactNativeHost
12 | import com.facebook.react.soloader.OpenSourceMergedSoMapping
13 | import com.facebook.soloader.SoLoader
14 |
15 | class MainApplication : Application(), ReactApplication {
16 |
17 | override val reactNativeHost: ReactNativeHost =
18 | object : DefaultReactNativeHost(this) {
19 | override fun getPackages(): List =
20 | PackageList(this).packages.apply {
21 | // Packages that cannot be autolinked yet can be added manually here, for example:
22 | // add(MyReactNativePackage())
23 | }
24 |
25 | override fun getJSMainModuleName(): String = "index"
26 |
27 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
28 |
29 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
30 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
31 | }
32 |
33 | override val reactHost: ReactHost
34 | get() = getDefaultReactHost(applicationContext, reactNativeHost)
35 |
36 | override fun onCreate() {
37 | super.onCreate()
38 | SoLoader.init(this, OpenSourceMergedSoMapping)
39 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
40 | // If you opted-in for the New Architecture, we load the native entry point for this app.
41 | load()
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | # AndroidX package structure to make it clearer which packages are bundled with the
21 | # Android operating system, and which are packaged with your app's APK
22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
23 | android.useAndroidX=true
24 |
25 | # Use this property to specify which architecture you want to build.
26 | # You can also override it from the CLI using
27 | # ./gradlew -PreactNativeArchitectures=x86_64
28 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
29 |
30 | # Use this property to enable support to the new architecture.
31 | # This will allow you to use TurboModules and the Fabric render in
32 | # your application. You should enable this flag either if you want
33 | # to write custom TurboModules/Fabric components OR use libraries that
34 | # are providing them.
35 | newArchEnabled=true
36 |
37 | # Use this property to enable or disable the Hermes JS engine.
38 | # If set to false, you will be using JSC instead.
39 | hermesEnabled=true
40 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/rn_edit_text_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
22 |
23 |
24 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/res/drawable/rn_edit_text_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
22 |
23 |
24 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/api.ts:
--------------------------------------------------------------------------------
1 | import { NativeModules, Platform } from 'react-native';
2 |
3 | const LINKING_ERROR =
4 | `The package 'react-native-localization-settings' doesn't seem to be linked. Make sure: \n\n` +
5 | Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6 | '- You rebuilt the app after installing the package\n' +
7 | '- You are not using Expo Go\n';
8 |
9 | // @ts-expect-error
10 | const isTurboModuleEnabled = global.__turboModuleProxy != null;
11 |
12 | const LocalizationSettingsModule = isTurboModuleEnabled
13 | ? require('./NativeLocalizationSettings').default
14 | : NativeModules.LocalizationSettings;
15 |
16 | const LocalizationSettings = LocalizationSettingsModule
17 | ? LocalizationSettingsModule
18 | : new Proxy(
19 | {},
20 | {
21 | get() {
22 | throw new Error(LINKING_ERROR);
23 | },
24 | }
25 | );
26 |
27 | /**
28 | * Get language (sync)
29 | * @returns Language in IETF BCP 47 format (like 'en-US')
30 | * @example
31 | * console.log(getLanguage())
32 | */
33 | export function getLanguage(): string {
34 | return LocalizationSettings.getConstants().language.split('_')[0];
35 | }
36 |
37 | /**
38 | * Get language (async)
39 | * @param fallback - fallback language
40 | * @returns Promise with Language in IETF BCP 47 format (like 'en-US')
41 | * @example
42 | * getLanguageAsync().then(console.log)
43 | */
44 | export function getLanguageAsync(fallback?: string): Promise {
45 | return LocalizationSettings.getLanguage()
46 | .then((res: string) => res.split('_'))
47 | .then((res: string[]) => {
48 | if (res[0]) {
49 | return res[0];
50 | }
51 | if (fallback) {
52 | return fallback;
53 | }
54 | throw new Error('Invalid language format');
55 | });
56 | }
57 |
58 | /**
59 | * Set language
60 | * @param language - locale string
61 | * @example
62 | * Usage:
63 | * setLanguage('en-US')
64 | *
65 | * Preferred format:
66 | * IETF BCP 47 format - "en-US"
67 | *
68 | * Other:
69 | * ISO 639-1 format - "en"
70 | *
71 | */
72 | export function setLanguage(language: string): void {
73 | LocalizationSettings.setLanguage(language);
74 | }
75 |
--------------------------------------------------------------------------------
/example/App.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { StyleSheet, View, Text, Button } from 'react-native';
3 | import i18next from 'i18next';
4 | import { initReactI18next, useTranslation } from 'react-i18next';
5 | import {
6 | createLanguageDetector,
7 | getLanguage,
8 | getLanguageAsync,
9 | } from 'react-native-localization-settings';
10 |
11 | const languageDetector = createLanguageDetector();
12 |
13 | i18next
14 | .use(languageDetector)
15 | .use(initReactI18next)
16 | .init({
17 | resources: {
18 | en: {
19 | translation: {
20 | key: 'hello world in english',
21 | },
22 | },
23 | pl: {
24 | translation: {
25 | key: 'hello world in polish',
26 | },
27 | },
28 | fr: {
29 | translation: {
30 | key: 'hello world in french',
31 | },
32 | },
33 | },
34 | fallbackLng: 'en',
35 | interpolation: {
36 | escapeValue: false,
37 | },
38 | compatibilityJSON: 'v3',
39 | });
40 |
41 | export default function App() {
42 | const { t } = useTranslation();
43 | const [lang, setLang] = React.useState(getLanguage());
44 |
45 | const changeLanguage = (language: string) => () => {
46 | i18next.changeLanguage(language);
47 | setLang(getLanguage());
48 | };
49 | return (
50 |
51 | {t('key')}
52 | {lang}
53 |
54 |
55 |
56 |
65 | );
66 | }
67 |
68 | const styles = StyleSheet.create({
69 | container: {
70 | flex: 1,
71 | alignItems: 'center',
72 | justifyContent: 'center',
73 | },
74 | box: {
75 | width: 60,
76 | height: 60,
77 | marginVertical: 20,
78 | },
79 | });
80 |
--------------------------------------------------------------------------------
/example/ios/exampleTests/exampleTests.m:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | #import
5 | #import
6 |
7 | #define TIMEOUT_SECONDS 600
8 | #define TEXT_TO_LOOK_FOR @"Welcome to React"
9 |
10 | @interface exampleTests : XCTestCase
11 |
12 | @end
13 |
14 | @implementation exampleTests
15 |
16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test
17 | {
18 | if (test(view)) {
19 | return YES;
20 | }
21 | for (UIView *subview in [view subviews]) {
22 | if ([self findSubviewInView:subview matching:test]) {
23 | return YES;
24 | }
25 | }
26 | return NO;
27 | }
28 |
29 | - (void)testRendersWelcomeScreen
30 | {
31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
33 | BOOL foundElement = NO;
34 |
35 | __block NSString *redboxError = nil;
36 | #ifdef DEBUG
37 | RCTSetLogFunction(
38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
39 | if (level >= RCTLogLevelError) {
40 | redboxError = message;
41 | }
42 | });
43 | #endif
44 |
45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
48 |
49 | foundElement = [self findSubviewInView:vc.view
50 | matching:^BOOL(UIView *view) {
51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
52 | return YES;
53 | }
54 | return NO;
55 | }];
56 | }
57 |
58 | #ifdef DEBUG
59 | RCTSetLogFunction(RCTDefaultLogFunction);
60 | #endif
61 |
62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/java/pl/jakubgrzywacz/exampleexpo/MainApplication.kt:
--------------------------------------------------------------------------------
1 | package pl.jakubgrzywacz.exampleexpo
2 |
3 | import android.app.Application
4 | import android.content.res.Configuration
5 |
6 | import com.facebook.react.PackageList
7 | import com.facebook.react.ReactApplication
8 | import com.facebook.react.ReactNativeHost
9 | import com.facebook.react.ReactPackage
10 | import com.facebook.react.ReactHost
11 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
12 | import com.facebook.react.defaults.DefaultReactNativeHost
13 | import com.facebook.react.soloader.OpenSourceMergedSoMapping
14 | import com.facebook.soloader.SoLoader
15 |
16 | import expo.modules.ApplicationLifecycleDispatcher
17 | import expo.modules.ReactNativeHostWrapper
18 |
19 | class MainApplication : Application(), ReactApplication {
20 |
21 | override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper(
22 | this,
23 | object : DefaultReactNativeHost(this) {
24 | override fun getPackages(): List {
25 | val packages = PackageList(this).packages
26 | // Packages that cannot be autolinked yet can be added manually here, for example:
27 | // packages.add(new MyReactNativePackage());
28 | return packages
29 | }
30 |
31 | override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"
32 |
33 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
34 |
35 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
36 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
37 | }
38 | )
39 |
40 | override val reactHost: ReactHost
41 | get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)
42 |
43 | override fun onCreate() {
44 | super.onCreate()
45 | SoLoader.init(this, OpenSourceMergedSoMapping)
46 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
47 | // If you opted-in for the New Architecture, we load the native entry point for this app.
48 | load()
49 | }
50 | ApplicationLifecycleDispatcher.onApplicationCreate(this)
51 | }
52 |
53 | override fun onConfigurationChanged(newConfig: Configuration) {
54 | super.onConfigurationChanged(newConfig)
55 | ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/languageDetector.ts:
--------------------------------------------------------------------------------
1 | import { getLanguage, getLanguageAsync, setLanguage } from './api';
2 |
3 | interface I18nLanguageDetectorModule {
4 | type: 'languageDetector';
5 | init?(): void;
6 | detect(): string | readonly string[] | undefined;
7 | cacheUserLanguage?(lang: string): void;
8 | }
9 | interface I18nLanguageDetectorAsyncModule {
10 | type: 'languageDetector';
11 | async: true;
12 | init?(): void;
13 | detect(
14 | callback: (lng: string | readonly string[] | undefined) => void | undefined
15 | ): void | Promise;
16 | cacheUserLanguage?(lng: string): void | Promise;
17 | }
18 |
19 | type LanguageDetectorOptions = {
20 | cacheCurrentLanguage?: boolean;
21 | async?: boolean;
22 | };
23 |
24 | /**
25 | * @deprecated Use createLanguageDetector instead
26 | */
27 | export const ReactNativeLanguageDetector: I18nLanguageDetectorModule = {
28 | type: 'languageDetector',
29 | init: () => {},
30 | detect: () => getLanguage(),
31 | cacheUserLanguage: (lang: string) => setLanguage(lang),
32 | };
33 |
34 | /**
35 | * I18next language detector generator
36 | * @param options - detector options
37 | * @returns I18nLanguageDetectorModule | I18nLanguageDetectorAsyncModule
38 | * @example
39 | * Usage:
40 | * const languageDetector = createLanguageDetector(options);
41 | * i18next
42 | * .use(languageDetector)
43 | * .init({
44 | * ...
45 | * });
46 | */
47 | export const createLanguageDetector = (
48 | options?: LanguageDetectorOptions
49 | ): I18nLanguageDetectorModule | I18nLanguageDetectorAsyncModule => {
50 | const { cacheCurrentLanguage = false } = options || {};
51 | let skipNextCache = false;
52 |
53 | let languageDetector:
54 | | I18nLanguageDetectorModule
55 | | I18nLanguageDetectorAsyncModule = {
56 | type: 'languageDetector',
57 | init: () => {
58 | skipNextCache = true;
59 | },
60 | detect: () => getLanguage(),
61 | cacheUserLanguage: (lang: string) => {
62 | if (cacheCurrentLanguage === false && skipNextCache) {
63 | skipNextCache = false;
64 | return;
65 | }
66 | setLanguage(lang);
67 | },
68 | };
69 | if (options?.async) {
70 | languageDetector = {
71 | ...languageDetector,
72 | async: true,
73 | detect: (callback) => {
74 | getLanguageAsync().then(callback);
75 | },
76 | };
77 | }
78 | return languageDetector;
79 | };
80 |
--------------------------------------------------------------------------------
/example-expo/android/app/src/main/java/pl/jakubgrzywacz/exampleexpo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package pl.jakubgrzywacz.exampleexpo
2 |
3 | import android.os.Build
4 | import android.os.Bundle
5 |
6 | import com.facebook.react.ReactActivity
7 | import com.facebook.react.ReactActivityDelegate
8 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
9 | import com.facebook.react.defaults.DefaultReactActivityDelegate
10 |
11 | import expo.modules.ReactActivityDelegateWrapper
12 |
13 | class MainActivity : ReactActivity() {
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | // Set the theme to AppTheme BEFORE onCreate to support
16 | // coloring the background, status bar, and navigation bar.
17 | // This is required for expo-splash-screen.
18 | setTheme(R.style.AppTheme);
19 | super.onCreate(null)
20 | }
21 |
22 | /**
23 | * Returns the name of the main component registered from JavaScript. This is used to schedule
24 | * rendering of the component.
25 | */
26 | override fun getMainComponentName(): String = "main"
27 |
28 | /**
29 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
30 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
31 | */
32 | override fun createReactActivityDelegate(): ReactActivityDelegate {
33 | return ReactActivityDelegateWrapper(
34 | this,
35 | BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
36 | object : DefaultReactActivityDelegate(
37 | this,
38 | mainComponentName,
39 | fabricEnabled
40 | ){})
41 | }
42 |
43 | /**
44 | * Align the back button behavior with Android S
45 | * where moving root activities to background instead of finishing activities.
46 | * @see onBackPressed
47 | */
48 | override fun invokeDefaultOnBackPressed() {
49 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
50 | if (!moveTaskToBack(false)) {
51 | // For non-root activities, use the default implementation to finish them.
52 | super.invokeDefaultOnBackPressed()
53 | }
54 | return
55 | }
56 |
57 | // Use the default back button implementation on Android S
58 | // because it's doing more than [Activity.moveTaskToBack] in fact.
59 | super.invokeDefaultOnBackPressed()
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/example-expo/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | # AndroidX package structure to make it clearer which packages are bundled with the
21 | # Android operating system, and which are packaged with your app's APK
22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
23 | android.useAndroidX=true
24 |
25 | # Enable AAPT2 PNG crunching
26 | android.enablePngCrunchInReleaseBuilds=true
27 |
28 | # Use this property to specify which architecture you want to build.
29 | # You can also override it from the CLI using
30 | # ./gradlew -PreactNativeArchitectures=x86_64
31 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
32 |
33 | # Use this property to enable support to the new architecture.
34 | # This will allow you to use TurboModules and the Fabric render in
35 | # your application. You should enable this flag either if you want
36 | # to write custom TurboModules/Fabric components OR use libraries that
37 | # are providing them.
38 | newArchEnabled=false
39 |
40 | # Use this property to enable or disable the Hermes JS engine.
41 | # If set to false, you will be using JSC instead.
42 | hermesEnabled=true
43 |
44 | # Enable GIF support in React Native images (~200 B increase)
45 | expo.gif.enabled=true
46 | # Enable webp support in React Native images (~85 KB increase)
47 | expo.webp.enabled=true
48 | # Enable animated webp support (~3.4 MB increase)
49 | # Disabled by default because iOS doesn't support animated webp
50 | expo.webp.animated=false
51 |
52 | # Enable network inspector
53 | EX_DEV_CLIENT_NETWORK_INSPECTOR=true
54 |
55 | # Use legacy packaging to compress native libraries in the resulting APK.
56 | expo.useLegacyPackaging=false
57 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CADisableMinimumFrameDurationOnPhone
6 |
7 | CFBundleDevelopmentRegion
8 | $(DEVELOPMENT_LANGUAGE)
9 | CFBundleDisplayName
10 | example-expo
11 | CFBundleExecutable
12 | $(EXECUTABLE_NAME)
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | $(PRODUCT_NAME)
19 | CFBundlePackageType
20 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
21 | CFBundleShortVersionString
22 | 1.0.0
23 | CFBundleSignature
24 | ????
25 | CFBundleURLTypes
26 |
27 |
28 | CFBundleURLSchemes
29 |
30 | pl.jakubgrzywacz.exampleexpo
31 |
32 |
33 |
34 | CFBundleVersion
35 | 1
36 | LSMinimumSystemVersion
37 | 12.0
38 | LSRequiresIPhoneOS
39 |
40 | NSAppTransportSecurity
41 |
42 | NSAllowsArbitraryLoads
43 |
44 | NSAllowsLocalNetworking
45 |
46 |
47 | UILaunchStoryboardName
48 | SplashScreen
49 | UIRequiredDeviceCapabilities
50 |
51 | arm64
52 |
53 | UIRequiresFullScreen
54 |
55 | UIStatusBarStyle
56 | UIStatusBarStyleDefault
57 | UISupportedInterfaceOrientations
58 |
59 | UIInterfaceOrientationPortrait
60 | UIInterfaceOrientationPortraitUpsideDown
61 |
62 | UISupportedInterfaceOrientations~ipad
63 |
64 | UIInterfaceOrientationPortrait
65 | UIInterfaceOrientationPortraitUpsideDown
66 | UIInterfaceOrientationLandscapeLeft
67 | UIInterfaceOrientationLandscapeRight
68 |
69 | UIUserInterfaceStyle
70 | Light
71 | UIViewControllerBasedStatusBarAppearance
72 |
73 |
74 |
--------------------------------------------------------------------------------
/example-expo/ios/Podfile:
--------------------------------------------------------------------------------
1 | require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
2 | require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
3 |
4 | require 'json'
5 | podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}
6 |
7 | ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'
8 | ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']
9 |
10 | platform :ios, podfile_properties['ios.deploymentTarget'] || '15.1'
11 | install! 'cocoapods',
12 | :deterministic_uuids => false
13 |
14 | prepare_react_native_project!
15 |
16 | target 'exampleexpo' do
17 | use_expo_modules!
18 |
19 | if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
20 | config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
21 | else
22 | config_command = [
23 | 'node',
24 | '--no-warnings',
25 | '--eval',
26 | 'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
27 | 'react-native-config',
28 | '--json',
29 | '--platform',
30 | 'ios'
31 | ]
32 | end
33 |
34 | config = use_native_modules!(config_command)
35 |
36 | use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
37 | use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']
38 |
39 | use_react_native!(
40 | :path => config[:reactNativePath],
41 | :hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
42 | # An absolute path to your application root.
43 | :app_path => "#{Pod::Config.instance.installation_root}/..",
44 | :privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] != 'false',
45 | )
46 |
47 | post_install do |installer|
48 | react_native_post_install(
49 | installer,
50 | config[:reactNativePath],
51 | :mac_catalyst_enabled => false,
52 | :ccache_enabled => podfile_properties['apple.ccacheEnabled'] == 'true',
53 | )
54 |
55 | # This is necessary for Xcode 14, because it signs resource bundles by default
56 | # when building for devices.
57 | installer.target_installation_results.pod_target_installation_results
58 | .each do |pod_name, target_installation_result|
59 | target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
60 | resource_bundle_target.build_configurations.each do |config|
61 | config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
62 | end
63 | end
64 | end
65 | end
66 | end
67 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/AppDelegate.mm:
--------------------------------------------------------------------------------
1 | #import "AppDelegate.h"
2 |
3 | #import
4 | #import
5 |
6 | @implementation AppDelegate
7 |
8 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
9 | {
10 | self.moduleName = @"main";
11 |
12 | // You can add your custom initial props in the dictionary below.
13 | // They will be passed down to the ViewController used by React Native.
14 | self.initialProps = @{};
15 |
16 | return [super application:application didFinishLaunchingWithOptions:launchOptions];
17 | }
18 |
19 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
20 | {
21 | return [self bundleURL];
22 | }
23 |
24 | - (NSURL *)bundleURL
25 | {
26 | #if DEBUG
27 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"];
28 | #else
29 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
30 | #endif
31 | }
32 |
33 | // Linking API
34 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options {
35 | return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];
36 | }
37 |
38 | // Universal Links
39 | - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler {
40 | BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
41 | return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result;
42 | }
43 |
44 | // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
45 | - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
46 | {
47 | return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
48 | }
49 |
50 | // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
51 | - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
52 | {
53 | return [super application:application didFailToRegisterForRemoteNotificationsWithError:error];
54 | }
55 |
56 | // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
57 | - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
58 | {
59 | return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
60 | }
61 |
62 | @end
63 |
--------------------------------------------------------------------------------
/example/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | CFPropertyList (3.0.7)
5 | base64
6 | nkf
7 | rexml
8 | activesupport (6.1.7.10)
9 | concurrent-ruby (~> 1.0, >= 1.0.2)
10 | i18n (>= 1.6, < 2)
11 | minitest (>= 5.1)
12 | tzinfo (~> 2.0)
13 | zeitwerk (~> 2.3)
14 | addressable (2.8.7)
15 | public_suffix (>= 2.0.2, < 7.0)
16 | algoliasearch (1.27.5)
17 | httpclient (~> 2.8, >= 2.8.3)
18 | json (>= 1.5.1)
19 | atomos (0.1.3)
20 | base64 (0.2.0)
21 | claide (1.1.0)
22 | cocoapods (1.15.2)
23 | addressable (~> 2.8)
24 | claide (>= 1.0.2, < 2.0)
25 | cocoapods-core (= 1.15.2)
26 | cocoapods-deintegrate (>= 1.0.3, < 2.0)
27 | cocoapods-downloader (>= 2.1, < 3.0)
28 | cocoapods-plugins (>= 1.0.0, < 2.0)
29 | cocoapods-search (>= 1.0.0, < 2.0)
30 | cocoapods-trunk (>= 1.6.0, < 2.0)
31 | cocoapods-try (>= 1.1.0, < 2.0)
32 | colored2 (~> 3.1)
33 | escape (~> 0.0.4)
34 | fourflusher (>= 2.3.0, < 3.0)
35 | gh_inspector (~> 1.0)
36 | molinillo (~> 0.8.0)
37 | nap (~> 1.0)
38 | ruby-macho (>= 2.3.0, < 3.0)
39 | xcodeproj (>= 1.23.0, < 2.0)
40 | cocoapods-core (1.15.2)
41 | activesupport (>= 5.0, < 8)
42 | addressable (~> 2.8)
43 | algoliasearch (~> 1.0)
44 | concurrent-ruby (~> 1.1)
45 | fuzzy_match (~> 2.0.4)
46 | nap (~> 1.0)
47 | netrc (~> 0.11)
48 | public_suffix (~> 4.0)
49 | typhoeus (~> 1.0)
50 | cocoapods-deintegrate (1.0.5)
51 | cocoapods-downloader (2.1)
52 | cocoapods-plugins (1.0.0)
53 | nap
54 | cocoapods-search (1.0.1)
55 | cocoapods-trunk (1.6.0)
56 | nap (>= 0.8, < 2.0)
57 | netrc (~> 0.11)
58 | cocoapods-try (1.2.0)
59 | colored2 (3.1.2)
60 | concurrent-ruby (1.3.4)
61 | escape (0.0.4)
62 | ethon (0.16.0)
63 | ffi (>= 1.15.0)
64 | ffi (1.17.0)
65 | fourflusher (2.3.1)
66 | fuzzy_match (2.0.4)
67 | gh_inspector (1.1.3)
68 | httpclient (2.8.3)
69 | i18n (1.14.6)
70 | concurrent-ruby (~> 1.0)
71 | json (2.7.6)
72 | minitest (5.25.1)
73 | molinillo (0.8.0)
74 | nanaimo (0.3.0)
75 | nap (1.1.0)
76 | netrc (0.11.0)
77 | nkf (0.2.0)
78 | public_suffix (4.0.7)
79 | rexml (3.3.9)
80 | ruby-macho (2.5.1)
81 | typhoeus (1.4.1)
82 | ethon (>= 0.9.0)
83 | tzinfo (2.0.6)
84 | concurrent-ruby (~> 1.0)
85 | xcodeproj (1.25.1)
86 | CFPropertyList (>= 2.3.3, < 4.0)
87 | atomos (~> 0.1.3)
88 | claide (>= 1.0.2, < 2.0)
89 | colored2 (~> 3.1)
90 | nanaimo (~> 0.3.0)
91 | rexml (>= 3.3.6, < 4.0)
92 | zeitwerk (2.6.18)
93 |
94 | PLATFORMS
95 | ruby
96 |
97 | DEPENDENCIES
98 | activesupport (>= 6.1.7.5, != 7.1.0)
99 | cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
100 | xcodeproj (< 1.26.0)
101 |
102 | RUBY VERSION
103 | ruby 2.6.10p210
104 |
105 | BUNDLED WITH
106 | 1.17.2
107 |
--------------------------------------------------------------------------------
/example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/example-expo/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3 | def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["LocalizationSettings_kotlinVersion"]
4 |
5 | repositories {
6 | google()
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:7.2.1"
12 | // noinspection DifferentKotlinGradleVersion
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | }
15 | }
16 |
17 | def isNewArchitectureEnabled() {
18 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19 | }
20 |
21 | apply plugin: "com.android.library"
22 | apply plugin: "kotlin-android"
23 |
24 |
25 | def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
26 |
27 | if (isNewArchitectureEnabled()) {
28 | apply plugin: "com.facebook.react"
29 | }
30 |
31 | def getExtOrDefault(name) {
32 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["LocalizationSettings_" + name]
33 | }
34 |
35 | def getExtOrIntegerDefault(name) {
36 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LocalizationSettings_" + name]).toInteger()
37 | }
38 |
39 | android {
40 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
41 |
42 | defaultConfig {
43 | minSdkVersion getExtOrIntegerDefault("minSdkVersion")
44 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
45 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
46 | }
47 | buildTypes {
48 | release {
49 | minifyEnabled false
50 | }
51 | }
52 |
53 | lintOptions {
54 | disable "GradleCompatible"
55 | }
56 |
57 | compileOptions {
58 | sourceCompatibility JavaVersion.VERSION_1_8
59 | targetCompatibility JavaVersion.VERSION_1_8
60 | }
61 |
62 | sourceSets {
63 | main {
64 | if (isNewArchitectureEnabled()) {
65 | java.srcDirs += [
66 | "src/newarch",
67 | // This is needed to build Kotlin project with NewArch enabled
68 | "${project.buildDir}/generated/source/codegen/java"
69 | ]
70 | } else {
71 | java.srcDirs += ["src/oldarch"]
72 | }
73 | }
74 | }
75 | }
76 |
77 | repositories {
78 | mavenCentral()
79 | google()
80 | }
81 |
82 | def kotlin_version = getExtOrDefault("kotlinVersion")
83 |
84 | dependencies {
85 | // For < 0.71, this will be from the local maven repo
86 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
87 | //noinspection GradleDynamicVersion
88 | implementation "com.facebook.react:react-native:+"
89 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
90 |
91 | implementation "androidx.appcompat:appcompat:1.6.1"
92 | implementation "androidx.appcompat:appcompat-resources:1.6.1"
93 | }
94 |
95 | if (isNewArchitectureEnabled()) {
96 | react {
97 | jsRootDir = file("../src/")
98 | libraryName = "LocalizationSettings"
99 | codegenJavaPackageName = "com.localizationsettings"
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
2 |
3 | # Getting Started
4 |
5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding.
6 |
7 | ## Step 1: Start the Metro Server
8 |
9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native.
10 |
11 | To start Metro, run the following command from the _root_ of your React Native project:
12 |
13 | ```bash
14 | # using npm
15 | npm start
16 |
17 | # OR using Yarn
18 | yarn start
19 | ```
20 |
21 | ## Step 2: Start your Application
22 |
23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app:
24 |
25 | ### For Android
26 |
27 | ```bash
28 | # using npm
29 | npm run android
30 |
31 | # OR using Yarn
32 | yarn android
33 | ```
34 |
35 | ### For iOS
36 |
37 | ```bash
38 | # using npm
39 | npm run ios
40 |
41 | # OR using Yarn
42 | yarn ios
43 | ```
44 |
45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly.
46 |
47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.
48 |
49 | ## Step 3: Modifying your App
50 |
51 | Now that you have successfully run the app, let's modify it.
52 |
53 | 1. Open `App.tsx` in your text editor of choice and edit some lines.
54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes!
55 |
56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes!
57 |
58 | ## Congratulations! :tada:
59 |
60 | You've successfully run and modified your React Native App. :partying_face:
61 |
62 | ### Now what?
63 |
64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started).
66 |
67 | # Troubleshooting
68 |
69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
70 |
71 | # Learn More
72 |
73 | To learn more about React Native, take a look at the following resources:
74 |
75 | - [React Native Website](https://reactnative.dev) - learn more about React Native.
76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
80 |
--------------------------------------------------------------------------------
/ios/LocalizationSettings.mm:
--------------------------------------------------------------------------------
1 | #import "LocalizationSettings.h"
2 |
3 | @implementation LocalizationSettings
4 | RCT_EXPORT_MODULE()
5 |
6 |
7 | /**
8 | * Get IETF BCP 47 (language-COUNTRY "pl-PL")
9 | * if country is not available in locale, then use system defaults (even if it's not 100% correct, like "pl-US")
10 | **/
11 | -(NSString*) getLanguageTag:(NSString *)language {
12 | NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:language];
13 | if ([locale countryCode]) {
14 | return [locale localeIdentifier];
15 | }
16 | NSLocale *currentLocale = [NSLocale currentLocale];
17 | return [[locale languageCode] stringByAppendingFormat:@"-%@", [currentLocale countryCode]];
18 | }
19 |
20 | -(NSString*) getUserLocale {
21 | NSArray* locales = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
22 | if (locales == nil ) { return nil; }
23 | if ([locales count] == 0) { return nil; }
24 |
25 | NSString* userLocale = locales[0];
26 | return userLocale;
27 | }
28 |
29 | /**
30 | * Get current language
31 | * returns string in IETF BCP 47 (language-COUNTRY "pl-PL")
32 | **/
33 | - (NSString *)getCurrentLanguage {
34 | NSString *userLocale = [self getUserLocale];
35 | if (userLocale) {
36 | return userLocale;
37 |
38 | }
39 | return [[NSLocale preferredLanguages] objectAtIndex:0];
40 | }
41 |
42 | /**
43 | * Set current language
44 | * passed language can be in ISO 639-1 (language "pl")
45 | * or IETF BCP 47 (language-COUNTRY "pl-PL")
46 | **/
47 | - (void)setCurrentLanguage:(NSString *)lang {
48 | NSString *languageTag = [self getLanguageTag:lang];
49 | [[NSUserDefaults standardUserDefaults] setObject:@[languageTag] forKey:@"AppleLanguages"];
50 | [[NSUserDefaults standardUserDefaults] synchronize];
51 | }
52 |
53 |
54 | - (void)getLanguage:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
55 | resolve([self getCurrentLanguage]);
56 | }
57 |
58 |
59 | - (void)setLanguage:(NSString *)lang {
60 | [self setCurrentLanguage:lang];
61 | }
62 |
63 | /**
64 | * Expose functions to react-native
65 | **/
66 | RCT_REMAP_METHOD(getLanguage,
67 | withResolver:(RCTPromiseResolveBlock)resolve
68 | withReject:(RCTPromiseRejectBlock)reject)
69 | {
70 | return [self getLanguage:resolve reject:reject];
71 | }
72 |
73 | RCT_REMAP_METHOD(setLanguage,
74 | language:(NSString *)lang)
75 | {
76 | return [self setLanguage:lang];
77 | }
78 |
79 | /**
80 | * Expose constants to react-native
81 | **/
82 | - (NSDictionary *)constantsToExport
83 | {
84 | return @{ @"language": [self getCurrentLanguage]};
85 | }
86 |
87 | +(BOOL)requiresMainQueueSetup
88 | {
89 | return YES;
90 | }
91 |
92 | // Don't compile this code when we build for the old architecture.
93 | #ifdef RCT_NEW_ARCH_ENABLED
94 | - (std::shared_ptr)getTurboModule:
95 | (const facebook::react::ObjCTurboModule::InitParams &)params
96 | {
97 | return std::make_shared(params);
98 | }
99 |
100 | - (facebook::react::ModuleConstants)getConstants {
101 | return [self constantsToExport];
102 | }
103 |
104 | #endif
105 |
106 | @end
107 |
--------------------------------------------------------------------------------
/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
55 |
61 |
62 |
63 |
64 |
70 |
72 |
78 |
79 |
80 |
81 |
83 |
84 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo/SplashScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/example-expo/ios/exampleexpo.xcodeproj/xcshareddata/xcschemes/exampleexpo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
55 |
61 |
62 |
63 |
64 |
70 |
72 |
78 |
79 |
80 |
81 |
83 |
84 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/example/ios/example/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/android/src/main/java/com/localizationsettings/LocalizationSettingsModule.kt:
--------------------------------------------------------------------------------
1 | package com.localizationsettings
2 |
3 | import android.content.Context
4 | import android.content.SharedPreferences
5 | import android.os.Build
6 | import androidx.appcompat.app.AppCompatDelegate
7 | import androidx.core.os.LocaleListCompat
8 | import com.facebook.react.bridge.Promise
9 | import com.facebook.react.bridge.ReactApplicationContext
10 | import com.facebook.react.bridge.ReactMethod
11 | import java.util.*
12 |
13 |
14 | class LocalizationSettingsModule internal constructor(context: ReactApplicationContext) :
15 | LocalizationSettingsSpec(context) {
16 |
17 | override fun getName(): String {
18 | return NAME
19 | }
20 |
21 | /**
22 | * Get IETF BCP 47 (language-COUNTRY "pl-PL")
23 | * if country is not available in locale, then use system defaults (even if it's not 100% correct, like "pl-US")
24 | **/
25 | private fun getLanguageTag(language: String): String {
26 | val locale = Locale.forLanguageTag(language);
27 |
28 | // if language has format language-COUNTRY, then return it
29 | if (locale.country != "") return locale.toLanguageTag()
30 | // fallback for system country
31 | return Locale(locale.language, Locale.getDefault().country).toLanguageTag()
32 | }
33 |
34 |
35 | /**
36 | * Get current language
37 | * returns string in IETF BCP 47 (language-COUNTRY "pl-PL")
38 | * If API version >= 33, use native per-app language feature
39 | * else, fallback to SharedPreferences
40 | **/
41 | private fun getCurrentLanguage(): String? {
42 | // If API version is >= 33, then use per-app language settings
43 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
44 | val currentLocaleName = if (!AppCompatDelegate.getApplicationLocales().isEmpty) {
45 | // get per-app language
46 | AppCompatDelegate.getApplicationLocales()[0]?.toLanguageTag()
47 | } else {
48 | // Fallback to the default System Locale
49 | Locale.getDefault().toLanguageTag()
50 | }
51 | return currentLocaleName
52 | }
53 | // if API is < 33, then use SharedPreferences with fallback to default System Locale
54 | if (getPreferences().getString("languageFrom", null) == Locale.getDefault().language) {
55 | return getPreferences().getString("language", Locale.getDefault().toLanguageTag())
56 | }
57 | return Locale.getDefault().toLanguageTag()
58 | }
59 |
60 |
61 | /**
62 | * Set current language
63 | * passed language can be in ISO 639-1 (language "pl")
64 | * or IETF BCP 47 (language-COUNTRY "pl-PL")
65 | * If API version >= 33, use native per-app language feature
66 | * else, fallback to SharedPreferences
67 | **/
68 | private fun setCurrentLanguage(language: String) {
69 | // If API version is >= 33, then use per-app language settings
70 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
71 | val localeList = LocaleListCompat.forLanguageTags(getLanguageTag(language))
72 | AppCompatDelegate.setApplicationLocales(localeList)
73 | } else {
74 | // if API is < 33, then set SharedPreferences language
75 | val editor = getEditor();
76 | editor.putString("languageFrom", Locale.getDefault().language)
77 | editor.putString("language", getLanguageTag(language))
78 | editor.apply()
79 | }
80 | }
81 |
82 |
83 | /**
84 | * Expose functions to react-native
85 | **/
86 | @ReactMethod
87 | override fun getLanguage(promise: Promise) {
88 | promise.resolve(getCurrentLanguage())
89 | }
90 |
91 | @ReactMethod
92 | override fun setLanguage(language: String) {
93 | setCurrentLanguage(language)
94 | }
95 |
96 | /**
97 | * Expose constants to react-native
98 | **/
99 | override fun getTypedExportedConstants(): Map {
100 | return mapOf(
101 | "language" to getCurrentLanguage()
102 | )
103 | }
104 |
105 | /**
106 | * SharedPreferences (only used when API version is below 33)
107 | **/
108 | private fun getPreferences(): SharedPreferences {
109 | return reactApplicationContext.getSharedPreferences(
110 | "LocalizationSettings", Context.MODE_PRIVATE
111 | )
112 | }
113 |
114 | private fun getEditor(): SharedPreferences.Editor {
115 | return getPreferences().edit()
116 | }
117 |
118 | companion object {
119 | const val NAME = "LocalizationSettings"
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-localization-settings",
3 | "version": "1.2.0",
4 | "description": "React Native module to expose per-app language preferences API on iOS and Android.",
5 | "main": "lib/commonjs/index",
6 | "module": "lib/module/index",
7 | "types": "lib/typescript/index.d.ts",
8 | "react-native": "src/index",
9 | "source": "src/index",
10 | "files": [
11 | "src",
12 | "lib",
13 | "android",
14 | "ios",
15 | "cpp",
16 | "*.podspec",
17 | "plugin",
18 | "app.plugin.js",
19 | "!plugin/tsconfig.*",
20 | "!lib/typescript/example",
21 | "!ios/build",
22 | "!android/build",
23 | "!android/gradle",
24 | "!android/gradlew",
25 | "!android/gradlew.bat",
26 | "!android/local.properties",
27 | "!**/__tests__",
28 | "!**/__fixtures__",
29 | "!**/__mocks__",
30 | "!**/.*"
31 | ],
32 | "scripts": {
33 | "test": "jest",
34 | "typecheck": "tsc --noEmit",
35 | "lint": "eslint \"**/*.{js,ts,tsx}\"",
36 | "plugin-dev": "expo-module build plugin",
37 | "plugin-build": "tsc --build plugin",
38 | "plugin-clean": "expo-module clean plugin",
39 | "prepack": "bob build && yarn plugin-clean && yarn plugin-build",
40 | "release": "release-it",
41 | "example": "yarn --cwd example",
42 | "bootstrap": "yarn example && yarn install && yarn example pods",
43 | "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
44 | },
45 | "keywords": [
46 | "react-native",
47 | "ios",
48 | "android"
49 | ],
50 | "repository": "https://github.com/jakex7/react-native-localization-settings",
51 | "author": "Jakub Grzywacz (https://github.com/jakex7)",
52 | "license": "MIT",
53 | "bugs": {
54 | "url": "https://github.com/jakex7/react-native-localization-settings/issues"
55 | },
56 | "homepage": "https://github.com/jakex7/react-native-localization-settings#readme",
57 | "publishConfig": {
58 | "registry": "https://registry.npmjs.org/"
59 | },
60 | "devDependencies": {
61 | "@commitlint/config-conventional": "^17.0.2",
62 | "@evilmartians/lefthook": "^1.2.2",
63 | "@react-native-community/eslint-config": "^3.0.2",
64 | "@release-it/conventional-changelog": "^5.0.0",
65 | "@types/jest": "^28.1.2",
66 | "@types/react": "~17.0.21",
67 | "@types/react-native": "0.70.0",
68 | "commitlint": "^17.0.2",
69 | "del-cli": "^5.0.0",
70 | "eslint": "^8.4.1",
71 | "eslint-config-prettier": "^8.5.0",
72 | "eslint-plugin-prettier": "^4.0.0",
73 | "expo-module-scripts": "3.5.4",
74 | "jest": "^28.1.1",
75 | "pod-install": "^0.1.0",
76 | "prettier": "^2.0.5",
77 | "react": "18.2.0",
78 | "react-native": "0.71.6",
79 | "react-native-builder-bob": "^0.20.0",
80 | "release-it": "^15.0.0",
81 | "typescript": "^5.6.3"
82 | },
83 | "resolutions": {
84 | "@types/react": "17.0.21"
85 | },
86 | "peerDependencies": {
87 | "react": "*",
88 | "react-native": "*"
89 | },
90 | "engines": {
91 | "node": ">= 16.0.0"
92 | },
93 | "packageManager": "yarn@1.22.22",
94 | "jest": {
95 | "preset": "react-native",
96 | "modulePathIgnorePatterns": [
97 | "/example/node_modules",
98 | "/lib/"
99 | ]
100 | },
101 | "commitlint": {
102 | "extends": [
103 | "@commitlint/config-conventional"
104 | ]
105 | },
106 | "release-it": {
107 | "git": {
108 | "commitMessage": "chore: release ${version}",
109 | "tagName": "v${version}"
110 | },
111 | "npm": {
112 | "publish": true
113 | },
114 | "github": {
115 | "release": true
116 | },
117 | "plugins": {
118 | "@release-it/conventional-changelog": {
119 | "preset": "angular"
120 | }
121 | }
122 | },
123 | "eslintConfig": {
124 | "root": true,
125 | "extends": [
126 | "@react-native-community",
127 | "prettier"
128 | ],
129 | "rules": {
130 | "prettier/prettier": [
131 | "error",
132 | {
133 | "quoteProps": "consistent",
134 | "singleQuote": true,
135 | "tabWidth": 2,
136 | "trailingComma": "es5",
137 | "useTabs": false
138 | }
139 | ]
140 | }
141 | },
142 | "eslintIgnore": [
143 | "node_modules/",
144 | "lib/"
145 | ],
146 | "prettier": {
147 | "quoteProps": "consistent",
148 | "singleQuote": true,
149 | "tabWidth": 2,
150 | "trailingComma": "es5",
151 | "useTabs": false
152 | },
153 | "react-native-builder-bob": {
154 | "source": "src",
155 | "output": "lib",
156 | "targets": [
157 | "commonjs",
158 | "module",
159 | [
160 | "typescript",
161 | {
162 | "project": "tsconfig.build.json"
163 | }
164 | ]
165 | ]
166 | },
167 | "codegenConfig": {
168 | "name": "RNLocalizationSettingsSpec",
169 | "type": "modules",
170 | "jsSrcsDir": "src"
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 | apply plugin: "org.jetbrains.kotlin.android"
3 | apply plugin: "com.facebook.react"
4 |
5 | /**
6 | * This is the configuration block to customize your React Native Android app.
7 | * By default you don't need to apply any configuration, just uncomment the lines you need.
8 | */
9 | react {
10 | /* Folders */
11 | // The root of your project, i.e. where "package.json" lives. Default is '../..'
12 | // root = file("../../")
13 | // The folder where the react-native NPM package is. Default is ../../node_modules/react-native
14 | // reactNativeDir = file("../../node_modules/react-native")
15 | // The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
16 | // codegenDir = file("../../node_modules/@react-native/codegen")
17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
18 | // cliFile = file("../../node_modules/react-native/cli.js")
19 |
20 | /* Variants */
21 | // The list of variants to that are debuggable. For those we're going to
22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
24 | // debuggableVariants = ["liteDebug", "prodDebug"]
25 |
26 | /* Bundling */
27 | // A list containing the node command and its flags. Default is just 'node'.
28 | // nodeExecutableAndArgs = ["node"]
29 | //
30 | // The command to run when bundling. By default is 'bundle'
31 | // bundleCommand = "ram-bundle"
32 | //
33 | // The path to the CLI configuration file. Default is empty.
34 | // bundleConfig = file(../rn-cli.config.js)
35 | //
36 | // The name of the generated asset file containing your JS bundle
37 | // bundleAssetName = "MyApplication.android.bundle"
38 | //
39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
40 | // entryFile = file("../js/MyApplication.android.js")
41 | //
42 | // A list of extra flags to pass to the 'bundle' commands.
43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
44 | // extraPackagerArgs = []
45 |
46 | /* Hermes Commands */
47 | // The hermes compiler command to run. By default it is 'hermesc'
48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
49 | //
50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
51 | // hermesFlags = ["-O", "-output-source-map"]
52 |
53 | /* Autolinking */
54 | autolinkLibrariesWithApp()
55 | }
56 |
57 | /**
58 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
59 | */
60 | def enableProguardInReleaseBuilds = false
61 |
62 | /**
63 | * The preferred build flavor of JavaScriptCore (JSC)
64 | *
65 | * For example, to use the international variant, you can use:
66 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
67 | *
68 | * The international variant includes ICU i18n library and necessary data
69 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
70 | * give correct results when using with locales other than en-US. Note that
71 | * this variant is about 6MiB larger per architecture than default.
72 | */
73 | def jscFlavor = 'org.webkit:android-jsc:+'
74 |
75 | android {
76 | ndkVersion rootProject.ext.ndkVersion
77 | buildToolsVersion rootProject.ext.buildToolsVersion
78 | compileSdk rootProject.ext.compileSdkVersion
79 |
80 | namespace "com.example"
81 | defaultConfig {
82 | applicationId "com.example"
83 | minSdkVersion rootProject.ext.minSdkVersion
84 | targetSdkVersion rootProject.ext.targetSdkVersion
85 | versionCode 1
86 | versionName "1.0"
87 | }
88 | signingConfigs {
89 | debug {
90 | storeFile file('debug.keystore')
91 | storePassword 'android'
92 | keyAlias 'androiddebugkey'
93 | keyPassword 'android'
94 | }
95 | }
96 | buildTypes {
97 | debug {
98 | signingConfig signingConfigs.debug
99 | }
100 | release {
101 | // Caution! In production, you need to generate your own keystore file.
102 | // see https://reactnative.dev/docs/signed-apk-android.
103 | signingConfig signingConfigs.debug
104 | minifyEnabled enableProguardInReleaseBuilds
105 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
106 | }
107 | }
108 | }
109 |
110 | dependencies {
111 | // The version of react-native is set by the React Native Gradle Plugin
112 | implementation("com.facebook.react:react-android")
113 |
114 | if (hermesEnabled.toBoolean()) {
115 | implementation("com.facebook.react:hermes-android")
116 | } else {
117 | implementation jscFlavor
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Native Localization Settings
2 |
3 | `react-native-localization-settings` is a native module to expose per-app language preferences API on iOS and Android.
4 |
5 | 
6 |
7 | ## Supported platforms
8 |
9 | | Platform | Supported |
10 | |----------|:---------:|
11 | | iOS | ✅ |
12 | | Android* | ✅ |
13 |
14 | _*per-app language settings was introduced in API level 33 (Android 13). On the older versions, the library uses
15 | SharedPreferences to store the language._
16 |
17 | ## Installation
18 |
19 | To get started with `react-native-localization-settings`, you'll need to install it using npm:
20 |
21 | ```sh
22 | npm install react-native-localization-settings
23 | ```
24 |
25 | or with yarn:
26 |
27 | ```sh
28 | yarn add react-native-localization-settings
29 | ```
30 |
31 | ## Setup
32 |
33 | To get started, define the languages your app will support. If you're using Expo, you can leverage the Expo config plugin to generate the necessary native configurations.
34 |
35 | ### Expo
36 |
37 | Simply add the config plugin to your `app.json` file and specify the list of supported languages:
38 |
39 | ```json
40 | {
41 | "expo": {
42 | // ...
43 | "plugins": [
44 | [
45 | "react-native-localization-settings",
46 | {
47 | "languages": ["en", "pl"]
48 | }
49 | ]
50 | ]
51 | }
52 | }
53 | ```
54 |
55 | and run `npx expo prebuild`.
56 |
57 | ### Bare react-native app
58 |
59 | If your app isn’t using Expo, you’ll need to add the configuration manually.
60 |
61 |
62 |
63 | iOS configuration
64 |
65 | Open your project in XCode, in Project Navigator select project, go to `Info` tab, and
66 | under `Localizations` section add languages you want to support.
67 |
68 | 
69 |
70 | Next, you need to create a `Localization.strings` file.
71 |
72 | 
73 |
74 | Select newly created file and on the right side of the screen, under `Localizations` selection press `Localize`. Confirm
75 | the popup.
76 |
77 | 
78 |
79 | Lastly, you need to select all elements in the section form previous step.
80 |
81 |
82 |
83 |
84 |
85 | Android configuration
86 |
87 | Create new file in `android/app/src/main/res/xml` directory named `locales_config.xml`. and define supported languages:
88 |
89 | ```xml
90 |
91 |
92 |
93 |
94 |
95 |
96 | ```
97 |
98 | Then, open `android/app/src/main/AndroidManifest.xml` and add following line to the Application tag:
99 |
100 | ```xml
101 |
104 | >
105 | ```
106 |
107 |
108 | ## API
109 |
110 | ### getLanguage()
111 |
112 | Function to get current language.
113 |
114 | Returns Language in IETF BCP 47 format (like 'en-US')
115 |
116 | ```ts
117 | getLanguage(); // 'en-US'
118 | ```
119 |
120 | ### setLanguage()
121 |
122 | Function to set the current language.
123 | It accepts a string with language code in IETF BCP 47 format (like 'en-US') or ISO 639-1 format (like 'en').
124 |
125 | ```ts
126 | setLanguage("en-US");
127 | ```
128 |
129 | ## i18next
130 |
131 | This library is fully compatible with [i18next](https://www.i18next.com/).
132 |
133 | To use it with i18next, create a language detector by using `createLanguageDetector` with the specified `options`:
134 | ```ts
135 | import { createLanguageDetector } from 'react-native-localization-settings';
136 |
137 | const languageDetector = createLanguageDetector({});
138 |
139 | i18next
140 | .use(languageDetector)
141 | .use(initReactI18next)
142 | .init({
143 | // ...
144 | });
145 | ```
146 |
147 | ### Options
148 |
149 | ```ts
150 | type LanguageDetectorOptions = {
151 | cacheCurrentLanguage?: boolean; // default: false - sets current detected language
152 | async?: boolean; // default: false - uses getLanguageAsync (set to true on old architecture)
153 | };
154 | ```
155 |
156 | ### Changing language
157 |
158 | Then, if you want to create custom in-app language selector, you should be able to change the language (along with the
159 | settings per-app language) using standard i18next function:
160 |
161 | ```ts
162 | i18next.changeLanguage('pl-PL');
163 | ```
164 |
165 | ## Why?
166 |
167 | Users who speak multiple languages often set their device language to one language, such as English, but they may want
168 | to use other languages for certain apps, like Polish, Dutch, or French. To help apps provide a better experience for
169 | these users, this package adds the ability to set language preferences for individual apps in the device's settings.
170 |
171 | ## License
172 |
173 | [MIT](LICENSE)
174 |
175 | ---
176 |
177 | Made with ❤️ by [Jakub Grzywacz](https://jakubgrzywacz.pl)
178 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are always welcome, no matter how large or small!
4 |
5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
6 |
7 | ## Development workflow
8 |
9 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
10 |
11 | ```sh
12 | yarn
13 | ```
14 |
15 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
16 |
17 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
18 |
19 | To start the packager:
20 |
21 | ```sh
22 | yarn example start
23 | ```
24 |
25 | To run the example app on Android:
26 |
27 | ```sh
28 | yarn example android
29 | ```
30 |
31 | To run the example app on iOS:
32 |
33 | ```sh
34 | yarn example ios
35 | ```
36 |
37 | By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following:
38 |
39 | 1. For Android, run:
40 |
41 | ```sh
42 | ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android
43 | ```
44 |
45 | 2. For iOS, run:
46 |
47 | ```sh
48 | RCT_NEW_ARCH_ENABLED=1 yarn example pods
49 | yarn example ios
50 | ```
51 |
52 | If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders:
53 |
54 | ```sh
55 | yarn clean
56 | ```
57 |
58 | To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:
59 |
60 | ```sh
61 | Running "LocalizationSettingsExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
62 | ```
63 |
64 | Note the `"fabric":true` and `"concurrentRoot":true` properties.
65 |
66 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
67 |
68 | ```sh
69 | yarn typecheck
70 | yarn lint
71 | ```
72 |
73 | To fix formatting errors, run the following:
74 |
75 | ```sh
76 | yarn lint --fix
77 | ```
78 |
79 | Remember to add tests for your change if possible. Run the unit tests by:
80 |
81 | ```sh
82 | yarn test
83 | ```
84 |
85 | To edit the Objective-C or Swift files, open `example/ios/LocalizationSettingsExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-localization-settings`.
86 |
87 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-localization-settings` under `Android`.
88 |
89 |
90 | ### Commit message convention
91 |
92 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
93 |
94 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
95 | - `feat`: new features, e.g. add new method to the module.
96 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
97 | - `docs`: changes into documentation, e.g. add usage example for the module..
98 | - `test`: adding or updating tests, e.g. add integration tests using detox.
99 | - `chore`: tooling changes, e.g. change CI config.
100 |
101 | Our pre-commit hooks verify that your commit message matches this format when committing.
102 |
103 | ### Linting and tests
104 |
105 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
106 |
107 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
108 |
109 | Our pre-commit hooks verify that the linter and tests pass when committing.
110 |
111 | ### Publishing to npm
112 |
113 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
114 |
115 | To publish new versions, run the following:
116 |
117 | ```sh
118 | yarn release
119 | ```
120 |
121 | ### Scripts
122 |
123 | The `package.json` file contains various scripts for common tasks:
124 |
125 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
126 | - `yarn typecheck`: type-check files with TypeScript.
127 | - `yarn lint`: lint files with ESLint.
128 | - `yarn test`: run unit tests with Jest.
129 | - `yarn example start`: start the Metro server for the example app.
130 | - `yarn example android`: run the example app on Android.
131 | - `yarn example ios`: run the example app on iOS.
132 |
133 | ### Sending a pull request
134 |
135 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
136 |
137 | When you're sending a pull request:
138 |
139 | - Prefer small pull requests focused on one change.
140 | - Verify that linters and tests are passing.
141 | - Review the documentation to make sure it looks good.
142 | - Follow the pull request template when opening a pull request.
143 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
144 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributor Covenant Code of Conduct
3 |
4 | ## Our Pledge
5 |
6 | We as members, contributors, and leaders pledge to make participation in our
7 | community a harassment-free experience for everyone, regardless of age, body
8 | size, visible or invisible disability, ethnicity, sex characteristics, gender
9 | identity and expression, level of experience, education, socio-economic status,
10 | nationality, personal appearance, race, caste, color, religion, or sexual
11 | identity and orientation.
12 |
13 | We pledge to act and interact in ways that contribute to an open, welcoming,
14 | diverse, inclusive, and healthy community.
15 |
16 | ## Our Standards
17 |
18 | Examples of behavior that contributes to a positive environment for our
19 | community include:
20 |
21 | * Demonstrating empathy and kindness toward other people
22 | * Being respectful of differing opinions, viewpoints, and experiences
23 | * Giving and gracefully accepting constructive feedback
24 | * Accepting responsibility and apologizing to those affected by our mistakes,
25 | and learning from the experience
26 | * Focusing on what is best not just for us as individuals, but for the overall
27 | community
28 |
29 | Examples of unacceptable behavior include:
30 |
31 | * The use of sexualized language or imagery, and sexual attention or advances of
32 | any kind
33 | * Trolling, insulting or derogatory comments, and personal or political attacks
34 | * Public or private harassment
35 | * Publishing others' private information, such as a physical or email address,
36 | without their explicit permission
37 | * Other conduct which could reasonably be considered inappropriate in a
38 | professional setting
39 |
40 | ## Enforcement Responsibilities
41 |
42 | Community leaders are responsible for clarifying and enforcing our standards of
43 | acceptable behavior and will take appropriate and fair corrective action in
44 | response to any behavior that they deem inappropriate, threatening, offensive,
45 | or harmful.
46 |
47 | Community leaders have the right and responsibility to remove, edit, or reject
48 | comments, commits, code, wiki edits, issues, and other contributions that are
49 | not aligned to this Code of Conduct, and will communicate reasons for moderation
50 | decisions when appropriate.
51 |
52 | ## Scope
53 |
54 | This Code of Conduct applies within all community spaces, and also applies when
55 | an individual is officially representing the community in public spaces.
56 | Examples of representing our community include using an official e-mail address,
57 | posting via an official social media account, or acting as an appointed
58 | representative at an online or offline event.
59 |
60 | ## Enforcement
61 |
62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
63 | reported to the community leaders responsible for enforcement at
64 | [INSERT CONTACT METHOD].
65 | All complaints will be reviewed and investigated promptly and fairly.
66 |
67 | All community leaders are obligated to respect the privacy and security of the
68 | reporter of any incident.
69 |
70 | ## Enforcement Guidelines
71 |
72 | Community leaders will follow these Community Impact Guidelines in determining
73 | the consequences for any action they deem in violation of this Code of Conduct:
74 |
75 | ### 1. Correction
76 |
77 | **Community Impact**: Use of inappropriate language or other behavior deemed
78 | unprofessional or unwelcome in the community.
79 |
80 | **Consequence**: A private, written warning from community leaders, providing
81 | clarity around the nature of the violation and an explanation of why the
82 | behavior was inappropriate. A public apology may be requested.
83 |
84 | ### 2. Warning
85 |
86 | **Community Impact**: A violation through a single incident or series of
87 | actions.
88 |
89 | **Consequence**: A warning with consequences for continued behavior. No
90 | interaction with the people involved, including unsolicited interaction with
91 | those enforcing the Code of Conduct, for a specified period of time. This
92 | includes avoiding interactions in community spaces as well as external channels
93 | like social media. Violating these terms may lead to a temporary or permanent
94 | ban.
95 |
96 | ### 3. Temporary Ban
97 |
98 | **Community Impact**: A serious violation of community standards, including
99 | sustained inappropriate behavior.
100 |
101 | **Consequence**: A temporary ban from any sort of interaction or public
102 | communication with the community for a specified period of time. No public or
103 | private interaction with the people involved, including unsolicited interaction
104 | with those enforcing the Code of Conduct, is allowed during this period.
105 | Violating these terms may lead to a permanent ban.
106 |
107 | ### 4. Permanent Ban
108 |
109 | **Community Impact**: Demonstrating a pattern of violation of community
110 | standards, including sustained inappropriate behavior, harassment of an
111 | individual, or aggression toward or disparagement of classes of individuals.
112 |
113 | **Consequence**: A permanent ban from any sort of public interaction within the
114 | community.
115 |
116 | ## Attribution
117 |
118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119 | version 2.1, available at
120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121 |
122 | Community Impact Guidelines were inspired by
123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124 |
125 | For answers to common questions about this code of conduct, see the FAQ at
126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127 | [https://www.contributor-covenant.org/translations][translations].
128 |
129 | [homepage]: https://www.contributor-covenant.org
130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131 | [Mozilla CoC]: https://github.com/mozilla/diversity
132 | [FAQ]: https://www.contributor-covenant.org/faq
133 | [translations]: https://www.contributor-covenant.org/translations
134 |
--------------------------------------------------------------------------------
/example-expo/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 | apply plugin: "org.jetbrains.kotlin.android"
3 | apply plugin: "com.facebook.react"
4 |
5 | def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
6 |
7 | /**
8 | * This is the configuration block to customize your React Native Android app.
9 | * By default you don't need to apply any configuration, just uncomment the lines you need.
10 | */
11 | react {
12 | entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
13 | reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
14 | hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
15 | codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
16 |
17 | // Use Expo CLI to bundle the app, this ensures the Metro config
18 | // works correctly with Expo projects.
19 | cliFile = new File(["node", "--print", "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })"].execute(null, rootDir).text.trim())
20 | bundleCommand = "export:embed"
21 |
22 | /* Folders */
23 | // The root of your project, i.e. where "package.json" lives. Default is '../..'
24 | // root = file("../../")
25 | // The folder where the react-native NPM package is. Default is ../../node_modules/react-native
26 | // reactNativeDir = file("../../node_modules/react-native")
27 | // The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
28 | // codegenDir = file("../../node_modules/@react-native/codegen")
29 |
30 | /* Variants */
31 | // The list of variants to that are debuggable. For those we're going to
32 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
33 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
34 | // debuggableVariants = ["liteDebug", "prodDebug"]
35 |
36 | /* Bundling */
37 | // A list containing the node command and its flags. Default is just 'node'.
38 | // nodeExecutableAndArgs = ["node"]
39 |
40 | //
41 | // The path to the CLI configuration file. Default is empty.
42 | // bundleConfig = file(../rn-cli.config.js)
43 | //
44 | // The name of the generated asset file containing your JS bundle
45 | // bundleAssetName = "MyApplication.android.bundle"
46 | //
47 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
48 | // entryFile = file("../js/MyApplication.android.js")
49 | //
50 | // A list of extra flags to pass to the 'bundle' commands.
51 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
52 | // extraPackagerArgs = []
53 |
54 | /* Hermes Commands */
55 | // The hermes compiler command to run. By default it is 'hermesc'
56 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
57 | //
58 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
59 | // hermesFlags = ["-O", "-output-source-map"]
60 |
61 | /* Autolinking */
62 | autolinkLibrariesWithApp()
63 | }
64 |
65 | /**
66 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
67 | */
68 | def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()
69 |
70 | /**
71 | * The preferred build flavor of JavaScriptCore (JSC)
72 | *
73 | * For example, to use the international variant, you can use:
74 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
75 | *
76 | * The international variant includes ICU i18n library and necessary data
77 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
78 | * give correct results when using with locales other than en-US. Note that
79 | * this variant is about 6MiB larger per architecture than default.
80 | */
81 | def jscFlavor = 'org.webkit:android-jsc:+'
82 |
83 | android {
84 | ndkVersion rootProject.ext.ndkVersion
85 |
86 | buildToolsVersion rootProject.ext.buildToolsVersion
87 | compileSdk rootProject.ext.compileSdkVersion
88 |
89 | namespace 'pl.jakubgrzywacz.exampleexpo'
90 | defaultConfig {
91 | applicationId 'pl.jakubgrzywacz.exampleexpo'
92 | minSdkVersion rootProject.ext.minSdkVersion
93 | targetSdkVersion rootProject.ext.targetSdkVersion
94 | versionCode 1
95 | versionName "1.0.0"
96 | }
97 | signingConfigs {
98 | debug {
99 | storeFile file('debug.keystore')
100 | storePassword 'android'
101 | keyAlias 'androiddebugkey'
102 | keyPassword 'android'
103 | }
104 | }
105 | buildTypes {
106 | debug {
107 | signingConfig signingConfigs.debug
108 | }
109 | release {
110 | // Caution! In production, you need to generate your own keystore file.
111 | // see https://reactnative.dev/docs/signed-apk-android.
112 | signingConfig signingConfigs.debug
113 | shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
114 | minifyEnabled enableProguardInReleaseBuilds
115 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
116 | crunchPngs (findProperty('android.enablePngCrunchInReleaseBuilds')?.toBoolean() ?: true)
117 | }
118 | }
119 | packagingOptions {
120 | jniLibs {
121 | useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
122 | }
123 | }
124 | androidResources {
125 | ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
126 | }
127 | }
128 |
129 | // Apply static values from `gradle.properties` to the `android.packagingOptions`
130 | // Accepts values in comma delimited lists, example:
131 | // android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
132 | ["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
133 | // Split option: 'foo,bar' -> ['foo', 'bar']
134 | def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
135 | // Trim all elements in place.
136 | for (i in 0.. 0) {
141 | println "android.packagingOptions.$prop += $options ($options.length)"
142 | // Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
143 | options.each {
144 | android.packagingOptions[prop] += it
145 | }
146 | }
147 | }
148 |
149 | dependencies {
150 | // The version of react-native is set by the React Native Gradle Plugin
151 | implementation("com.facebook.react:react-android")
152 |
153 | def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
154 | def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
155 | def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
156 |
157 | if (isGifEnabled) {
158 | // For animated gif support
159 | implementation("com.facebook.fresco:animated-gif:${reactAndroidLibs.versions.fresco.get()}")
160 | }
161 |
162 | if (isWebpEnabled) {
163 | // For webp support
164 | implementation("com.facebook.fresco:webpsupport:${reactAndroidLibs.versions.fresco.get()}")
165 | if (isWebpAnimatedEnabled) {
166 | // Animated webp support
167 | implementation("com.facebook.fresco:animated-webp:${reactAndroidLibs.versions.fresco.get()}")
168 | }
169 | }
170 |
171 | if (hermesEnabled.toBoolean()) {
172 | implementation("com.facebook.react:hermes-android")
173 | } else {
174 | implementation jscFlavor
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90 | ' "$PWD" ) || exit
91 |
92 | # Use the maximum available, or set MAX_FD != -1 to use that value.
93 | MAX_FD=maximum
94 |
95 | warn () {
96 | echo "$*"
97 | } >&2
98 |
99 | die () {
100 | echo
101 | echo "$*"
102 | echo
103 | exit 1
104 | } >&2
105 |
106 | # OS specific support (must be 'true' or 'false').
107 | cygwin=false
108 | msys=false
109 | darwin=false
110 | nonstop=false
111 | case "$( uname )" in #(
112 | CYGWIN* ) cygwin=true ;; #(
113 | Darwin* ) darwin=true ;; #(
114 | MSYS* | MINGW* ) msys=true ;; #(
115 | NONSTOP* ) nonstop=true ;;
116 | esac
117 |
118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
119 |
120 |
121 | # Determine the Java command to use to start the JVM.
122 | if [ -n "$JAVA_HOME" ] ; then
123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
124 | # IBM's JDK on AIX uses strange locations for the executables
125 | JAVACMD=$JAVA_HOME/jre/sh/java
126 | else
127 | JAVACMD=$JAVA_HOME/bin/java
128 | fi
129 | if [ ! -x "$JAVACMD" ] ; then
130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
131 |
132 | Please set the JAVA_HOME variable in your environment to match the
133 | location of your Java installation."
134 | fi
135 | else
136 | JAVACMD=java
137 | if ! command -v java >/dev/null 2>&1
138 | then
139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
140 |
141 | Please set the JAVA_HOME variable in your environment to match the
142 | location of your Java installation."
143 | fi
144 | fi
145 |
146 | # Increase the maximum file descriptors if we can.
147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
148 | case $MAX_FD in #(
149 | max*)
150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
151 | # shellcheck disable=SC2039,SC3045
152 | MAX_FD=$( ulimit -H -n ) ||
153 | warn "Could not query maximum file descriptor limit"
154 | esac
155 | case $MAX_FD in #(
156 | '' | soft) :;; #(
157 | *)
158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
159 | # shellcheck disable=SC2039,SC3045
160 | ulimit -n "$MAX_FD" ||
161 | warn "Could not set maximum file descriptor limit to $MAX_FD"
162 | esac
163 | fi
164 |
165 | # Collect all arguments for the java command, stacking in reverse order:
166 | # * args from the command line
167 | # * the main class name
168 | # * -classpath
169 | # * -D...appname settings
170 | # * --module-path (only if needed)
171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
172 |
173 | # For Cygwin or MSYS, switch paths to Windows format before running java
174 | if "$cygwin" || "$msys" ; then
175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
177 |
178 | JAVACMD=$( cygpath --unix "$JAVACMD" )
179 |
180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
181 | for arg do
182 | if
183 | case $arg in #(
184 | -*) false ;; # don't mess with options #(
185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
186 | [ -e "$t" ] ;; #(
187 | *) false ;;
188 | esac
189 | then
190 | arg=$( cygpath --path --ignore --mixed "$arg" )
191 | fi
192 | # Roll the args list around exactly as many times as the number of
193 | # args, so each arg winds up back in the position where it started, but
194 | # possibly modified.
195 | #
196 | # NB: a `for` loop captures its iteration list before it begins, so
197 | # changing the positional parameters here affects neither the number of
198 | # iterations, nor the values presented in `arg`.
199 | shift # remove old arg
200 | set -- "$@" "$arg" # push replacement arg
201 | done
202 | fi
203 |
204 |
205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207 |
208 | # Collect all arguments for the java command:
209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210 | # and any embedded shellness will be escaped.
211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212 | # treated as '${Hostname}' itself on the command line.
213 |
214 | set -- \
215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
216 | -classpath "$CLASSPATH" \
217 | org.gradle.wrapper.GradleWrapperMain \
218 | "$@"
219 |
220 | # Stop when "xargs" is not available.
221 | if ! command -v xargs >/dev/null 2>&1
222 | then
223 | die "xargs is not available"
224 | fi
225 |
226 | # Use "xargs" to parse quoted args.
227 | #
228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
229 | #
230 | # In Bash we could simply go:
231 | #
232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
233 | # set -- "${ARGS[@]}" "$@"
234 | #
235 | # but POSIX shell has neither arrays nor command substitution, so instead we
236 | # post-process each arg (as a line of input to sed) to backslash-escape any
237 | # character that might be a shell metacharacter, then use eval to reverse
238 | # that process (while maintaining the separation between arguments), and wrap
239 | # the whole thing up as a single "set" statement.
240 | #
241 | # This will of course break if any of these variables contains a newline or
242 | # an unmatched quote.
243 | #
244 |
245 | eval "set -- $(
246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
247 | xargs -n1 |
248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
249 | tr '\n' ' '
250 | )" '"$@"'
251 |
252 | exec "$JAVACMD" "$@"
253 |
--------------------------------------------------------------------------------
/example-expo/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90 | ' "$PWD" ) || exit
91 |
92 | # Use the maximum available, or set MAX_FD != -1 to use that value.
93 | MAX_FD=maximum
94 |
95 | warn () {
96 | echo "$*"
97 | } >&2
98 |
99 | die () {
100 | echo
101 | echo "$*"
102 | echo
103 | exit 1
104 | } >&2
105 |
106 | # OS specific support (must be 'true' or 'false').
107 | cygwin=false
108 | msys=false
109 | darwin=false
110 | nonstop=false
111 | case "$( uname )" in #(
112 | CYGWIN* ) cygwin=true ;; #(
113 | Darwin* ) darwin=true ;; #(
114 | MSYS* | MINGW* ) msys=true ;; #(
115 | NONSTOP* ) nonstop=true ;;
116 | esac
117 |
118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
119 |
120 |
121 | # Determine the Java command to use to start the JVM.
122 | if [ -n "$JAVA_HOME" ] ; then
123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
124 | # IBM's JDK on AIX uses strange locations for the executables
125 | JAVACMD=$JAVA_HOME/jre/sh/java
126 | else
127 | JAVACMD=$JAVA_HOME/bin/java
128 | fi
129 | if [ ! -x "$JAVACMD" ] ; then
130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
131 |
132 | Please set the JAVA_HOME variable in your environment to match the
133 | location of your Java installation."
134 | fi
135 | else
136 | JAVACMD=java
137 | if ! command -v java >/dev/null 2>&1
138 | then
139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
140 |
141 | Please set the JAVA_HOME variable in your environment to match the
142 | location of your Java installation."
143 | fi
144 | fi
145 |
146 | # Increase the maximum file descriptors if we can.
147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
148 | case $MAX_FD in #(
149 | max*)
150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
151 | # shellcheck disable=SC2039,SC3045
152 | MAX_FD=$( ulimit -H -n ) ||
153 | warn "Could not query maximum file descriptor limit"
154 | esac
155 | case $MAX_FD in #(
156 | '' | soft) :;; #(
157 | *)
158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
159 | # shellcheck disable=SC2039,SC3045
160 | ulimit -n "$MAX_FD" ||
161 | warn "Could not set maximum file descriptor limit to $MAX_FD"
162 | esac
163 | fi
164 |
165 | # Collect all arguments for the java command, stacking in reverse order:
166 | # * args from the command line
167 | # * the main class name
168 | # * -classpath
169 | # * -D...appname settings
170 | # * --module-path (only if needed)
171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
172 |
173 | # For Cygwin or MSYS, switch paths to Windows format before running java
174 | if "$cygwin" || "$msys" ; then
175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
177 |
178 | JAVACMD=$( cygpath --unix "$JAVACMD" )
179 |
180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
181 | for arg do
182 | if
183 | case $arg in #(
184 | -*) false ;; # don't mess with options #(
185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
186 | [ -e "$t" ] ;; #(
187 | *) false ;;
188 | esac
189 | then
190 | arg=$( cygpath --path --ignore --mixed "$arg" )
191 | fi
192 | # Roll the args list around exactly as many times as the number of
193 | # args, so each arg winds up back in the position where it started, but
194 | # possibly modified.
195 | #
196 | # NB: a `for` loop captures its iteration list before it begins, so
197 | # changing the positional parameters here affects neither the number of
198 | # iterations, nor the values presented in `arg`.
199 | shift # remove old arg
200 | set -- "$@" "$arg" # push replacement arg
201 | done
202 | fi
203 |
204 |
205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207 |
208 | # Collect all arguments for the java command:
209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210 | # and any embedded shellness will be escaped.
211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212 | # treated as '${Hostname}' itself on the command line.
213 |
214 | set -- \
215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
216 | -classpath "$CLASSPATH" \
217 | org.gradle.wrapper.GradleWrapperMain \
218 | "$@"
219 |
220 | # Stop when "xargs" is not available.
221 | if ! command -v xargs >/dev/null 2>&1
222 | then
223 | die "xargs is not available"
224 | fi
225 |
226 | # Use "xargs" to parse quoted args.
227 | #
228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
229 | #
230 | # In Bash we could simply go:
231 | #
232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
233 | # set -- "${ARGS[@]}" "$@"
234 | #
235 | # but POSIX shell has neither arrays nor command substitution, so instead we
236 | # post-process each arg (as a line of input to sed) to backslash-escape any
237 | # character that might be a shell metacharacter, then use eval to reverse
238 | # that process (while maintaining the separation between arguments), and wrap
239 | # the whole thing up as a single "set" statement.
240 | #
241 | # This will of course break if any of these variables contains a newline or
242 | # an unmatched quote.
243 | #
244 |
245 | eval "set -- $(
246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
247 | xargs -n1 |
248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
249 | tr '\n' ' '
250 | )" '"$@"'
251 |
252 | exec "$JAVACMD" "$@"
253 |
--------------------------------------------------------------------------------
/ios/LocalizationSettings.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 5E555C0D2413F4C50049A1A2 /* LocalizationSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* LocalizationSettings.m */; };
11 | /* End PBXBuildFile section */
12 |
13 | /* Begin PBXCopyFilesBuildPhase section */
14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = {
15 | isa = PBXCopyFilesBuildPhase;
16 | buildActionMask = 2147483647;
17 | dstPath = "include/$(PRODUCT_NAME)";
18 | dstSubfolderSpec = 16;
19 | files = (
20 | );
21 | runOnlyForDeploymentPostprocessing = 0;
22 | };
23 | /* End PBXCopyFilesBuildPhase section */
24 |
25 | /* Begin PBXFileReference section */
26 | 134814201AA4EA6300B7C361 /* libLocalizationSettings.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLocalizationSettings.a; sourceTree = BUILT_PRODUCTS_DIR; };
27 | B3E7B5881CC2AC0600A0062D /* LocalizationSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationSettings.h; sourceTree = ""; };
28 | B3E7B5891CC2AC0600A0062D /* LocalizationSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationSettings.m; sourceTree = ""; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 58B511D81A9E6C8500147676 /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | );
37 | runOnlyForDeploymentPostprocessing = 0;
38 | };
39 | /* End PBXFrameworksBuildPhase section */
40 |
41 | /* Begin PBXGroup section */
42 | 134814211AA4EA7D00B7C361 /* Products */ = {
43 | isa = PBXGroup;
44 | children = (
45 | 134814201AA4EA6300B7C361 /* libLocalizationSettings.a */,
46 | );
47 | name = Products;
48 | sourceTree = "";
49 | };
50 | 58B511D21A9E6C8500147676 = {
51 | isa = PBXGroup;
52 | children = (
53 | B3E7B5881CC2AC0600A0062D /* LocalizationSettings.h */,
54 | B3E7B5891CC2AC0600A0062D /* LocalizationSettings.m */,
55 | 134814211AA4EA7D00B7C361 /* Products */,
56 | );
57 | sourceTree = "";
58 | };
59 | /* End PBXGroup section */
60 |
61 | /* Begin PBXNativeTarget section */
62 | 58B511DA1A9E6C8500147676 /* LocalizationSettings */ = {
63 | isa = PBXNativeTarget;
64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "LocalizationSettings" */;
65 | buildPhases = (
66 | 58B511D71A9E6C8500147676 /* Sources */,
67 | 58B511D81A9E6C8500147676 /* Frameworks */,
68 | 58B511D91A9E6C8500147676 /* CopyFiles */,
69 | );
70 | buildRules = (
71 | );
72 | dependencies = (
73 | );
74 | name = LocalizationSettings;
75 | productName = RCTDataManager;
76 | productReference = 134814201AA4EA6300B7C361 /* libLocalizationSettings.a */;
77 | productType = "com.apple.product-type.library.static";
78 | };
79 | /* End PBXNativeTarget section */
80 |
81 | /* Begin PBXProject section */
82 | 58B511D31A9E6C8500147676 /* Project object */ = {
83 | isa = PBXProject;
84 | attributes = {
85 | LastUpgradeCheck = 0920;
86 | ORGANIZATIONNAME = Facebook;
87 | TargetAttributes = {
88 | 58B511DA1A9E6C8500147676 = {
89 | CreatedOnToolsVersion = 6.1.1;
90 | };
91 | };
92 | };
93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "LocalizationSettings" */;
94 | compatibilityVersion = "Xcode 3.2";
95 | developmentRegion = English;
96 | hasScannedForEncodings = 0;
97 | knownRegions = (
98 | English,
99 | en,
100 | );
101 | mainGroup = 58B511D21A9E6C8500147676;
102 | productRefGroup = 58B511D21A9E6C8500147676;
103 | projectDirPath = "";
104 | projectRoot = "";
105 | targets = (
106 | 58B511DA1A9E6C8500147676 /* LocalizationSettings */,
107 | );
108 | };
109 | /* End PBXProject section */
110 |
111 | /* Begin PBXSourcesBuildPhase section */
112 | 58B511D71A9E6C8500147676 /* Sources */ = {
113 | isa = PBXSourcesBuildPhase;
114 | buildActionMask = 2147483647;
115 | files = (
116 | B3E7B58A1CC2AC0600A0062D /* LocalizationSettings.m in Sources */,
117 | );
118 | runOnlyForDeploymentPostprocessing = 0;
119 | };
120 | /* End PBXSourcesBuildPhase section */
121 |
122 | /* Begin XCBuildConfiguration section */
123 | 58B511ED1A9E6C8500147676 /* Debug */ = {
124 | isa = XCBuildConfiguration;
125 | buildSettings = {
126 | ALWAYS_SEARCH_USER_PATHS = NO;
127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
128 | CLANG_CXX_LIBRARY = "libc++";
129 | CLANG_ENABLE_MODULES = YES;
130 | CLANG_ENABLE_OBJC_ARC = YES;
131 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
132 | CLANG_WARN_BOOL_CONVERSION = YES;
133 | CLANG_WARN_COMMA = YES;
134 | CLANG_WARN_CONSTANT_CONVERSION = YES;
135 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
136 | CLANG_WARN_EMPTY_BODY = YES;
137 | CLANG_WARN_ENUM_CONVERSION = YES;
138 | CLANG_WARN_INFINITE_RECURSION = YES;
139 | CLANG_WARN_INT_CONVERSION = YES;
140 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
141 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
142 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
143 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
144 | CLANG_WARN_STRICT_PROTOTYPES = YES;
145 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
146 | CLANG_WARN_UNREACHABLE_CODE = YES;
147 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
148 | COPY_PHASE_STRIP = NO;
149 | ENABLE_STRICT_OBJC_MSGSEND = YES;
150 | ENABLE_TESTABILITY = YES;
151 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
152 | GCC_C_LANGUAGE_STANDARD = gnu99;
153 | GCC_DYNAMIC_NO_PIC = NO;
154 | GCC_NO_COMMON_BLOCKS = YES;
155 | GCC_OPTIMIZATION_LEVEL = 0;
156 | GCC_PREPROCESSOR_DEFINITIONS = (
157 | "DEBUG=1",
158 | "$(inherited)",
159 | );
160 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
161 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
162 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
163 | GCC_WARN_UNDECLARED_SELECTOR = YES;
164 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
165 | GCC_WARN_UNUSED_FUNCTION = YES;
166 | GCC_WARN_UNUSED_VARIABLE = YES;
167 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
168 | MTL_ENABLE_DEBUG_INFO = YES;
169 | ONLY_ACTIVE_ARCH = YES;
170 | SDKROOT = iphoneos;
171 | };
172 | name = Debug;
173 | };
174 | 58B511EE1A9E6C8500147676 /* Release */ = {
175 | isa = XCBuildConfiguration;
176 | buildSettings = {
177 | ALWAYS_SEARCH_USER_PATHS = NO;
178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
179 | CLANG_CXX_LIBRARY = "libc++";
180 | CLANG_ENABLE_MODULES = YES;
181 | CLANG_ENABLE_OBJC_ARC = YES;
182 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
183 | CLANG_WARN_BOOL_CONVERSION = YES;
184 | CLANG_WARN_COMMA = YES;
185 | CLANG_WARN_CONSTANT_CONVERSION = YES;
186 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
187 | CLANG_WARN_EMPTY_BODY = YES;
188 | CLANG_WARN_ENUM_CONVERSION = YES;
189 | CLANG_WARN_INFINITE_RECURSION = YES;
190 | CLANG_WARN_INT_CONVERSION = YES;
191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
192 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
194 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
195 | CLANG_WARN_STRICT_PROTOTYPES = YES;
196 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
197 | CLANG_WARN_UNREACHABLE_CODE = YES;
198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
199 | COPY_PHASE_STRIP = YES;
200 | ENABLE_NS_ASSERTIONS = NO;
201 | ENABLE_STRICT_OBJC_MSGSEND = YES;
202 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
203 | GCC_C_LANGUAGE_STANDARD = gnu99;
204 | GCC_NO_COMMON_BLOCKS = YES;
205 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
206 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
207 | GCC_WARN_UNDECLARED_SELECTOR = YES;
208 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
209 | GCC_WARN_UNUSED_FUNCTION = YES;
210 | GCC_WARN_UNUSED_VARIABLE = YES;
211 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
212 | MTL_ENABLE_DEBUG_INFO = NO;
213 | SDKROOT = iphoneos;
214 | VALIDATE_PRODUCT = YES;
215 | };
216 | name = Release;
217 | };
218 | 58B511F01A9E6C8500147676 /* Debug */ = {
219 | isa = XCBuildConfiguration;
220 | buildSettings = {
221 | HEADER_SEARCH_PATHS = (
222 | "$(inherited)",
223 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
224 | "$(SRCROOT)/../../../React/**",
225 | "$(SRCROOT)/../../react-native/React/**",
226 | );
227 | LIBRARY_SEARCH_PATHS = "$(inherited)";
228 | OTHER_LDFLAGS = "-ObjC";
229 | PRODUCT_NAME = LocalizationSettings;
230 | SKIP_INSTALL = YES;
231 | };
232 | name = Debug;
233 | };
234 | 58B511F11A9E6C8500147676 /* Release */ = {
235 | isa = XCBuildConfiguration;
236 | buildSettings = {
237 | HEADER_SEARCH_PATHS = (
238 | "$(inherited)",
239 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
240 | "$(SRCROOT)/../../../React/**",
241 | "$(SRCROOT)/../../react-native/React/**",
242 | );
243 | LIBRARY_SEARCH_PATHS = "$(inherited)";
244 | OTHER_LDFLAGS = "-ObjC";
245 | PRODUCT_NAME = LocalizationSettings;
246 | SKIP_INSTALL = YES;
247 | };
248 | name = Release;
249 | };
250 | /* End XCBuildConfiguration section */
251 |
252 | /* Begin XCConfigurationList section */
253 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "LocalizationSettings" */ = {
254 | isa = XCConfigurationList;
255 | buildConfigurations = (
256 | 58B511ED1A9E6C8500147676 /* Debug */,
257 | 58B511EE1A9E6C8500147676 /* Release */,
258 | );
259 | defaultConfigurationIsVisible = 0;
260 | defaultConfigurationName = Release;
261 | };
262 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "LocalizationSettings" */ = {
263 | isa = XCConfigurationList;
264 | buildConfigurations = (
265 | 58B511F01A9E6C8500147676 /* Debug */,
266 | 58B511F11A9E6C8500147676 /* Release */,
267 | );
268 | defaultConfigurationIsVisible = 0;
269 | defaultConfigurationName = Release;
270 | };
271 | /* End XCConfigurationList section */
272 | };
273 | rootObject = 58B511D31A9E6C8500147676 /* Project object */;
274 | }
275 |
--------------------------------------------------------------------------------