Can I use flat json keys in i18n-js react native

897 Views Asked by At

I have a flat json as follows

'action.skip': 'Skip this for now', 'action.start': 'Start'

I want to call it as

{I18n.t('action.start')}

currently it is not working because i18n trying to find "action" key and its child "start" instead of "action.start". I couldn't find any option to change the key separator. please help

1

There are 1 best solutions below

8
On

We can change the key seperator by adding following codes.

import I18n from 'i18n-js';

import { de, en } from '../locales';

I18n.defaultLocale = 'en';
I18n.defaultSeparator = '_';

i18n-js now only split the string with "_", so if add "abc.xyz" it will treat as a single key.