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 support for locale folders #1113

Merged
merged 23 commits into from
Oct 10, 2024
Merged

Add support for locale folders #1113

merged 23 commits into from
Oct 10, 2024

Conversation

Sporiff
Copy link
Collaborator

@Sporiff Sporiff commented Oct 7, 2024

Closes https://adjustcom.atlassian.net/browse/THC-1023

Due to limitations in our translation software, we've previously had to add workarounds for keeping all of our localized files in the same directory as the English content (with the locale appended to differentiate). Since this missing feature has been added, we can now make use of Astro's build-in 18n routing rules by moving our files to locale-based folders.

@Sporiff Sporiff added the enhancement New feature or request label Oct 7, 2024
@Sporiff Sporiff self-assigned this Oct 7, 2024
Copy link

vercel bot commented Oct 7, 2024

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

Name Status Preview Comments Updated (UTC)
dev-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 9:37am

Copy link

vercel bot commented Oct 8, 2024

Deployment failed with the following error:

Rewrite at index 0 has invalid `source` pattern "/(?<lang>[^/]*)/(.*)".

Learn More: https://vercel.link/invalid-route-source-pattern

Copy link

vercel bot commented Oct 9, 2024

Deployment failed with the following error:

If `rewrites`, `redirects`, `headers`, `cleanUrls` or `trailingSlash` are used, then `routes` cannot be present.

Learn More: https://vercel.link/mix-routing-props

@bzavhorodskyi
Copy link
Collaborator

bzavhorodskyi commented Oct 10, 2024

@Sporiff I can't make a good review cause I can't load a page with changes(I tried from both my machines and it`s just lagging and sending an error), but anyway:

  • On the 404 page we have a rewrite rule that probably will not work as we rely on Astro.currentLocale that is equal to 'en' in all cases, I`ve tried this way when working on the logic updates. We may need to extract language from the URL in such cases. or just display English version always(it seems we do this on the Production version)
  • Do we need to have middleware? Is it working as expected? I`ve also tried to work with middleware but seems it works only in the "server" mode(maybe something was changed)

Maybe I've missed something cause I can`t open all changes, but preview works for me

@Sporiff
Copy link
Collaborator Author

Sporiff commented Oct 10, 2024

@bzavhorodskyi

@Sporiff I can't make a good review cause I can't load a page with changes(I tried from both my machines and it`s just lagging and sending an error), but anyway:

You should be able to load it if you use the file filter to remove the mdx and mdoc files and just show the ts/mjs/astro files.

  • On the 404 page we have a rewrite rule that probably will not work as we rely on Astro.currentLocale that is equal to 'en' in all cases, I`ve tried this way when working on the logic updates. We may need to extract language from the URL in such cases. or just display English version always(it seems we do this on the Production version)

This is actually what we currently have. The 404.astro page in the pages directory gets copied at build time, but the 404 doesn't appear at a localized path (e.g. /en, /ja). Because of this, it's always showing up in English. As a test, you can use a locale switcher and go to https://dev.adjust.com/nonsense. You'll see an English 404 no matter what.

When using the i18n API in Astro without prefixing the default locale, the custom 404 file doesn't get copied unless it's inside the [lang] folder. I've opened up a ticket with the Astro team to address this because we agreed it's really an oversight on their part.

Basically, the 404 page doesn't appear under a locale route. It's just served at the root level whenever the user hits a nonexistent page. This means the localization doesn't work quite as expected. The Vercel middleware enables us to push the user to the English 404 page, but it's a bit limited beyond that.

  • Do we need to have middleware? Is it working as expected? I`ve also tried to work with middleware but seems it works only in the "server" mode(maybe something was changed)

Astro middleware is a bit limited on SSG mode because the middleware can't know at build time what the user's locale is or where they're trying to go. The best solution for this is probably just to put some inline script in the 404 page that redirects the user to the localized page based on normal browser detection at runtime.

@bzavhorodskyi
Copy link
Collaborator

bzavhorodskyi commented Oct 10, 2024

@Sporiff Yep, I've tried to filter but can't check everything.

Under middleware, I mean astro middleware in our src folder, but it's fine if it works for now

Approved(can't do this from review)

@Sporiff Sporiff merged commit 5e5c452 into main Oct 10, 2024
4 of 6 checks passed
@Sporiff Sporiff deleted the locale-folder-support branch October 10, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants