how to switch between English & Tamil language using unicode in react native locale?

Viewed 270

I'm Using tn.js for storing unicode for the tamil language but when i'm run the application , it displays only the unicode character not the tamil letter, so can anyone help me?

import i18n from 'i18n-js';
import locales from './locale';

let locale = 'ta';

const setLocale = (l) => {
  locale = l;
};

const t = (scope, options) => {
  return i18n.t(scope, { locale, ...options });
};

i18n.fallbacks = true;
i18n.translations = locales;

export default {
  locale,
  setLocale,
  t,
};

This is my index.js in Locale

import en from './en';
import fr from './fr';
import ta from './Tn';

export default {
  en,
  fr,
  ta,
};

This my Tn.js ( unicode for tamil) can anbody help.

export default {
  POINTS: '%u0BAA%u0BC1%u0BB3%u0BCD%u0BB3%u0BBF%u0B95%u0BB3%u0BCD',
  COST: '%u0B9A%u0BC6%u0BB2%u0BB5%u0BC1',
  SEND: 'அனுப்புக',
};

Here i'm implementing the translation in linear button

import { View } from 'react-native';
import React from 'react';
import translation from '../../../Util/Translation';
import LinearButton from '../../Common/Button';
const { t } = translation;
const MobileNumberComponent = React.forwardRef((props, ref) => 

  return (
           <View style={{flex:1, alignItems:'center'}}>
            <LinearButton
              title={t('SEND')}
            />
            </View>
)
1 Answers

Use unescape to decode the unicode for every languge

import i18n from 'i18n-js';
import locales from './locale';

let locale = 'en';

const unescaped = (value) => unescape(value);
const setLocale = (l) => {
  locale = l;
};

const t = (scope, options) => {
  return unescaped(i18n.t(scope, { locale, ...options }));
};

i18n.fallbacks = true;
i18n.translations = locales;

export default {
  locale,
  setLocale,
  t,
};
Related