Giter Club home page Giter Club logo

Comments (3)

joshswan avatar joshswan commented on August 24, 2024

You have to use objects throughout the message JSON structure and make sure the path you're providing via the array is valid.

en = {
    scenes: {
        faq: {
            title: 'Frequently Asked Questions',
            sections: {
                general: {
                    title: 'GENERAL',
                },
                advanced: {
                    title: 'ADVANCED',
                },
            },
        },
    },
};

<FormattedMessage message={['scenes', 'faq', 'sections', 'general', 'title']} />
// GENERAL
<FormattedMessage message={['scenes', 'faq', 'sections', 'advanced', 'title']} />
// ADVANCED
<FormattedMessage message={['scenes', 'faq', 'title']} />
// Frequently Asked Questions

// You can also use a dynamic value if you want to use a loop
const sections = ['general', 'advanced'];

sections.forEach((section) => (
    <FormattedMessage message={['scenes', 'faq', 'sections', section, 'title']} />
));
/>

from react-native-globalize.

ostrichegret avatar ostrichegret commented on August 24, 2024

Thank you very much for the help @joshswan

I hope this will support array in the future, some react components use array instead of object,
( I use the Accordion component in https://github.com/oblador/react-native-collapsible )

from react-native-globalize.

joshswan avatar joshswan commented on August 24, 2024

Your language data does not need to be an array in order to use a component like that. In fact it's better if it's not so that the language data can be updated and reordered without affecting your app.

Here's an example of how to use the two libraries. Notice that there is no need for the language data to be an array:

// Section identifiers
const sections = ['general', 'advanced'];

// Get localized section titles using react-native-globalize and the section identifiers
const sectionTitles = sections.map(section => (
  this.context.globalize.getMessageFormatter(['scenes', 'faq', 'sections', section, 'title'])
));

// Use the sectionTitles array in your Accordion component
<Accordion 
  sections={sectionTitles}
  renderHeader={this._renderHeader}
  renderContent={this._renderContent}
/>

from react-native-globalize.

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.