npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ahmedrowaihi/react-native-i18n-storage

v2.0.5

Published

React Native I18n Storage is a simple library to manage your app's I18nManager settings and language by keeping them in sync with local storage from the initial native app launch!.

Downloads

3

Readme

react-native-i18n-storage

Sync your I18n Manager from Native Side Without hassle!

Why?

React Native I18n Storage is a simple library to manage your app's I18nManager settings and language by keeping them in sync with local storage from the initial native app launch! Which means that you can change the locale from native side and the app will restart with the new locale from the local storage!

Conventions

  • Locale and Layout are initialized from the first native app launch, and then they are kept in sync with the local storage.
  • saves huge performance cost by not using hooks or context
  • keeps your code clean and simple
  • use Locale and RTL IN/OUT of React Components and they will be kept in sync with the local storage
  • No need to change your code logic
  • No need to change your code structure or architecture
  • No need to change your code style
  • No need to change your code design pattern
  • No need to change your code design pattern
  • No need to change your code anything 😅

Prerequisites

if you have not installed them yet, you can install them by running the following commands:

// you can use npm instead of yarn
yarn add @react-native-async-storage/async-storage react-native-restart

Installation

// you can use npm instead of yarn
yarn add @ahmedrowaihi/react-native-i18n-storage

Setup

iOS

1. import headers into your AppDelegate.mm:

// ios/your-app-name/AppDelegate.mm
#import "AppDelegate.h"
#import <I18nStorage.h>

2. modify AppDelegate.mm file inside didFinishLaunchingWithOptions method:

// ios/your-app-name/AppDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  I18nStorage *i18nStorage = [[I18nStorage alloc] init]; // <--- Add this line at the top
  [i18nStorage SyncI18nStorage]; // <- call the SyncI18nStorage method
  // rest of the code ...
}

Android

1. import package to your MainApplication.java

// android/app/src/main/java/com/your-app-name/MainApplication.java
import com.facebook.react.ReactApplication;
import com.i18nstorage.I18nStorageUtility; // <-- Add this line
// ... rest of the imports

2. Add the following code to your MainApplication.java file inside onCreate method:

// android/app/src/main/java/com/your-app-name/MainApplication.java
@Override
public void onCreate() {
  super.onCreate();
  I18nStorageUtility.SyncI18nStorage(this); // <-- Add this line
  // rest of the code ...
}

Usage

change the locale and Restart the app

import { setI18nStorage } from '@ahmedrowaihi/react-native-i18n-storage';
import { Platform, Settings } from 'react-native';

await setI18nStorage({
  locale: 'ar', // or any other locale
  forceRTL: true, // or false
  allowRTL: true, // or false
  doLeftAndRightSwapInRTL: true, // or false
});

or with optional parameters

await setI18nStorage(
  {
    locale: 'ar', // or any other locale
    forceRTL: true, // or false
    allowRTL: true, // or false
    doLeftAndRightSwapInRTL: true, // or false
  },
  false, // (restart) default is true
  () => {} // (callback before restart) default is undefined
);

get the locale and RTL from the local storage

/**
 * @returns {Promise<{locale: string, forceRTL: boolean, allowRTL: boolean, doLeftAndRightSwapInRTL: boolean}>}
 */
import { getI18nStorage } from '@ahmedrowaihi/react-native-i18n-storage';
const I18nStorage = await getI18nStorage();

reset the locale and RTL to the default values

import { resetI18nStorage } from '@ahmedrowaihi/react-native-i18n-storage';
await resetI18nStorage();

or with optional parameters

await resetI18nStorage(
  false, // (restart) default is true
  () => {} // (callback before restart) default is undefined
);

Roadmap

  • [x] Allow to change the locale from native side
  • [x] Add example of changing the locale from native side
  • [x] On App Launch, check if the locale is changed from native side (iOS)
  • [x] On App Launch, check if the locale is changed from native side (Android)
  • [x] On App Launch implementations to example
  • [x] Proof of concept for RTL Storage and Sync from native side!
  • [x] Add/Fix JavaScript Methods
  • [x] Refactor Native Code + JavaScript Code
  • [x] Write docs
  • [ ] Write tests

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

development workflow.

License

MIT