Socket
Socket
Sign inDemoInstall

react-native-locale-listener

Package Overview
Dependencies
719
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-locale-listener

The library allows you to listen to locale changes on your device. for example reloading the app when the locale changed. ## Getting started


Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
1
Install size
77.1 kB
Created
Weekly downloads
 

Readme

Source

react-native-locale-listener

The library allows you to listen to locale changes on your device. for example reloading the app when the locale changed.

Getting started

$ npm install react-native-locale-listener --save

Mostly automatic installation

$ react-native link react-native-locale-listener

Manual installation

Android
  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.toyberman.localeReload.RNReactNativeLocalePackage; to the imports at the top of the file
  • Add new RNReactNativeLocalePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-locale-listener'
    project(':react-native-locale-listener').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-locale-listener/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-locale-listener')
    

Usage

add to AndroidManifest.xml this :

android:configChanges="layoutDirection|locale"

and to MainActivity.java

import android.content.res.Configuration;
import android.content.Intent;
...
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Intent intent = new Intent("onConfigurationChanged");
    intent.putExtra("newConfig", newConfig);
    this.sendBroadcast(intent);
}

you can use it anywhere

import RNReactNativeLocale from 'react-native-locale-listener';

changeLayout(language) {
    // Do what you need here
    RNRestart.Restart();
}

componentDidMount () {
  RNReactNativeLocale.addLocaleListener(this.changeLayout)
}

componentWillUnmount() {
  // prevent leaking
  RNReactNativeLocale.removeLocaleListener(this.changeLayout)
}

Keywords

FAQs

Last updated on 22 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc