More i18n work

This commit is contained in:
vjrj 2017-11-29 10:50:28 +01:00
parent fffeb2a17a
commit e9029cd8b9
13 changed files with 49 additions and 28 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ settings-demo.json
settings-staging.json settings-staging.json
settings-production.json settings-production.json
settings-development.json settings-development.json
imports/ui/stylesheets/.sass-cache/

View file

@ -2,6 +2,9 @@ import i18n from 'i18next';
import backend from 'i18next-xhr-backend'; import backend from 'i18next-xhr-backend';
import LngDetector from 'i18next-browser-languagedetector'; import LngDetector from 'i18next-browser-languagedetector';
import Cache from 'i18next-localstorage-cache'; import Cache from 'i18next-localstorage-cache';
import { T9n } from 'meteor-accounts-t9n';
import en from 'meteor-accounts-t9n/build/en';
import es from 'meteor-accounts-t9n/build/es';
// Adapted from: https://github.com/appigram/ryfma-boilerplate/blob/44c1eabfb9928b5623afab36a23997969e5beb02/imports/startup/client/i18n.js // Adapted from: https://github.com/appigram/ryfma-boilerplate/blob/44c1eabfb9928b5623afab36a23997969e5beb02/imports/startup/client/i18n.js
@ -41,6 +44,8 @@ var backOpts = {
jsonIndent: 2 jsonIndent: 2
}; };
T9N_LANGUAGES='es,en';
i18n.use(backend) i18n.use(backend)
.use(LngDetector) .use(LngDetector)
.use(Cache) .use(Cache)
@ -79,8 +84,11 @@ i18n.use(backend)
} }
}, function(err, t) { }, function(err, t) {
// initialized and ready to // initialized and ready to
// console.log(t('AppName'));
document.title = t("AppName"); document.title = t("AppName");
// https://github.com/softwarerero/meteor-accounts-t9n
console.log("Language: " + i18n.language);
T9n.setLanguage(i18n.language);
console.log(T9n.get('error.accounts.User not found'));
}); });
export default i18n; export default i18n;

View file

@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
import { Bert } from 'meteor/themeteorchef:bert'; import { Bert } from 'meteor/themeteorchef:bert';
import Icon from '../Icon/Icon'; import Icon from '../Icon/Icon';
import { translate, Trans } from 'react-i18next'; import { translate, Trans } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
import './OAuthLoginButton.scss'; import './OAuthLoginButton.scss';
@ -49,7 +50,8 @@ const OAuthLoginButton = ({ service, callback }) => (
OAuthLoginButton.defaultProps = { OAuthLoginButton.defaultProps = {
callback: (error) => { callback: (error) => {
if (error) Bert.alert(error.message, 'danger'); if (error) Bert.alert(T9n.get(`error.accounts.${error.message}`), 'danger');
// Bert.alert(error.message, 'danger');
}, },
}; };

View file

@ -2,11 +2,12 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Grid, Alert, Button } from 'react-bootstrap'; import { Grid, Alert, Button } from 'react-bootstrap';
import { t, Trans, translate, Interpolate } from 'react-i18next'; import { t, Trans, translate, Interpolate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
const handleResendVerificationEmail = (emailAddress, t) => { const handleResendVerificationEmail = (emailAddress, t) => {
Meteor.call('users.sendVerificationEmail', (error) => { Meteor.call('users.sendVerificationEmail', (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Bert.alert(t("checkVerificationEmail", {email: emailAddress}), 'success'); Bert.alert(t("checkVerificationEmail", {email: emailAddress}), 'success');
} }

View file

@ -9,6 +9,7 @@ import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButt
import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter'; import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter';
import validate from '../../../modules/validate'; import validate from '../../../modules/validate';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
class Login extends React.Component { class Login extends React.Component {
constructor(props) { constructor(props) {
@ -48,7 +49,7 @@ class Login extends React.Component {
Meteor.loginWithPassword(this.emailAddress.value, this.password.value, (error) => { Meteor.loginWithPassword(this.emailAddress.value, this.password.value, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Bert.alert(this.t('Bienvenid@ de nuevo'), 'success'); Bert.alert(this.t('Bienvenid@ de nuevo'), 'success');
} }

View file

@ -12,6 +12,7 @@ import { createContainer } from 'meteor/react-meteor-data';
import InputHint from '../../components/InputHint/InputHint'; import InputHint from '../../components/InputHint/InputHint';
import validate from '../../../modules/validate'; import validate from '../../../modules/validate';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
import './Profile.scss'; import './Profile.scss';
@ -97,7 +98,7 @@ class Profile extends React.Component {
Meteor.call('users.editProfile', profile, (error) => { Meteor.call('users.editProfile', profile, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Bert.alert(this.t("¡Perfíl actualizado!"), 'success'); Bert.alert(this.t("¡Perfíl actualizado!"), 'success');
} }
@ -106,7 +107,7 @@ class Profile extends React.Component {
if (this.newPassword.value) { if (this.newPassword.value) {
Accounts.changePassword(this.currentPassword.value, this.newPassword.value, (error) => { Accounts.changePassword(this.currentPassword.value, this.newPassword.value, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
this.currentPassword.value = ''; this.currentPassword.value = '';
this.newPassword.value = ''; this.newPassword.value = '';

View file

@ -8,6 +8,7 @@ import { Bert } from 'meteor/themeteorchef:bert';
import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter'; import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter';
import validate from '../../../modules/validate'; import validate from '../../../modules/validate';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
class RecoverPassword extends React.Component { class RecoverPassword extends React.Component {
constructor(props) { constructor(props) {
@ -28,8 +29,8 @@ class RecoverPassword extends React.Component {
}, },
messages: { messages: {
emailAddress: { emailAddress: {
required: 'Need an email address here.', required: this.t("Necesitamos un correo aquí."),
email: 'Is this email address correct?', email: this.t("¿Es este correo correcto?"),
}, },
}, },
submitHandler() { component.handleSubmit(); }, submitHandler() { component.handleSubmit(); },
@ -43,7 +44,7 @@ class RecoverPassword extends React.Component {
Accounts.forgotPassword({ email, t }, (error) => { Accounts.forgotPassword({ email, t }, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Bert.alert(t("checkResetEmail", {email: email}), 'success'); Bert.alert(t("checkResetEmail", {email: email}), 'success');
history.push('/login'); history.push('/login');

View file

@ -6,6 +6,7 @@ import { Accounts } from 'meteor/accounts-base';
import { Bert } from 'meteor/themeteorchef:bert'; import { Bert } from 'meteor/themeteorchef:bert';
import validate from '../../../modules/validate'; import validate from '../../../modules/validate';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
class ResetPassword extends React.Component { class ResetPassword extends React.Component {
constructor(props) { constructor(props) {
@ -50,7 +51,7 @@ class ResetPassword extends React.Component {
Accounts.resetPassword(token, this.newPassword.value, (error) => { Accounts.resetPassword(token, this.newPassword.value, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
history.push('/documents'); history.push('/documents');
} }

View file

@ -13,6 +13,7 @@ import validate from '../../../modules/validate';
import Icon from '../../components/Icon/Icon'; import Icon from '../../components/Icon/Icon';
import './Signup.scss'; import './Signup.scss';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
class Signup extends React.Component { class Signup extends React.Component {
constructor(props) { constructor(props) {
@ -43,18 +44,18 @@ class Signup extends React.Component {
}, },
messages: { messages: {
firstName: { firstName: {
required: 'What\'s your first name?', required: this.t("¿Cuál es tu nombre?"),
}, },
lastName: { lastName: {
required: 'What\'s your last name?', required: this.t("¿Cuál es tu apellido?"),
}, },
emailAddress: { emailAddress: {
required: 'Need an email address here.', required: this.t("Necesitamos una contraseña aquí."),
email: 'Is this email address correct?', email: this.t("¿Es correcto este correo?"),
}, },
password: { password: {
required: 'Need a password here.', required: this.t("Necesitamos una contraseña aquí."),
minlength: 'Please use at least six characters.', minlength: this.t("Usa al menos seis caracteres."),
}, },
}, },
submitHandler() { component.handleSubmit(); }, submitHandler() { component.handleSubmit(); },
@ -75,7 +76,7 @@ class Signup extends React.Component {
}, },
}, (error) => { }, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Meteor.call('users.sendVerificationEmail'); Meteor.call('users.sendVerificationEmail');
Bert.alert('Welcome!', 'success'); Bert.alert('Welcome!', 'success');
@ -90,13 +91,13 @@ class Signup extends React.Component {
<Col xs={12} sm={6} md={5} lg={4}> <Col xs={12} sm={6} md={5} lg={4}>
<h4 className="page-header">{this.t("Registrarse")}</h4> <h4 className="page-header">{this.t("Registrarse")}</h4>
<Row> <Row>
<Col xs={12}> {/* <Col xs={12}>
<button <button
className={`btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram`} className={`btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram`}
type="button" onClick={() => handleLogin(service, callback)}> type="button" onClick={() => handleLogin(service, callback)}>
<span><Icon icon="telegram" /> Usa nuestro bot de Telegram</span> <span><Icon icon="telegram" /> Usa nuestro bot de Telegram</span>
</button> </button>
</Col> </Col> */}
<Col xs={12}> <Col xs={12}>
<OAuthLoginButtons <OAuthLoginButtons
services={['telegram', 'google']} services={['telegram', 'google']}

View file

@ -5,6 +5,7 @@ import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base'; import { Accounts } from 'meteor/accounts-base';
import { Bert } from 'meteor/themeteorchef:bert'; import { Bert } from 'meteor/themeteorchef:bert';
import { translate } from 'react-i18next'; import { translate } from 'react-i18next';
import { T9n } from 'meteor-accounts-t9n';
class VerifyEmail extends React.Component { class VerifyEmail extends React.Component {
constructor(props) { constructor(props) {
@ -17,7 +18,7 @@ class VerifyEmail extends React.Component {
const { match, history } = this.props; const { match, history } = this.props;
Accounts.verifyEmail(match.params.token, (error) => { Accounts.verifyEmail(match.params.token, (error) => {
if (error) { if (error) {
Bert.alert(error.reason, 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
this.setState({ error: error.reason + ". " + this.t("Por favor, inténtalo otra vez.")}); this.setState({ error: error.reason + ". " + this.t("Por favor, inténtalo otra vez.")});
// this.setState({ error: `${error.reason}. Please try again.` }); // this.setState({ error: `${error.reason}. Please try again.` });
} else { } else {

View file

@ -24,6 +24,7 @@
"jquery-validation": "^1.17.0", "jquery-validation": "^1.17.0",
"juice": "^4.1.1", "juice": "^4.1.1",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"meteor-accounts-t9n": "^2.0.3",
"meteor-node-stubs": "^0.2.11", "meteor-node-stubs": "^0.2.11",
"moment": "^2.19.2", "moment": "^2.19.2",
"popper.js": "^1.12.7", "popper.js": "^1.12.7",

View file

@ -12,6 +12,7 @@
"Licencia": "License", "Licencia": "License",
"Cerrar sesión": "Logout", "Cerrar sesión": "Logout",
"Registrarse": "Sign Up", "Registrarse": "Sign Up",
"Regístrate": "Sign Up",
"Iniciar sesión": "Login", "Iniciar sesión": "Login",
"o regístrate con un correo": "or Sign Up with an Email Address", "o regístrate con un correo": "or Sign Up with an Email Address",
"o inicia sesión con un correo": "o inicia sesión con un correo":
@ -30,7 +31,7 @@
"Use at least six characters.", "Use at least six characters.",
"Iniciar sesión con Google": "Iniciar sesión con Google":
"Log In with Google", "Log In with Google",
"¿Olvidaste tu contraseña": "¿Olvidaste tu contraseña?":
"Forgot password?", "Forgot password?",
"¿No tienes una cuenta?": "¿No tienes una cuenta?":
"Don't have an account?", "Don't have an account?",

View file

@ -12,6 +12,7 @@
"Licencia": "Licencia", "Licencia": "Licencia",
"Cerrar sesión": "Cerrar sesión", "Cerrar sesión": "Cerrar sesión",
"Registrarse": "Registrarse", "Registrarse": "Registrarse",
"Regístrate": "Regístrate",
"Iniciar sesión": "Iniciar sesión", "Iniciar sesión": "Iniciar sesión",
"o regístrate con un correo": "o regístrate con un correo":
"o regístrate con un correo", "o regístrate con un correo",
@ -31,8 +32,8 @@
"Usa al menos seis caracteres.", "Usa al menos seis caracteres.",
"Iniciar sesión con Google": "Iniciar sesión con Google":
"Iniciar sesión con Google", "Iniciar sesión con Google",
"¿Olvidaste tu contraseña": "¿Olvidaste tu contraseña?":
"¿Olvidaste tu contraseña", "¿Olvidaste tu contraseña?",
"¿No tienes una cuenta?": "¿No tienes una cuenta?":
"¿No tienes una cuenta?", "¿No tienes una cuenta?",
"Introduce tu correo abajo para recibir un enlace para resetear tu contraseña.": "Introduce tu correo abajo para recibir un enlace para resetear tu contraseña.":