website/versioned_docs/version-0.83/i18nmanager.md
The I18nManager module provides utilities for managing Right-to-Left (RTL) layout support for languages like Arabic, Hebrew, and others. It provides methods to control RTL behavior and check the current layout direction.
If you absolutely position elements to align with other flexbox elements, they may not align in RTL languages. Using isRTL can be used to adjust alignment or animations.
import React from 'react';
import {I18nManager, Text, View} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
// Change to `true` to see the effect in a non-RTL language
const isRTL = I18nManager.isRTL;
return (
<SafeAreaProvider>
<SafeAreaView>
<View
style={{
position: 'absolute',
left: isRTL ? undefined : 0,
right: isRTL ? 0 : undefined,
}}>
{isRTL ? <Text>Back ></Text> : <Text>< Back</Text>}
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};
export default App;
import React, {useState} from 'react';
import {Alert, I18nManager, StyleSheet, Switch, Text, View} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
const [rtl, setRTL] = useState(I18nManager.isRTL);
return (
<SafeAreaProvider>
<SafeAreaView>
<View style={styles.container}>
<View style={styles.forceRtl}>
<Text>Force RTL in Development:</Text>
<Switch
value={rtl}
onValueChange={value => {
setRTL(value);
I18nManager.forceRTL(value);
Alert.alert(
'Reload this page',
'Please reload this page to change the UI direction! ' +
'All examples in this app will be affected. ' +
'Check them out to see what they look like in RTL layout.',
);
}}
/>
</View>
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};
const styles = StyleSheet.create({
container: {
padding: 20,
},
forceRtl: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
});
export default App;
isRTLstatic isRTL: boolean;
A boolean value indicating whether the app is currently in RTL layout mode.
The value of isRTL is determined by the following logic:
forceRTL is true, isRTL returns trueallowRTL is false, isRTL returns falseisRTL will be true given the following:
knownRegions = (...))AndroidManifest.xml defines android:supportsRTL="true" on the <application> elementdoLeftAndRightSwapInRTLstatic doLeftAndRightSwapInRTL: boolean;
A boolean value indicating whether left and right style properties should be automatically swapped when in RTL mode. When enabled, left becomes right and right becomes left in RTL layouts.
allowRTL()static allowRTL: (allowRTL: boolean) => void;
Enables or disables RTL layout support for the application.
Parameters:
allowRTL (boolean): Whether to allow RTL layoutImportant Notes:
forceRTL()static forceRTL: (forced: boolean) => void;
Forces the app to use RTL layout regardless of the device language settings. This is primarily useful for testing RTL layouts during development.
Avoid forcing RTL in production apps as it requires a full app restart to take effect, which makes for a poor user-experience.
Parameters:
forced (boolean): Whether to force RTL layoutImportant Notes:
isRTL)swapLeftAndRightInRTL()static swapLeftAndRightInRTL: (swapLeftAndRight: boolean) => void;
Swap left and right style properties in RTL mode. When enabled, left becomes right and right becomes left in RTL layouts. Does not affect the value of isRTL.