Skip to content
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

Add english translations to members page #512

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amrsoll
Copy link
Contributor

@amrsoll amrsoll commented Apr 27, 2024

It seems like the babel translation tool with .pot file(s) could unify the translation methods, what do you think? I will come with an extra commit to show what I mean

Summary by CodeRabbit

  • New Features

    • Enhanced localization across the webshop with dynamic content in titles and text labels, supporting multiple languages.
    • Added translation capabilities in various web templates, including shopping cart, courses, and member pages.
  • Bug Fixes

    • Fixed language consistency issues by implementing translation functions across all user-facing text elements.
  • Documentation

    • Updated translation files to include new terms and phrases used across the webshop, ensuring accuracy and consistency in multiple languages.
  • Refactor

    • Improved code maintainability by integrating translation functions and updating template syntax for dynamic content rendering.
  • Chores

    • Updated dependencies to include necessary libraries for localization support.

Copy link

coderabbitai bot commented Apr 27, 2024

Walkthrough

The recent updates mainly focus on enhancing the localization and translation capabilities of a webshop project. Changes include the introduction of dynamic content in HTML templates using translation functions, updating Docker configurations to include additional libraries for localization, and modifications in TypeScript files to integrate translation hooks. The project now supports more inclusive language options, improving accessibility for users with different language preferences.

Changes

File(s) Change Summary
public/Dockerfile Updated to include flask_babel for localization support.
public/src/public.py, public/ts/... Integrated localization functionalities like flask_babel.Babel and useTranslation() hooks.
HTML Templates (cart.html, courses.html, etc.) Updated titles and content to use dynamic translation tags ({{ _("Text") }}).
.pot and .po files Updated translation files to support new strings in various languages.
TypeScript Files (member.tsx, translations.tsx) Enhanced translation handling in TypeScript components, added new translation strings and functions.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f5310af and 85453df.
Files ignored due to path filters (1)
  • public/babel.cfg is excluded by !**/*.cfg
Files selected for processing (21)
  • public/Dockerfile (1 hunks)
  • public/en.pot (1 hunks)
  • public/src/public.py (3 hunks)
  • public/src/templates/cart.html (1 hunks)
  • public/src/templates/courses.html (1 hunks)
  • public/src/templates/history.html (1 hunks)
  • public/src/templates/licenses.html (1 hunks)
  • public/src/templates/login.html (1 hunks)
  • public/src/templates/member.html (1 hunks)
  • public/src/templates/payment_form.html (2 hunks)
  • public/src/templates/product.html (2 hunks)
  • public/src/templates/quiz/questions.html (1 hunks)
  • public/src/templates/quiz/quiz.html (1 hunks)
  • public/src/templates/receipt.html (1 hunks)
  • public/src/templates/register.html (1 hunks)
  • public/src/templates/reset_password.html (1 hunks)
  • public/src/templates/shop.html (1 hunks)
  • public/src/templates/statistics.html (2 hunks)
  • public/sv.po (1 hunks)
  • public/ts/member.tsx (14 hunks)
  • public/ts/translations.tsx (5 hunks)
Files skipped from review due to trivial changes (7)
  • public/en.pot
  • public/src/templates/licenses.html
  • public/src/templates/member.html
  • public/src/templates/payment_form.html
  • public/src/templates/reset_password.html
  • public/src/templates/shop.html
  • public/sv.po
Additional comments not posted (23)
public/src/templates/login.html (1)

4-4: Title translation implemented correctly.

Ensure that the translation system correctly handles the key "Webshop" and that it is properly set up in the .pot and .po files.

public/src/templates/courses.html (1)

4-4: Title translation implemented correctly.

Ensure that the translation system correctly handles the key "Courses" and that it is properly set up in the .pot and .po files.

public/src/templates/quiz/questions.html (1)

4-4: Title translation implemented correctly.

Ensure that the translation system correctly handles the key "Quiz" and that it is properly set up in the .pot and .po files.

public/src/templates/history.html (1)

4-7: Title translation implemented correctly.

Ensure that the translation system correctly handles the keys "Purchase History" and "Webshop" and that they are properly set up in the .pot and .po files.

public/src/templates/register.html (1)

4-4: Title translation implemented correctly.

Ensure that the translation system correctly handles the key "Become a Member" and that it is properly set up in the .pot and .po files.

public/src/templates/receipt.html (1)

4-4: Title translation implemented correctly.

Ensure that the translation system correctly handles the key "Webshop" and that it is properly set up in the .pot and .po files.

public/Dockerfile (1)

21-21: Addition of flask_babel to Dockerfile is correct.

Ensure that flask_babel is correctly integrated with the Flask application and that it functions as expected in the container environment.

public/src/templates/cart.html (1)

4-6: Title translation implemented correctly.

Ensure that the translation system correctly handles the keys "Shopping Cart" and "Webshop" and that they are properly set up in the .pot and .po files.

public/src/templates/quiz/quiz.html (1)

4-4: Title translation implemented correctly.

Please ensure that the translation string for "Quiz" is correctly defined in the translation files.

public/src/templates/statistics.html (2)

4-4: Title translation implemented correctly.

Please ensure that the translation string for "Statistics" is correctly defined in the translation files.


22-22: Header translation implemented correctly.

Please ensure that the translation string for "Statistics for the makerspace" is correctly defined in the translation files.

public/src/templates/product.html (2)

4-4: Title translation implemented correctly.

Please ensure that the translation string for "Webshop" is correctly defined in the translation files.


21-26: Navigation button translations implemented correctly.

Please ensure that the translation strings for "Back" and "Shopping Cart" are correctly defined in the translation files.

public/src/public.py (3)

8-8: flask_babel import implemented correctly.


41-49: Locale selector function implemented correctly.

Please ensure that the locale selection works as expected during integration testing.


145-145: Flask-Babel configuration implemented correctly.

public/ts/translations.tsx (4)

11-11: New URLs added for translation context.


504-520: Lab membership translation strings implemented correctly.

Please ensure that these translation strings are used correctly in the application.


521-543: Membership translation strings implemented correctly.

Please ensure that these translation strings are used correctly in the application.


575-583: Phone number change translation strings implemented correctly.

Please ensure that these translation strings are used correctly in the application.

public/ts/member.tsx (3)

221-221: Ensure consistent translation key usage.

The translation key used here, member_page.old_membership_status.labaccess.inactive_recent, should be verified for consistency across the application to ensure it matches other similar usage contexts.


519-519: Validate dynamic translation function usage.

The dynamic translation function usage here should be validated to ensure that it correctly handles the parameters and returns the expected results in various locales.


769-769: Ensure translation keys are correctly implemented.

The translation key member_page.addr.street_and_number used here should be verified to ensure it is correctly implemented in the translation files and consistent with other similar keys in the application.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@amrsoll amrsoll marked this pull request as ready for review April 28, 2024 22:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

public/ts/member.tsx Show resolved Hide resolved
Comment on lines +444 to +446
`<h2>${t(
"change_pin.error",
)}</h2><b class="uk-text-danger"">${get_error(e)}</b>`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling presentation.

The error message presentation here could be improved for better user experience. Consider using a more structured layout or additional styling to make the error message clearer and more user-friendly.

- `<h2>${t("change_pin.error")}</h2><b class="uk-text-danger"">${get_error(e)}</b>`,
+ `<h2>${t("change_pin.error")}</h2><div class="uk-alert-danger" uk-alert><p>${get_error(e)}</p></div>`,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
`<h2>${t(
"change_pin.error",
)}</h2><b class="uk-text-danger"">${get_error(e)}</b>`,
`<h2>${t(
"change_pin.error",
)}</h2><div class="uk-alert-danger" uk-alert><p>${get_error(e)}</p></div>`,

Du har inte satt någon PIN-kod ännu. Använd BYT-knappen för att
sätta den. PIN-koden används för{" "}
<a href={URL_MEMBERBOOTH}>memberbooth</a>.
{t("member_page.no_pin_warning")}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address potential accessibility issues.

The color red is used directly in the style for indicating warning messages. Consider using a class that can be controlled via CSS for better accessibility and to support themes.

- <label class="uk-form-label" style="color: red;">
+ <label class="uk-form-label warning-label">

And in your CSS file:

.warning-label {
    color: red; /* Or use a more accessible color */
}

Copy link
Contributor

@HalfVoxel HalfVoxel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Great job!

Looks good for the most part, but with a few comments.

I'm not sure about using POT files. They look somewhat ancient.
Fluent seems like a more modern choice: https://github.com/projectfluent/python-fluent/blob/main/fluent.runtime/docs/usage.rst, but I haven't looked into this in depth.
They seem to be preferred by Mozilla: https://mozilla-l10n.github.io/documentation/localization/dev_best_practices.html

There also seems to be typescript support: https://github.com/macabeus/fluent-typescript (first result when googling).
Changing everything to use Fluent, POT, or some other system will be a lot of work, though. So it's probably best to get this PR merged before doing that.

@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Stockholm Makerspace Webshop</title>
<title>Stockholm Makerspace {{ _("Webshop") }}</title>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Stockholm Makerspace should be a localization string as well? To make it easier to re-use for different makerspaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering it, but what you actually want there is a variable holding the brand name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.

>
<a class="product-nav-right" href='{{ url("/cart") }}'
>Min kundvagn<span id="cart-sum"></span>
>{{ _("Shopping Cart") }}Min kundvagn<span
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you left the original text here.

@@ -461,7 +463,9 @@ async function change_phone_number(
);
switch (r) {
case "ok":
await UIkit.modal.alert(`<h2>Telefonnummret är nu bytt</h2>`);
await UIkit.modal.alert(
`<h2>${t("change_phone.validation_changed_success")}</h2>`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phone_number_changed_success?

(only {days} day(s) left). Remember to extend your lab
membership before next Friday morning.
{t("member_page.labaccess.valid")(enddate, days)}
{t("member_page.labaccess.extend_on_friday")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{t("member_page.labaccess.extend_on_friday")}
{t("member_page.labaccess.expires_within_days")}

The Friday text was actually outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rip out that string entirely instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably do, yeah.

},
addr: {
street_and_number: "Street and number",
extra: "Extra address info, fx C/O, 2.th.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fx intended to stand for for example here? I don't think that's a common usage. Use e.g. instead.
Also, I'm not quite sure what 2.th. is supposed to mean.

Copy link
Contributor Author

@amrsoll amrsoll May 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it isn't standard at all, I simply wanted to have it understandable for people living in Denmark. Unfortunately this type of info is mostly based on location, not language, so we can't find a standard

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 2.th. I can accept that, but e.g. is the English abbreviation for "for example", not fx.

@@ -557,6 +678,7 @@ export const useTranslation = (): Translator => {

const heuristicallyPickLanguage = (): "en" | "sv" => {
const langs = navigator.languages || [navigator.language];
console.log("lang ", langs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a generated file. If so, it should be ignored and added so it's generated when building (if it isn't already).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants