Comments (3)
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.
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.
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)
- Support for getting the currency symbol directly. HOT 6
- Is there a way this library can detect the locale automatically? HOT 2
- Undefinided is not an object <FormattedCurrency> HOT 1
- gulp cldr error HOT 1
- pt-BR is missing HOT 1
- Typescript support HOT 4
- postinstall step failing on CircleCI HOT 2
- typing of `useGlobalize().formatMessage` HOT 1
- [Proposal] useGlobalize generic type HOT 7
- getCurrencySymbol() with GlobalizeProvider throwing TypeError HOT 4
- How to use useGlobalize with class component HOT 4
- formatCurrency always return Error value must be anumber HOT 5
- Fallback locale in case formatMessage failure HOT 3
- Fallback locale does not fork HOT 4
- Customizing Formatted Currency Component HOT 4
- [RNGlobalize] Error processing message welcome HOT 1
- Translate functions strings HOT 1
- Access functions outside components HOT 2
- On demand loading of locales in a web app HOT 2
- Unable to resolve "../../../../../globalize" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.