Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import axios from 'axios';
  3. import TranslateForm from './TranslateForm';
  4. import TranslateOutput from './TranslateOutput';
  5. import {Container} from "react-bootstrap";
  6. import ContextMenu from "./contextmenu";
  7.  
  8. const key = "trnsl.1.1.20200108T112402Z.673445eef91fd0a3.1291a50e00d5c50e78cbf0ce86d6af81cd6cd831";
  9.  
  10.  
  11. class YandexTranslation extends Component {
  12. state = {
  13. output: '',
  14. yandexFormVisible: false
  15. };
  16.  
  17. translate = (textToTranslate, language) => {
  18. axios.get('https://translate.yandex.net/api/v1.5/tr.json/translate?key=' + key + '&lang=' + language + '&text=' + textToTranslate)
  19. .then((response) => {
  20. var output = response.data.text[0];
  21. this.setState({
  22. ...this.state,
  23. output: output
  24. });
  25. })
  26. .catch((error) =>
  27. console.log(error)
  28. );
  29. }
  30.  
  31. showYandexForm = () => {
  32. this.setState({
  33. ...this.state,
  34. yandexFormVisible: true
  35. });
  36. }
  37. render() {
  38. return (
  39. <Container>
  40. <div id="that"><ContextMenu showYandexForm={this.showYandexForm}/></div>
  41. {this.state.yandexFormVisible ? <TranslateForm translate={this.translate}/> : <div></div>}
  42. {this.state.yandexFormVisible ? <TranslateOutput output={this.state.output}/> : <div></div>}
  43. </Container>
  44. );
  45. }
  46. }
  47.  
  48. export default YandexTranslation;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement