React-native-i18n: Missing Translation error

Created on 9 May 2017  路  3Comments  路  Source: AlexanderZaytsev/react-native-i18n

I have the following code:

import I18n from 'react-native-i18n'

class Demo extends React.Component {
  render () {
    return (
      <Text>{I18n.t('DASHBOARD.AVAILABLE_BALANCE')}</Text>
 // I get the following error here: [missing "en.AVAILABLE_BALANCE" translation]
    )
  }
}

I18n.translations = {
  'en': {
    'DASHBOARD.AVAILABLE_BALANCE': Hi!'
  }
}

Any solution?

Most helpful comment

Hi there,

it doesn't seem like a repository issue so you should open this in stack overflow instead :)

Now, if you plan to use just 'en' and without the country part (i.e. en_GB) you need to enable fallbacks as per the README file.
Lastly your I18n.translations object can be written in a better way and you are also missing a quote in word 'Hi!'.

You code can be modified to this:

```
I18n.fallbacks = true;

I18n.translations = {
'en': {
'DASHBOARD': {
'AVAILABLE_BALANCE': 'Hi!'
}
}
};

All 3 comments

Hi there,

it doesn't seem like a repository issue so you should open this in stack overflow instead :)

Now, if you plan to use just 'en' and without the country part (i.e. en_GB) you need to enable fallbacks as per the README file.
Lastly your I18n.translations object can be written in a better way and you are also missing a quote in word 'Hi!'.

You code can be modified to this:

```
I18n.fallbacks = true;

I18n.translations = {
'en': {
'DASHBOARD': {
'AVAILABLE_BALANCE': 'Hi!'
}
}
};

Hi I have a Missing Translation error i call the translation like this
const dayHeadings = [ 'days.sun', 'days.mon', 'days.tue', 'days.wed', 'days.thu', 'days.fri', 'days.sat', ].map(day => i18n.t(day));
and my translation is like this:
"days": { "sun": "Sun", "mon": "Mon", "tue": "Tue", "wed": "Wed", "thu": "Thur", "fri": "Fri", "sat": "Sat" }

What happens is that it says that the translation is missing but if I have the hot reload active and I save a random page the translation works
This is on the first try: as you can see the translation is there.
screen shot 2017-05-17 at 5 44 36 pm
And here is when it hot reload
screen shot 2017-05-17 at 5 48 00 pm

im using :
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-i18n": "^1.0.0",

EDIT: My bad it sees it works on class component it gave this error on a stateless component

@AhsanAk @jaycee425 This is only because your are using dots in the translations keys.
You can change it with I18n.defaultSeparator = '/' or the string of your choice.

If you don't want to change it, you can use, like @marudy said:

I18n.translations = {
  'en': {
    'DASHBOARD': {
      'AVAILABLE_BALANCE': 'Hi!'
    }
  }
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiangjiatao picture jiangjiatao  路  4Comments

tigranbalayan picture tigranbalayan  路  5Comments

sibelius picture sibelius  路  4Comments

hannta picture hannta  路  5Comments

mphasize picture mphasize  路  7Comments