ReactNativeLocalization
ReactNativeLocalization copied to clipboard
Allow objects as well as strings so I can use bold text
I would like to add the ability to add bold text to my localizations. This would only require 1 line of code to change.
In LocalizedStrings.js change line 77 to be:
if (!(typeof strings[key] == "string" || typeof strings[key] == "object")) {
For my localization file I use:
import React, { Component } from 'react';
import { Text } from 'react-native';
const B = (props) => <Text style={{fontWeight: 'bold'}}>{props.children}</Text>
// Locale strings
const FR = {
text1: 'some text',
text2: <Text>some <B>bold</B> text</Text>,
text3: 'some more text'
};
The problem is that only strings are supported, if we add object support this works great.
That check is useful when keys are nested and there are missing keys in another language...
const FR = {
mainScreen:{
text1: 'some text',
},
text2: <Text>some <B>bold</B> text</Text>,
text3: 'some more text'
};
Have you check if this would still work?
Yes this still works.
@BlueBeetle13 Check out my PR which I have submitted. I think It should work for your use case https://github.com/stefalda/react-localization/pull/35
@henrikra How did you solve an issue with running React Native on Android? I'm getting [object Object]
.
Problem is this line
const isReactComponent = value => typeof value.$$typeof === 'symbol';
If you replace it with
const isReactComponent = value => React.isValidElement(value);
then it works.
I haven't run this on React Native. I think on RN you should use this since it is meant for it https://github.com/react-community/react-native-languages