Comments (14)
I came to the conclusion that achieving this without the I18nManager is better for now, due to the overall lack of support. Instead, we can play with Flexbox, although it requires spending more time. Here is a quick Snack about this.
import React, { Component } from 'react';
import { Button, LayoutAnimation, Text, UIManager, View } from 'react-native';
export default class App extends Component {
state = { rtl: false };
componentWillMount() {
if (UIManager.setLayoutAnimationEnabledExperimental)
UIManager.setLayoutAnimationEnabledExperimental(true);
}
componentWillUpdate() {
LayoutAnimation.spring();
}
render() {
const rtlText = this.state.rtl && { textAlign: 'right', writingDirection: 'rtl' };
const rtlView = this.state.rtl && { flexDirection: 'row-reverse' };
return (
<View style={{ flex: 1, justifyContent: 'center', padding: 40 }}>
<Text style={[{ color: '#444', fontSize: 36, marginBottom: 40 }, rtlText]}>
{this.state.rtl ? 'أهلاً بالعالم!' : 'Hello World!'}
</Text>
<View style={[{ flexDirection: 'row', marginBottom: 40 }, rtlView]}>
<View style={{ height: 40, width: 40, backgroundColor: '#db4437' }} />
<View style={{ height: 40, width: 40, backgroundColor: '#0f9d58' }} />
<View style={{ height: 40, width: 40, backgroundColor: '#4285f4' }} />
</View>
<Button
color="#444"
onPress={() => this.setState({ rtl: !this.state.rtl })}
title={this.state.rtl ? 'English' : 'العربية'}
/>
</View>
);
}
}
from expo.
+1 react-native-i18n 😊
from expo.
done! https://docs.getexponent.com/versions/v11.0.0/sdk/util.html#Exponent.Util.getCurrentLocaleAsync
from expo.
For people finding this issue and still struggling - i made a sample how to translate your expo app using react-i18next and includes:
- setting language from device language using expo.utils
- react-navigation (you will need that at some point)
https://github.com/locize/locize-examples/tree/master/react-native-expo
from expo.
Important when looking for an i18n package: Just use this one: https://github.com/fnando/i18n-js
AlexanderZaytsev/react-native-i18n#77 (comment)
from expo.
I just hope that Expo.Util.reload() would work as well on a stand alone app. Didn't get to test it yet.
It doesn't.
from expo.
I just hope that Expo.Util.reload() would work as well on a stand alone app. Didn't get to test it yet.
Yes it does @sonaye. Why do you think it doesn't? Did you try it?
from expo.
@eldadcaspi react-i18next gives you the option to get the information for a language if rtl or ltr: http://i18next.com/docs/api/#dir
but not more...but suggestions are welcome...
from expo.
Coming in sdk11!
from expo.
Another solution => https://github.com/xcarpentier/ex-react-native-i18n
from expo.
Hi guys,
Do you happen to know if any of the above libraries would support RTL language as a default language and would assist to load the app in RTL layout mode?
I'm working on a single RTL language app (Hebrew) and am struggling with loading my Expo based app on RTL layout mode as a default. I wonder if a localization library like the ones you suggest here could help (currently i'm using i18Manager.forceRTL(), but it requires a restart of the app to load the app in RTL mode).
Thanks!
from expo.
Thanks @jamuhl,
Solved it for now with a dirty fix.
So, if anyone might find it useful, when you're using expo for a single rtl language app and need the user to load the app in rtl layout mode at the very first time she'd open the app (without asking her to restart), just reload the app till the forceURL() kicks in (one reload, feels pretty seamless).
In my main.js:
componentWillMount() {
if (!I18nManager.isRTL){
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
Expo.Util.reload();
}
}
- I just hope that Expo.Util.reload() would work as well on a stand alone app. Didn't get to test it yet.
- You don't have to put in in a lifecycle method, worked fine above the root component as well
from expo.
@jesseruder I have tried it yes, Util.reload() does reload the experience, but the rtl/ltr I18nManager props don't take effect properly (they do when running in the expo client but not as standalone, same code), you'd have to ask the user to close the app completely or to detect the locale of the device at start up and work your way out from there.
from expo.
Ok that sounds like a separate issue. Feel free to create a new issue about that.
from expo.
Related Issues (20)
- How to install Expo into bare ReactNative with altered AppDelegate HOT 1
- [docs] AuthSession's useAuthRequest's promptAsync accepts WebBrowser's AuthSessionOpenOptions
- Individual ./gradlew assembleRelease do not load .env enviroment variables automatically HOT 2
- Module API Reference - not describe how to use Promise
- Expo-camera isn't functioning on my MacBook, but works on my Windows PC (web only) HOT 2
- Metro error: Unable to resolve module u/unimodules/core from expo-splash-screen/build/SplashScreen.js HOT 1
- Exception java.lang.ClassCastException: r1.j cannot be cast to m1.a at android.view.View.performClick (View.java:7870) at android.view.View.performClickInternal (View.java:7839) at android.view.View.access$3600 (View.java:886) at android.view.View$PerformClick.run (View.java:29363) at android.os.Handler.handleCallback (Handler.java:883) at android.os.Handler.dispatchMessage (Handler.java:100) at android.os.Looper.loop (Looper.java:237) at android.app.ActivityThread.main (ActivityThread.java:7948) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075) HOT 1
- [router] Routing from Push Notification on Android not working
- RN: CommandError: Can't determine id of Simulator HOT 9
- Request for Assistance with Expo Router Tab Behavior on Different Device Sizes HOT 1
- XMLHttpRequest will randomly throw network error in TestFlight Production Environment HOT 2
- Hide the Skip/forward button and Slider on the expo-av HOT 2
- [Android][Expo Go] Image request headers seem not to be set
- Automatic Signing Forced on iOS HOT 1
- API routes with a "." prefix are not able to be exported HOT 4
- Unmatched route issue in ios/android build but doesn't show in expo go app. HOT 2
- expo-av not handling chunked audio & crashing expo-go HOT 2
- androidNavigationBar not working after create build APK HOT 2
- Error while building the app ':expo-structured-header' HOT 1
- Error encountered while fetching Expo token: TypeError: Cannot read property 'prototype' of undefined. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expo.