From cd4e628e118c1b2b306c3fb3e5882a770f4a9cb3 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sun, 1 Dec 2019 14:08:12 -0700 Subject: [PATCH] Utilize nested locale translations and update usage --- app/appUtilities.js | 4 +- app/views/home/loggedIn.js | 6 +- app/views/home/loggedOut.js | 16 ++--- app/views/login/index.js | 2 +- app/views/search/index.js | 18 +++--- server/controllers/account.js | 26 ++++---- server/i18n/locales/en/ui.json | 110 ++++++++++++++++++++------------- server/routes/account.js | 28 ++++----- 8 files changed, 116 insertions(+), 94 deletions(-) diff --git a/app/appUtilities.js b/app/appUtilities.js index 0ada424..896ddb6 100644 --- a/app/appUtilities.js +++ b/app/appUtilities.js @@ -25,11 +25,11 @@ export const appUtilities = (app) => { .then(response => response.json()) .then(response => { if (response.error !== false) { - console.warn(response); + console.warn(appState.i18n.__(response.message)); return false; } - console.info(response.message); + console.info(appState.i18n.__(response.message)); appState.isLoggedIn = true; return true; }); diff --git a/app/views/home/loggedIn.js b/app/views/home/loggedIn.js index 7243c73..f94c6a0 100644 --- a/app/views/home/loggedIn.js +++ b/app/views/home/loggedIn.js @@ -5,12 +5,12 @@ export const loggedInView = (homeController, emit) => { return [ html`
-

${__('home.logged_in_subtitle')}

+

${__('home.logged_in.subtitle')}

-

${__('home.logged_in_updates')}

+

${__('home.logged_in.updates')}

@@ -23,7 +23,7 @@ export const loggedInView = (homeController, emit) => {
-

${__('home.logged_in_interactions')}

+

${__('home.logged_in.interactions')}

diff --git a/app/views/home/loggedOut.js b/app/views/home/loggedOut.js index fb0344b..05996d6 100644 --- a/app/views/home/loggedOut.js +++ b/app/views/home/loggedOut.js @@ -5,7 +5,7 @@ export const loggedOutView = (homeController, emit) => { return [ html`
-

${__('home.logged_out_subtitle')}

+

${__('home.logged_out.subtitle')}

@@ -15,7 +15,7 @@ export const loggedOutView = (homeController, emit) => {
- ${__('home.logged_out_track_books')} + ${__('home.logged_out.track_books')}
@@ -27,7 +27,7 @@ export const loggedOutView = (homeController, emit) => {
- ${__('home.logged_out_share_friends')} + ${__('home.logged_out.share_friends')}
@@ -39,19 +39,19 @@ export const loggedOutView = (homeController, emit) => {
- ${__('home.logged_out_read_rate')} + ${__('home.logged_out.read_rate')}
`, html`
-

${__('home.logged_out_community_header')}

+

${__('home.logged_out.community_header')}

-

${__('home.logged_out_recent_reviews')}

+

${__('home.logged_out.recent_reviews')}

@@ -64,7 +64,7 @@ export const loggedOutView = (homeController, emit) => {
-

${__('home.logged_out_recent_updates')}

+

${__('home.logged_out.recent_updates')}

@@ -77,7 +77,7 @@ export const loggedOutView = (homeController, emit) => {
`, html`
- ${__('home.logged_out_join_now')} + ${__('home.logged_out.join_now')}
`, ]; } \ No newline at end of file diff --git a/app/views/login/index.js b/app/views/login/index.js index f30ec85..88e07f3 100644 --- a/app/views/login/index.js +++ b/app/views/login/index.js @@ -20,7 +20,7 @@ export const loginView = (state, emit, i18n) => {
${ controller.state.loginMessage === '' - ? __('login.already_logged_in') + ? __('api.already_logged_in') : controller.state.loginMessage }
diff --git a/app/views/search/index.js b/app/views/search/index.js index dd166e4..b1dfe83 100644 --- a/app/views/search/index.js +++ b/app/views/search/index.js @@ -48,7 +48,7 @@ export const searchView = (state, emit, i18n) => {
${modal('searchSourceInfo', controller, [ html`

- ${__('search.search_source_help_text')} + ${__('search.search_source.help.text')}

`, html``, ], { - buttonText: __('search.search_source_help_button'), + buttonText: __('search.search_source.help.button'), buttonClasses: 'small marginless pseudo button pull-right', - headerText: __('search.search_source_help_header'), + headerText: __('search.search_source.help.header'), })}
diff --git a/server/controllers/account.js b/server/controllers/account.js index fdd3273..eac818b 100644 --- a/server/controllers/account.js +++ b/server/controllers/account.js @@ -30,19 +30,19 @@ class AccountController { || createAccountData.password === '') { return { error: true, - message: 'api.account_create_required_data_missing', + message: 'api.account.create.required_data_missing', }; } if (createAccountData.email.length < 5 || !/^.+@.+\..+$/.test(createAccountData.email)) { return { error: true, - message: 'api.account_create_invalid_email', + message: 'api.account.create.invalid_email', }; } if (createAccountData.username.length < 2 || !/^[a-z0-9_]+$/i.test(createAccountData.username)) { return { error: true, - message: 'api.account_create_invalid_username', + message: 'api.account.create.invalid_username', }; } @@ -55,13 +55,13 @@ class AccountController { || loginData.password === '') { return { error: true, - message: 'api.account_login_required_data_missing', + message: 'api.account.login.required_data_missing', }; } if (loginData.email.length < 5 || !/^.+@.+\..+$/.test(loginData.email)) { return { error: true, - message: 'api.account_login_invalid_email', + message: 'api.account.login.invalid_email', }; } @@ -84,7 +84,7 @@ class AccountController { || !createAccountData.confirm) { return { error: true, - message: 'api.account_confirm_required_data_missing', + message: 'api.account.confirm.required_data_missing', }; } @@ -117,13 +117,13 @@ class AccountController { if (emailExists) { return { error: true, - message: 'api.account_email_exists', + message: 'api.account.email_exists', }; } if (usernameExists) { return { error: true, - message: 'api.account_username_exists', + message: 'api.account.username_exists', }; } @@ -160,7 +160,7 @@ class AccountController { if (!userToConfirm) { return { error: true, - message: 'api.account_confirm_invalid_code', + message: 'api.account.confirm.invalid_code', } } @@ -175,7 +175,7 @@ class AccountController { if (success[0] < 1) { return { error: true, - message: 'api.account_confirm_update_fail', + message: 'api.account.confirm.update_fail', } } return userToConfirm; @@ -192,14 +192,14 @@ class AccountController { if (existingUser == null) { return { error: true, - message: 'api.account_login_invalid_email', + message: 'api.account.login.invalid_email', }; } if (existingUser.accountConfirm !== null) { return { error: true, - message: 'api.account_login_not_confirmed', + message: 'api.account.login.not_confirmed', }; } @@ -207,7 +207,7 @@ class AccountController { if (!passwordIsValid) { return { error: true, - message: 'api.account_login_invalid_password', + message: 'api.account.login.invalid_password', }; } diff --git a/server/i18n/locales/en/ui.json b/server/i18n/locales/en/ui.json index 0fed5d7..7d451e4 100644 --- a/server/i18n/locales/en/ui.json +++ b/server/i18n/locales/en/ui.json @@ -9,20 +9,24 @@ "menu_logout": "Log Out", "footer_repo": "Repo", "footer_chat": "Chat", - "change_language": "Change Language" + "change_language": "Language" }, "home": { - "logged_out_subtitle": "All the Book Buzz in Once Place", - "logged_out_track_books": "Keep track of books you've read, want to read, and are currently reading.", - "logged_out_share_friends": "Share your thoughts about what you're reading and see what your friends think of their books.", - "logged_out_read_rate": "Rate, review, and recommmend books or something. I dunno. It's early days, my friends!", - "logged_out_community_header": "A Look Inside the Hive", - "logged_out_recent_reviews": "Recent Reviews", - "logged_out_recent_updates": "Recent Updates", - "logged_out_join_now": "Join Now!", - "logged_in_subtitle": "Welcome!", - "logged_in_updates": "Updates", - "logged_in_interactions": "Interactions" + "logged_out": { + "subtitle": "All the Book Buzz in Once Place", + "track_books": "Keep track of books you've read, want to read, and are currently reading.", + "share_friends": "Share your thoughts about what you're reading and see what your friends think of their books.", + "read_rate": "Rate, review, and recommmend books or something. I dunno. It's early days, my friends!", + "community_header": "A Look Inside the Hive", + "recent_reviews": "Recent Reviews", + "recent_updates": "Recent Updates", + "join_now": "Join Now!" + }, + "logged_in": { + "subtitle": "Welcome!", + "updates": "Updates", + "interactions": "Interactions" + } }, "404": { "header": "Oops!", @@ -46,15 +50,21 @@ "header": "Search", "placeholder": "Search for Books", "button_text": "Search", - "search_source_label": "Search Source", - "search_source_help_button": "What's This?", - "search_source_help_header": "What does \"Search Source\" mean?", - "search_source_help_text": "This refers to where the search tries to look for data. Each source can be easily contributed to if you want to add missing books or correct errors.", - "search_source_help_inventaire": "Sources and extends data from WikiData, the service structure that powers Wikipedia and the like. Offers as many language options as possible.", - "search_source_help_openLibrary": "Sources data from Internet Archive and may provide a digital copy to read. Only offers English unless a work is in another language.", - "search_by_label": "Search By", - "search_by_title": "Title", - "search_by_author": "Author", + "search_source": { + "label": "Search Source", + "help": { + "button": "What's This?", + "header": "What does \"Search Source\" mean?", + "text": "This refers to where the search tries to look for data. Each source can be easily contributed to if you want to add missing books or correct errors.", + "inventaire": "Sources and extends data from WikiData, the service structure that powers Wikipedia and the like. Offers as many language options as possible.", + "openLibrary": "Sources data from Internet Archive and may provide a digital copy to read. Only offers English unless a work is in another language." + } + }, + "search_by": { + "label": "Search By", + "title": "Title", + "author": "Author" + }, "loading": "Loading...", "no_results": "None Found", "no_results_suggestion": "If you're expecting book data, go and help fill out the Inventaire database!", @@ -73,28 +83,40 @@ "reviews_written": "Total Reviews Written" }, "api": { - "account_already_logged_in": "You are already logged in! You cannot create an account or log in again.", - "account_create_required_data_missing": "Could not create account because required data is missing.", - "account_create_invalid_email": "The email address entered is not valid.", - "account_create_invalid_username": "The username entered is not valid. Usernames must be at least 2 characters long and can only contain letters a–z, numbers 0–9, and underscores", - "account_email_exists": "The email address entered is already in use.", - "account_username_exists": "The username entered is already in use.", - "account_email_send_fail": "Your account was created successfully, but we were unable to send the confirmation email!", - "account_confirm_email": "A confirmation email has been sent to the address you specified. Please confirm your account using the link provided.", - "account_create_success": "Account created successfully! You may now log in using the email address and password you provided.", - "account_confirm_required_data_missing": "Could not confirm account because required data is missing.", - "account_confirm_invalid_code": "The specified confirmation code is not valid.", - "account_confirm_update_fail": "Something went wrong and we couldn't confirm your account. Please try again later!", - "account_confirm_email_send_fail": "Your account has been confirmed, but we were unable to send the email notification about it. You can log in anyway.", - "account_confirm_success_email": "Your account has been confirmed, and an email notification has been sent! You may now log in using your email address and password.", - "account_confirm_success": "Your account has been confirmed! You may now log in using your email address and password.", - "account_login_required_data_missing": "Could not attempt login because required data is missing.", - "account_login_invalid_email": "The email address specified does not have an associated account.", - "account_login_not_confirmed": "The specified account has not been confirmed. Please use the link you received to confirm your email address.", - "account_login_invalid_password": "The password specified is not correct.", - "account_login_success": "You have been successfully logged in! You will now be redirected to the home screen.", - "account_validate_missing_token": "User not logged in: There is no login token to validate.", - "account_validate_invalid_token": "User not logged in: The stored token is not a valid token.", - "account_validate_renewed_token": "User logged in, and the token has been renewed." + "not_logged_in": "You are not logged in.", + "already_logged_in": "You are already logged in! You cannot create an account or log in again.", + "account": { + "username_exists": "The username entered is already in use.", + "email_send_fail": "Your account was created successfully, but we were unable to send the confirmation email!", + "email_exists": "The email address entered is already in use.", + "create": { + "fail": "Something went wrong and the account could not be created. Please try again later.", + "required_data_missing": "Could not create account because required data is missing.", + "invalid_email": "The email address entered is not valid.", + "invalid_username": "The username entered is not valid. Usernames must be at least 2 characters long and can only contain letters a–z, numbers 0–9, and underscores", + "success": "Account created successfully! You may now log in using the email address and password you provided." + }, + "confirm": { + "email": "A confirmation email has been sent to the address you specified. Please confirm your account using the link provided.", + "required_data_missing": "Could not confirm account because required data is missing.", + "invalid_code": "The specified confirmation code is not valid.", + "update_fail": "Something went wrong and we couldn't confirm your account. Please try again later!", + "email_send_fail": "Your account has been confirmed, but we were unable to send the email notification about it. You can log in anyway.", + "success_email": "Your account has been confirmed, and an email notification has been sent! You may now log in using your email address and password.", + "success": "Your account has been confirmed! You may now log in using your email address and password." + }, + "login": { + "required_data_missing": "Could not attempt login because required data is missing.", + "invalid_email": "The email address specified does not have an associated account.", + "not_confirmed": "The specified account has not been confirmed. Please use the link you received to confirm your email address.", + "invalid_password": "The password specified is not correct.", + "success": "You have been successfully logged in! You will now be redirected to the home screen." + }, + "validate": { + "missing_token": "User not logged in: There is no login token to validate.", + "invalid_token": "User not logged in: The stored token is not a valid token.", + "renewed_token": "User logged in, and the token has been renewed." + } + } } } \ No newline at end of file diff --git a/server/routes/account.js b/server/routes/account.js index 2118570..4504e3e 100644 --- a/server/routes/account.js +++ b/server/routes/account.js @@ -12,7 +12,7 @@ async function routes(fastify, options) { if (request.isLoggedInUser) { return reply.code(400).send({ error: true, - message: 'api.account_already_logged_in', + message: 'api.already_logged_in', }); } @@ -33,7 +33,7 @@ async function routes(fastify, options) { const newUser = await account.createUser(formData.email, formData.username, formData.displayName, formData.password, fastify.canEmail); if (typeof newUser.error !== 'undefined' && newUser.error !== false) { - newUser.message = 'api.account_create_fail'; + newUser.message = 'api.account.create.fail'; return reply.code(400).send(newUser); } @@ -43,7 +43,7 @@ async function routes(fastify, options) { // If some of the default shelves are not created successfully, delete the user and send an error if (typeof defaultShelvesCreated.error !== 'undefined' && defaultShelvesCreated.error !== false) { account.deleteUser(newUser); - defaultShelvesCreated.message = 'api.account_create_fail'; + defaultShelvesCreated.message = 'api.account.create.fail'; return reply.code(400).send(defaultShelvesCreated); } @@ -72,14 +72,14 @@ async function routes(fastify, options) { console.error(email.err); return reply.send({ error: true, - message: 'api.account_email_send_fail', + message: 'api.account.email_send_fail', newUser, }); } return reply.send({ error: false, - message: 'api.account_confirm_email', + message: 'api.account.confirm.email', }); }); } catch (ex) { @@ -89,7 +89,7 @@ async function routes(fastify, options) { return reply.send({ error: false, - message: 'api.account_create_success', + message: 'api.account.create.success', }); }); @@ -97,7 +97,7 @@ async function routes(fastify, options) { if (request.isLoggedInUser) { return reply.code(400).send({ error: true, - message: 'api.account_already_logged_in', + message: 'api.already_logged_in', }); } @@ -137,13 +137,13 @@ async function routes(fastify, options) { console.error(email.err); return reply.code(400).send({ error: true, - message: 'api.account_confirm_email_send_fail', + message: 'api.account.confirm.email_send_fail', }); } return reply.send({ error: false, - message: 'api.account_confirm_success_email', + message: 'api.account.confirm.success_email', }); }) } catch (ex) { @@ -152,7 +152,7 @@ async function routes(fastify, options) { return reply.send({ error: false, - message: 'api.account_confirm_success', + message: 'api.account.confirm.success', }); }); @@ -182,7 +182,7 @@ async function routes(fastify, options) { }) .send({ error: false, - message: 'api.account_login_success', + message: 'api.account.login.success', }); }); @@ -190,7 +190,7 @@ async function routes(fastify, options) { if (typeof request.cookies.token === "undefined") { return reply.code(400).send({ error: true, - message: 'api.account_validate_missing_token', + message: 'api.account.validate.missing_token', }); } @@ -198,7 +198,7 @@ async function routes(fastify, options) { if (!tokenIsValid) { return reply.code(400).send({ error: true, - message: 'api.account_validate_invalid_token', + message: 'api.account.validate.invalid_token', }); } @@ -214,7 +214,7 @@ async function routes(fastify, options) { }) .send({ error: false, - message: 'api.account_validate_renewed_token', + message: 'api.account.validate.renewed_token', }); });