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

feat(i18n): improve texts sizes #1204

Merged
merged 10 commits into from
Aug 26, 2024
Merged

Conversation

pladaria
Copy link
Member

@pladaria pladaria commented Aug 21, 2024

  • Texts moved to text-tokens.tsx. Once the text tokens defined by design are ready we could autogenerate this file
  • A Token is an object like: {es: 'Patata', en: 'Potato', de: 'Kartofel', ...}
  • Each component imports (by name) the required tokens
  • The provider still allows to override texts

Copy link

github-actions bot commented Aug 21, 2024

Size stats

master this branch diff
Total JS 12.1 MB 12.1 MB +1.96 kB
JS without icons 2.03 MB 2.03 MB +1.96 kB
Lib overhead 77 kB 68.1 kB -8.91 kB
Lib overhead (gzip) 18.9 kB 16.5 kB -2.4 kB

Copy link

github-actions bot commented Aug 21, 2024

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

Copy link

github-actions bot commented Aug 21, 2024

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-2foqr098s-flows-projects-65bb050e.vercel.app

Built with commit 45c617e.
This pull request is being automatically deployed with vercel-action

src/callout.tsx Outdated Show resolved Hide resolved
src/callout.tsx Outdated
Comment on lines 55 to 58
const {
texts,
i18n: {locale},
} = useTheme();
Copy link
Member Author

Choose a reason for hiding this comment

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

As you can see we now require to get the locale and import a translate function to get the translation.
Also, the locale must be converted to language inside the translate function.

This can be improved.

useTheme could provide the translate function and the language can be precalculated in the context creation, so no extra imports (apart of the tokens) would be needed.

Unless you think a better approach, I will make this change

Copy link
Member Author

@pladaria pladaria Aug 21, 2024

Choose a reason for hiding this comment

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

choose one

const {t} = useTheme(); // I prefer this one. `t` is commonly used for translations
const {translate} = useTheme(); 
const {i18n: {t}} = useTheme();
const {i18n: {translate}} = useTheme();

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like const {translate} = useTheme(); but t is ok too
You could have a different hook just for translations too const translate = useTranslate()

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to keep it in the same useTheme hook. This way we avoid an additional import and the useTheme is required anyway to get the text overrides

Copy link
Collaborator

Choose a reason for hiding this comment

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

Using {t} sounds good to me

src/callout.tsx Outdated
Comment on lines 115 to 117
closeButtonLabel ||
texts.closeButtonLabel ||
translate(closeButtonLabelText, locale)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I'm using || instead of ??. I think we can consider empty strings as missing

src/callout.tsx Outdated
Comment on lines 114 to 117
aria-label={
closeButtonLabel ||
texts.closeButtonLabel ||
translate(closeButtonLabelText, locale)
Copy link
Member Author

Choose a reason for hiding this comment

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

You will see this pattern a lot in following files:

texts.patata || translate(patata)

I'm unable to think way to avoid having to write this in each token usage (unless we disable text customization)

Copy link
Collaborator

@marcoskolodny marcoskolodny Aug 23, 2024

Choose a reason for hiding this comment

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

Maybe we could have some kind of utility function that does this and use it everywhere?

const getTranslation = (token) => texts[token] || translate(token, locale)

In this way, we avoid having to write the || logic everywhere

Copy link
Member Author

@pladaria pladaria Aug 26, 2024

Choose a reason for hiding this comment

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

that wouldn't work.

Imagine you want to translate the text defined by "cancel"

// from the provider's context
texts: {
    cancel: 'cancelar`, 
    ...
}

// from text-tokens.tsx
export const cancel = {es: 'cancelar', en: 'cancel'...}.

Then...

const getTranslation = (token) => { // ----> is this token value the "cancel" string?
  if (texts.token) { // --->  this would be `texts["cancel"]`. That's fine
    return texts.token;
  }
  return translate(???, locale);  // ---> the translate function accepts as parameter a Token type, 
  // which is an object like {es: 'cancelar', en: 'cancel'...}.
  // We can't use the "cancel" string here as parameter
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I see :(

I think we can proceed with what we have now, and if we come up with some ideas in the future, we can iterate on this

@pladaria pladaria marked this pull request as ready for review August 22, 2024 13:33
@pladaria pladaria added this pull request to the merge queue Aug 26, 2024
Merged via the queue into master with commit 0345e7c Aug 26, 2024
11 checks passed
@pladaria pladaria deleted the pladaria/WEB-1987_improve-texts-sizes branch August 26, 2024 10:21
pladaria added a commit that referenced this pull request Aug 28, 2024
tuentisre pushed a commit that referenced this pull request Sep 3, 2024
# [15.19.0](v15.18.0...v15.19.0) (2024-09-03)

### Bug Fixes

* **Buttons:** avoid warnings related to change in order of react hooks ([#1229](#1229)) ([2dbc411](2dbc411))
* **i18n): Revert "feat(i18n:** improve texts sizes" because it is breaking ([#1226](#1226)) ([79eb4a4](79eb4a4))
* **Logo:** fix webpackChunkName magic comments ([#1214](#1214)) ([3d1f098](3d1f098))
* **Vivinho char:** vivinho char in headings being read as a separated heading ([#1209](#1209)) ([f0f5fb0](f0f5fb0))

### Features

* **Buttons:** refactor code and fix spacing bug in loading buttonLink ([#1212](#1212)) ([640e429](640e429))
* **i18n:** improve texts sizes ([#1204](#1204)) ([0345e7c](0345e7c))
* **Logo:** Refactor logo to improve bundle size and loading times ([#1210](#1210)) ([15b77cb](15b77cb))
* **NavigationBar, FunnelNavigationBar, MainNavigationBar:** add alternative variant ([#1200](#1200)) ([eef87ec](eef87ec))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 15.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants