Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

feat: right to left layout #101

Merged
merged 17 commits into from
Jun 8, 2023
Merged

feat: right to left layout #101

merged 17 commits into from
Jun 8, 2023

Conversation

Pertempto
Copy link
Contributor

@Pertempto Pertempto commented May 30, 2023

To Do

  • Add Arabic book names
  • Look at replacing tailwindcss-rtl with alternative method

@Pertempto Pertempto linked an issue May 30, 2023 that may be closed by this pull request
@vercel
Copy link

vercel bot commented May 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gloss-translation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2023 0:30am
gloss-translation-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2023 0:30am

@Pertempto Pertempto changed the title 85 right to left layout feat:right to left layout May 30, 2023
@vercel vercel bot temporarily deployed to Preview – gloss-translation May 30, 2023 09:48 Inactive
@Pertempto Pertempto changed the title feat:right to left layout feat: right to left layout May 30, 2023
package.json Outdated
@@ -65,6 +65,7 @@
"react-i18next": "12.2.0",
"react-refresh": "0.10.0",
"tailwindcss": "3.2.7",
"tailwindcss-rtl": "^0.9.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this library might not be the best supported, but it does what it does well. I think it is easier to read and write me-4 than ltr:ml-4 rtl:mr-4, especially when we will have that kind of thing all throughout the codebase. The start-[x] and end-[x] utilities are also very useful, instead of ltr:left-[x] rtl:right-[x].

The only bug I really ran into was that the library doesn't handle negative numbers. 20lives/tailwindcss-rtl#53. It does look like the maintainer has quite releasing updates.

Copy link
Member

@arrocke arrocke Jun 1, 2023

Choose a reason for hiding this comment

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

I'm in total agreement about the ease of these new utilities. However, given that we've already run into a limitation of this unmaintained library, what do you think about using the code from the library directly in our tailwind config? Since we are going to be heavily using direction utilities, maybe we should have control over them. Here is all that it would take to add margin utilities, including negative margins. That just wasn't released in this library. We wouldn't need to add everything the library supports to start, just the ones that we need.

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 didn't even think of this. Good idea.

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 think I brought over all the utilities we are using.

@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 1, 2023 09:49 Inactive
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 didn't even try to translate the short versions, I didn't know where to start. We definitely will want an actual Arabic speaker to update all the translations in this file at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the name translations are computer generated. I went back and replaced a few from this list.

Copy link
Member

Choose a reason for hiding this comment

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

We can remove the short versions for now. In situations where we would use t('gen', { context: 'short' }) it will fallback to the normal key if the _short key is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@vercel vercel bot temporarily deployed to Preview – gloss-translation June 1, 2023 09:50 Inactive
@Pertempto Pertempto marked this pull request as ready for review June 1, 2023 09:58
@Pertempto Pertempto requested a review from arrocke June 1, 2023 09:58
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 1, 2023 09:59 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 1, 2023 09:59 Inactive
# Conflicts:
#	packages/web/src/features/languages/LanguagesView.tsx
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 1, 2023 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 1, 2023 21:46 Inactive
Copy link
Member

@arrocke arrocke left a comment

Choose a reason for hiding this comment

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

Nice work on figuring this out. It's working really well

import { FlashProvider } from './shared/hooks/flash';

function App() {
const { i18n } = useTranslation();
document.body.dir = i18n.dir();
Copy link
Member

Choose a reason for hiding this comment

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

We should only update this when the language changes. We can use useEffect to set up event listeners to i18next events

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I should create a local "dir" variable, update it in the event callback, and watch that variable in the useEffect? (I'm still trying to get comfortable with the react way of doing things)

Copy link
Member

Choose a reason for hiding this comment

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

Something like this should work:

useEffect(() => {
  function handler() {
    document.body.dir = i18next.dir()
  }
  i18next.on('initialized', handler)
  i18next.on('languageChanged', handler)
}, [i18next.dir, i18next.on])

That will attach event listeners to i18next and only apply changes when the language changes. Both the dir and on functions should be stable (meaning their reference doesn't change), so this effect will fire only once on first render and attach the listeners.

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 tried this, but the handler never got called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that both events trigger before the callback of useEffect is called.

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 think my newest commit fixes it. Instead of using the initialized event, I just call the handler directly from the effect.

Copy link
Member

Choose a reason for hiding this comment

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

We can remove the short versions for now. In situations where we would use t('gen', { context: 'short' }) it will fallback to the normal key if the _short key is missing.

Copy link
Member

Choose a reason for hiding this comment

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

These locale json files have been updated in the past few PRs. Can you make sure the arabic ones are up to date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 45 to 47
{/* Use flex-row-reverse on rtl, so that the previous button is always
to the left of the next button. */}
<div className="flex ltr:flex-row rtl:flex-row-reverse gap-4">
Copy link
Member

Choose a reason for hiding this comment

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

In a RTL language, we want the next button to be on the right. It's confusing for us, but natural in those languages. We should be able to remove this secondary flex box and leave it in the natural rtl order, but flip the icons.

Might be easiest to render two icons and show/hide the correct one with tailwind rather than trying to manage that with react

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 wondered if this was the case or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just looked so strange to me 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

package.json Outdated
@@ -65,6 +65,7 @@
"react-i18next": "12.2.0",
"react-refresh": "0.10.0",
"tailwindcss": "3.2.7",
"tailwindcss-rtl": "^0.9.0",
Copy link
Member

@arrocke arrocke Jun 1, 2023

Choose a reason for hiding this comment

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

I'm in total agreement about the ease of these new utilities. However, given that we've already run into a limitation of this unmaintained library, what do you think about using the code from the library directly in our tailwind config? Since we are going to be heavily using direction utilities, maybe we should have control over them. Here is all that it would take to add margin utilities, including negative margins. That just wasn't released in this library. We wouldn't need to add everything the library supports to start, just the ones that we need.

@arrocke
Copy link
Member

arrocke commented Jun 2, 2023

I noticed this when preparing my update video: When in a RTL language, we still want the Hebrew translation line to be RTL. Right now, they are flipped back to LTR

@Pertempto
Copy link
Contributor Author

I noticed this when preparing my update video: When in a RTL language, we still want the Hebrew translation line to be RTL. Right now, they are flipped back to LTR

Thanks for catching that! I remember noticing this, but then I forgot to address it.

@vercel vercel bot temporarily deployed to Preview – gloss-translation June 2, 2023 15:30 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 2, 2023 15:30 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 2, 2023 15:45 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 2, 2023 15:45 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 2, 2023 15:49 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 2, 2023 15:49 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 2, 2023 15:52 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 2, 2023 15:52 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 2, 2023 16:21 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 2, 2023 16:22 Inactive
@Pertempto Pertempto requested a review from arrocke June 2, 2023 16:22
@Pertempto
Copy link
Contributor Author

I think I addressed everything you brought up. I'll be offline until Wednesday.

@vercel vercel bot temporarily deployed to Preview – gloss-translation June 6, 2023 00:07 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 6, 2023 00:08 Inactive
packages/web/src/tailwind-utilities/index.js Outdated Show resolved Hide resolved
@Pertempto Pertempto merged commit 8221b96 into main Jun 8, 2023
@Pertempto Pertempto deleted the 85-right-to-left-layout branch June 8, 2023 00:29
@vercel vercel bot temporarily deployed to Preview – gloss-translation June 8, 2023 00:29 Inactive
@vercel vercel bot temporarily deployed to Preview – gloss-translation-api June 8, 2023 00:30 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

right to left layout
2 participants