Skip to content

Feat: Add Spanish translation #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module API. Options include:
container: '#some-query-selector'; // container to attach to
APIUrl: 'https://www.example.com/.netlify/functions/identity'; // Absolute url to endpoint. ONLY USE IN SPECIAL CASES!
namePlaceholder: 'some-placeholder-for-Name'; // custom placeholder for name input form
locale: 'en'; // language code for translations - available: en, fr - default to en
locale: 'en'; // language code for translations - available: en, fr, es - default to en
}
```

Expand Down
1 change: 1 addition & 0 deletions src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<select name="locale" id="locale" onChange="changeLocale(this.value)">
<option value="en">English</option>
<option value="fr">French</option>
<option value="es">Espa&ntilde;ol</option>
</select>
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions src/translations/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"log_in": "Iniciar sesión",
"log_out": "Cerrar sesión",
"logged_in_as": "Conectado como",
"logged_in": "Conectado",
"logging_in": "Iniciando sesión",
"logging_out": "Cerrando cuenta",
"sign_up": "Registrarse",
"signing_up": "Registrandose",
"forgot_password": "¿Olvidó su contraseña?",
"recover_password": "Recuperar contraseña",
"send_recovery_email": "Enviar correo electrónico de recuperación",
"sending_recovery_email": "Envío de correo electrónico de recuperación",
"never_mind": "No importa",
"update_password": "Actualizar contraseña",
"updating_password": "Actualizando contraseña",
"complete_your_signup": "Complete su registro",
"site_url_title": "Configuración de desarrollo",
"site_url_link_text": "Borrar URL del localhost",
"site_url_message": "Parece que está corriendo un servidor local. Háganos saber la URL de su sitio en Netlify.",
"site_url_label": "Ingrese la URL de su sitio en Netlify",
"site_url_placeholder": "URL de su sitio en Netlify",
"site_url_submit": "Establecer la URL del sitio",
"message_confirm": "Se envió un mensaje de confirmación a su correo electrónico, haga clic en el enlace allí para continuar.",
"message_password_mail": "Hemos enviado un correo electrónico de recuperación a su correo electrónico, siga el enlace allí para restablecer su contraseña.",
"message_email_changed": "¡Su dirección de correo electrónico ha sido actualizada!",
"message_verfication_error": "Se produjo un error al verificar su cuenta. Por favor intente nuevamente o contacte a un administrador.",
"message_signup_disabled": "Los registros públicos están deshabilitados. Póngase en contacto con un administrador y solicite una invitación.",
"form_name_placeholder": "Nombre",
"form_email_label": "Introduzca su correo electrónico",
"form_name_label": "Introduzca su nombre",
"form_email_placeholder": "Correo electrónico",
"form_password_label": "Ingrese su contraseña",
"form_password_placeholder": "Contraseña",
"coded_by": "Codificado por Netlify",
"No user found with this email": "No existe ningún usuario con este correo electrónico",
"Invalid Password": "La contraseña es invalida",
"continue_with": "Continúe con"
}
3 changes: 2 additions & 1 deletion src/translations/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as en from "./en.json";
import * as fr from "./fr.json";
import * as es from "./es.json";

export const defaultLocale = "en";
const translations = { en, fr };
const translations = { en, fr, es };

export const getTranslation = (key, locale = defaultLocale) => {
const translated = translations[locale] && translations[locale][key];
Expand Down
7 changes: 7 additions & 0 deletions src/translations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe("translations", () => {
expect(getTranslation("log_in", "fr")).toEqual("Connexion");
});

it("should return translation for 'es' locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in", "es")).toEqual("Iniciar sesión");
});

it("should return key for non existing translation", () => {
const { getTranslation } = require("./");
expect(getTranslation("unknown_key")).toEqual("unknown_key");
Expand All @@ -26,9 +31,11 @@ describe("translations", () => {
it("should default to 'en' on missing key", () => {
jest.mock("./en.json", () => ({ log_in: "Log in" }));
jest.mock("./fr.json", () => ({}));
jest.mock("./es.json", () => ({}));

const { getTranslation } = require("./");
expect(getTranslation("log_in")).toEqual("Log in");
expect(getTranslation("log_in", "fr")).toEqual("Log in");
expect(getTranslation("log_in", "es")).toEqual("Log in");
});
});