Coder Social home page Coder Social logo

Comments (8)

kanzitelli avatar kanzitelli commented on May 19, 2024 2

Hey @Yasir5247! I have added an example of nav&tab bars title translations. Basically, if you change a language in the Settings screen, the app will reload itself and all new translations will be applied.

from rnn-starter.

kanzitelli avatar kanzitelli commented on May 19, 2024 1

@Yasir5247 you are welcome! I have added a working (production-ready) example in #52 for language switching. Now you can force to use a specific language as well as make it dependent on the system language. The same logic is applied to Appearance settings (light/dark mode).

from rnn-starter.

kanzitelli avatar kanzitelli commented on May 19, 2024 1

hey @Yasir5247! What I usually do is the following:

import {services} from '../services';
// ...
topBar: {
        ...withTitle(services.t.do('home.title')),
}

And as I see now, It will work only from the app launch, but if you want to toggle in-app language switch, then it's not gonna work, you will need to close the app and then open it again. This might be enough for some cases but I will think about the easiest way to achieve it with in-app switch.

from rnn-starter.

kanzitelli avatar kanzitelli commented on May 19, 2024

@Yasir5247 hey, could specify what you mean?
For more information, you could check the translation service under src/services/translate/index.ts and play around with it. Also, you can add other translations in translations.ts file.

from rnn-starter.

Yasir5247 avatar Yasir5247 commented on May 19, 2024

src/services/translate/translations.ts
I have two objects in the file. one is English and another one is some other language.
I'm trying to switch between languages from the UI. I was hoping if there was a demo to achieve this in this repo if possible.

from rnn-starter.

kanzitelli avatar kanzitelli commented on May 19, 2024

@Yasir5247
There is no demo in this repo at the moment, but it would be great to have it! I will work on it and release it in one of the next versions (after integrating RN 0.65 in #48, which is almost done).

If you'd like to achieve it now, I can give you some tips:

  1. Add change function to src/services/translate/index.ts
change = (l: 'en' | 'ru'): void => {
  i18n.locale = l;
};
  1. Add UI related code to src/screens/settings.tsx
export const Settings: NavigationFunctionComponent = observer(() => {
  const { t, nav } = useServices();

  // ...
 
  const changeLanguage = () => {
    t.change('ru'); // change to desired language
    nav.start('three_tabs'); // after changing language, we need to do setRoot() again
  };

  // ...
  
  return (
    // ...
      <Section bg title="General">
        <Action title="Toggle theme" info={ui.themeMode} onPress={ui.toggleThemeMode} />
        <Action title="Change language" icon="share-outline" onPress={changeLanguage} />
    // ...
  );
}

For the full correct implementation, the current language should be stored in the UI store, which I will do later.

from rnn-starter.

Yasir5247 avatar Yasir5247 commented on May 19, 2024

This is great. This repo saved my life. Good work and appreciate for the effort.

from rnn-starter.

Yasir5247 avatar Yasir5247 commented on May 19, 2024

Screenshot 2021-09-21 at 10 57 55

I wonder how would you go about translation for navigational components. any hint?

from rnn-starter.

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.