Utilisation des json de messages pour les boutons de langue

This commit is contained in:
Anthony Dumas 2022-06-15 00:44:44 +02:00
parent accaf328c2
commit 115b432771
2 changed files with 58 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,11 @@
import React, {Component} from '../../../node_modules/react'; import './MenuComponent.scss';
import {FormattedMessage} from 'react-intl';
import './MenuComponent.scss'
const URL_add_parameter = function(url, param, value){ import { FormattedMessage, injectIntl } from 'react-intl';
import React, { Component } from '../../../node_modules/react';
const URL_add_parameter = function (url, param, value) {
var hash = {}; var hash = {};
var parser = document.createElement('a'); var parser = document.createElement('a');
@ -10,8 +13,8 @@ const URL_add_parameter = function(url, param, value){
var parameters = parser.search.split(/\?|&/); var parameters = parser.search.split(/\?|&/);
for(var i=0; i < parameters.length; i++) { for (var i = 0; i < parameters.length; i++) {
if(!parameters[i]) if (!parameters[i])
continue; continue;
var ary = parameters[i].split('='); var ary = parameters[i].split('=');
@ -28,41 +31,42 @@ const URL_add_parameter = function(url, param, value){
parser.search = '?' + list.join('&'); parser.search = '?' + list.join('&');
return parser.href; return parser.href;
} }
export default class MenuComponent extends Component { class MenuComponent extends Component {
// constructor(props) { // constructor(props) {
// super(props); // super(props);
// this.state = {}; // this.state = {};
// } // }
honhonhon() { honhonhon() {
window.location.href=URL_add_parameter(window.location.href, "lang", "fr"); window.location.href = URL_add_parameter(window.location.href, "lang", "fr");
} }
heygovna() { heygovna() {
window.location.href=URL_add_parameter(window.location.href, "lang", "en"); window.location.href = URL_add_parameter(window.location.href, "lang", "en");
} }
render() { render() {
const buttonsLanguagesMessage = this.props.intl.messages.global.buttons.languages;
return <section id="menu" class="hero is-primary dontPrint is-bold"> return <section id="menu" class="hero is-primary dontPrint is-bold">
<div class="hero-body"> <div class="hero-body">
<div class="container"> <div class="container">
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<h1 class="title"> <h1 class="title">
<FormattedMessage id="title"/> <FormattedMessage id="title" />
</h1> </h1>
<h2 class="subtitle"> <h2 class="subtitle">
<FormattedMessage id="subtitle"/> <FormattedMessage id="subtitle" />
</h2> </h2>
</div> </div>
<div class="column is-hidden-touch"> <div class="column is-hidden-touch">
<div id="langButtons"> <div id="langButtons">
<div class="buttons"> <div class="buttons">
<span class="button is-light" onClick={this.honhonhon}> <span class="button is-light" onClick={this.honhonhon}>
En Français 🇫🇷 {buttonsLanguagesMessage.fr}
</span> </span>
<span class="button is-light" onClick={this.heygovna}> <span class="button is-light" onClick={this.heygovna}>
In English 🇮🇪 {buttonsLanguagesMessage.en}
</span> </span>
</div> </div>
</div> </div>
@ -73,8 +77,10 @@ export default class MenuComponent extends Component {
</div> </div>
</section>; </section>;
} }
} }
// export default connect( // export default connect(
// ({ MenuComponent }) => ({ ...MenuComponent }), // ({ MenuComponent }) => ({ ...MenuComponent }),
// dispatch => bindActionCreators({ ...MenuComponentActions }, dispatch) // dispatch => bindActionCreators({ ...MenuComponentActions }, dispatch)
// )( MenuComponent ); // )( MenuComponent );
export default injectIntl(MenuComponent)