localization, trigger changing language

Question related to localization
SDK Version 38.0.2

I initialised i18n like this in separate file.

import * as Localization from 'expo-localization';
import i18n from 'i18n-js';
import en from "./locales/en";
import nl from "./locales/nl";

i18n.translations = {
  en: en,
  nl: nl,
};
i18n.locale = Localization.locale;


export default i18n

I have some content in my app which is in different file, from this file I export my data and map it (usual react)

{menuItemsData.map(({ menuItem }) => (
        <View>
          <Text>{menuItem}</Text>
        </View>
      ))}

data file is like

export const menuItemsData = [
  {
    id: 1,
    menuItem: 'Home,
  },
  {
    id: 2,
    menuItem: 'Privacy,
  }
]

How to change language with “onPress” inside of this menuItemsData array ?
Yes I can do something like this inside of array

menuItem: i18n.t('greetings'),

But if I’ll change language inside of app, language will be the same.

But in general, how to trigger changing language ? Is it possible to make with hooks idk or something like this ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.