ReactNativeLocalization icon indicating copy to clipboard operation
ReactNativeLocalization copied to clipboard

Allow objects as well as strings so I can use bold text

Open BlueBeetle13 opened this issue 7 years ago • 5 comments

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.

BlueBeetle13 avatar Apr 07 '17 21:04 BlueBeetle13

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?

stefalda avatar Apr 08 '17 18:04 stefalda

Yes this still works.

BlueBeetle13 avatar Apr 10 '17 14:04 BlueBeetle13

@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 avatar Jul 11 '17 20:07 henrikra

@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.

milansusnjar avatar Oct 10 '18 20:10 milansusnjar

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

henrikra avatar Oct 11 '18 04:10 henrikra