react-native - i18n React-Native 意外标记 ';'

标签 react-native

我在一个 IOS 项目中设置了 I18n,现在正在一个 Android 项目中工作。

我不断收到意想不到的标记 ';'错误。

当我注释掉字符串的导入语句和静态导航选项时,错误消失并且构建成功:

import React, { Component } from 'react';
import {
  View,
  Text,
  StyleSheet,
  ImageBackgroud,
  // TextInput
} from 'react-native';
// import {
//   Button
// } from 'react-native-elements';
// import {
//   Spinner
// } from '../components/common';

here --> //import { strings } from '../locales/i18n';

class SignUp extends Component {

  //static navigationOptions = {
 here -->// title: strings('SignUp.title')
  //}

  constructor(props) {
    super(props);
    this.state = {
      email: '',
      password: '',
      loading: false
    };
  }

  render() {
   return (
      <ImageBackgroud
        source={require('.././assets/swooshResize.jpg')}
        style={styles.backG}
      >
        <View>
          <Text>
           HELLO!
          </Text>
        </View>
      </ImageBackgroud>
    );
  }

}

const styles = StyleSheet.create({
  backG: {
     width: '100%',
     height: '100%'
  },
});

export default SignUp;

这是语言环境文件 i18n.js:

import I18n from 'react-native-i18n';
import en from './en.json';
import fr from './fr.json';
import es from './es.json';

I18n.fallbacks = true;

I18n.translations = {
  en, 
  fr,
  es
};

// RTL language support
// export const isRTL = currentLocale.indexOf('he') === 0 || 
currentLocale.indexOf('ar') === 0;

// Allow RTL alignment in RTL languages
// ReactNative.I18nManager.allowRTL(isRTL);

export function strings(name, params = {}) {
  return I18n.t(name, params);
}

export default I18n;

这是英语的 JSON:

{
  "SignUp": {
    "title": "Sign Up"
  }
}

完整错误信息:

意外的标记“;” ( http://10.0.2.2:8081/index.delta ? 平台=android&dev=true&minify=false:112892)

意外的标记“;” ( http://10.0.2.2:8081/index.delta ? 平台=android&dev=true&minify=false:112892)

我在 IOS 构建中运行它,然后注意到 react-native i18n 更新到 2.0.15,现在我得到了这个奇怪的错误。任何帮助将不胜感激,我也确实将其更改为文档规范,但它仍然有错误。运行中的 eslint。

也许一双全新的眼睛会有所帮助。

感谢您花时间看这篇文章

最佳答案

我遇到了同样的问题。不知道从哪里开始。事实证明,如果您的翻译文件之一只是空的(甚至不包含 {}),它就会抛出此错误。

通过为所有翻译文件提供内容来解决此问题,至少 {} 使其成为有效的 json 文件。

已打开 this ticket .

关于react-native - i18n React-Native 意外标记 ';',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52261224/

相关文章:

android - 样式在 React Native 中无法正常工作

android - 使用 react-native-push-notification 删除以前的通知

javascript - 如何在 react native map 中获得缩放级别

reactjs - 使用react-native-web实现组件

react-native - 有没有办法在 sails.io.js 中禁用 jsonp?

react-native - 如何修复 : A problem occurred configuring project

javascript - 如何使React Hot Loader适用于JSX?

android - React Native,TouchableOpacity 包装 float 按钮一无所获

react-native - 错误正则表达式无效 : Metro Bundler process exited with code 1

javascript - MobX:观察到的组件在可观察到的变化后不会重新呈现