Giter Club home page Giter Club logo

Comments (14)

sonaye avatar sonaye commented on April 28, 2024 4

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.

xcarpentier avatar xcarpentier commented on April 28, 2024 3

+1 react-native-i18n 😊

from expo.

brentvatne avatar brentvatne commented on April 28, 2024 3

done! https://docs.getexponent.com/versions/v11.0.0/sdk/util.html#Exponent.Util.getCurrentLocaleAsync

from expo.

jamuhl avatar jamuhl commented on April 28, 2024 3

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.

lucfranken avatar lucfranken commented on April 28, 2024 2

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.

sonaye avatar sonaye commented on April 28, 2024 2

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.

jesseruder avatar jesseruder commented on April 28, 2024 2

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.

jamuhl avatar jamuhl commented on April 28, 2024 1

@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.

brentvatne avatar brentvatne commented on April 28, 2024

Coming in sdk11!

from expo.

xcarpentier avatar xcarpentier commented on April 28, 2024

Another solution => https://github.com/xcarpentier/ex-react-native-i18n

from expo.

eldadcaspi avatar eldadcaspi commented on April 28, 2024

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.

eldadcaspi avatar eldadcaspi commented on April 28, 2024

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.

sonaye avatar sonaye commented on April 28, 2024

@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.

jesseruder avatar jesseruder commented on April 28, 2024

Ok that sounds like a separate issue. Feel free to create a new issue about that.

from expo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.