Skip to content

Instantly share code, notes, and snippets.

@danialkalbasi
Last active October 27, 2020 07:01
Show Gist options
  • Save danialkalbasi/350d960a6d28016a3331f6a9c7baefa4 to your computer and use it in GitHub Desktop.
Save danialkalbasi/350d960a6d28016a3331f6a9c7baefa4 to your computer and use it in GitHub Desktop.
Power Translator Demo
import React, { Component } from 'react';
import { PowerTranslator, ProviderTypes, TranslatorConfiguration } from 'react-native-power-translator';
import { View, ScrollView, TouchableOpacity, Text } from 'react-native';
export default class PowerTranslatorDemo extends Component {
constructor() {
super();
this.state = { languageCode: 'fr' };
}
render() {
const styles = this.getStyles();
TranslatorConfiguration.setConfig(ProviderTypes.Google, 'AIzaSyB5ip6KC-9KCIjO9Q7Rm47dYJDmOdjLgM0', this.state.languageCode);
return (
<ScrollView style={styles.container}>
<View style={styles.languageBar}>
<TouchableOpacity onPress={() => { this.changeLanguage('en') }}><Text style={styles.p}>English</Text></TouchableOpacity>
<TouchableOpacity onPress={() => { this.changeLanguage('fr') }}><Text style={styles.p}>French</Text></TouchableOpacity>
<TouchableOpacity onPress={() => { this.changeLanguage('ru') }}><Text style={styles.p}>Russian</Text></TouchableOpacity>
<TouchableOpacity onPress={() => { this.changeLanguage('de') }}><Text style={styles.p}>German</Text></TouchableOpacity>
</View>
<View>
<PowerTranslator style={styles.title} text={'A Confucian Revival Began'} />
<PowerTranslator style={styles.subtitle} text={'Author: Confucianism'} />
</View>
<View style={styles.section}>
<PowerTranslator style={styles.p} text={'Confucianism was particularly strong during the Han Dynasty, whose greatest thinker was Dong Zhongshu, who integrated Confucianism with the thoughts of the Zhongshu School and the theory of the Five Elements. He also was a promoter of the New Text school, which considered Confucius as a divine figure and a spiritual ruler of China, who foresaw and started the evolution of the world towards the Universal Peace.'} />
</View>
<View style={styles.section}>
<PowerTranslator style={styles.p} text={'Confucianism was particularly strong during the Han Dynasty, whose greatest thinker was Dong Zhongshu, who integrated Confucianism with the thoughts of the Zhongshu School and the theory of the Five Elements. He also was a promoter of the New Text school, which considered Confucius as a divine figure and a spiritual ruler of China, who foresaw and started the evolution of the world towards the Universal Peace.'} />
</View>
<View style={styles.section}>
<PowerTranslator style={styles.p} text={'Engineering physics or engineering science refers to the study of the combined disciplines of physics'} />
</View>
</ScrollView>
);
}
getStyles() {
return {
container: {
padding: 40,
backgroundColor: '#FAFAFA',
},
section: {
marginTop: 15,
marginBottom: 15,
},
title: {
marginTop: 80,
marginBottom: 5,
fontWeight: 'bold',
fontSize: 38,
lineHeight: 38
},
subtitle: {
color: '#B3B3B3',
},
p: {
color: '#828280',
lineHeight: 24
},
languageBar: {
flexDirection: 'row',
justifyContent: 'space-between'
},
languageBarItem: {
color: '#828280',
}
}
}
changeLanguage(languageCode) {
this.setState({ languageCode: languageCode });
}
}
@harsha-kotapati
Copy link

for me am getting unable TypeError: undefined is not an object (evaluating 'translator.translate') any answers plz

@Arslan24
Copy link

@harsha-kotapati This power translator didnt work for me. so check the above link for a solution
danialkalbasi/react-native-power-translator#18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment