Replies: 10 comments 17 replies
-
Dope 🚀 |
Beta Was this translation helpful? Give feedback.
-
please ssi please |
Beta Was this translation helpful? Give feedback.
-
@9ssi7 thanks for the interesting suggestion. It would be good if your proposal could include a bit about how this would work with the existing i18n support. I don't think it would make sense to have a separate config file, for example. |
Beta Was this translation helpful? Give feedback.
-
@ascorbic Thank you for the feedback and for raising important integration questions! Here’s a detailed, technical clarification of the proposal, with examples and direct analogies to next-intl’s middleware. Config Location & Pattern
// astro.config.ts
import i18n from './i18n.config'; // Optional: only for very large configs
export default defineConfig({
site: 'https://example.com',
i18n: {
defaultLocale: 'en',
locales: ['en', 'tr'],
domains: {
tr: "https://example.com.tr",
en: "http://example.com",
},
pathnames: {
'/about-us': { en: '/about-us', tr: '/hakkimizda' },
'/profile': { en: '/profile', tr: '/profil' },
'/places/[slug]': { en: '/places/[slug]', tr: '/yerler/[slug]' }
},
// or: ...i18n // If config is imported from external file
}
}); The Core of the Solution: SSR Middleware
Expected Middleware Flow
flowchart TD
A[User visits a URL] --> B[Astro SSR Middleware]
B --> C[Detect locale]
C --> D{Path matches<br>localizedPath?}
D -- No --> E[Redirect to localizedPath]
D -- Yes --> F{Exists canonicalPath<br>in pages?}
F -- Yes --> G[Rewrite to canonicalPath]
G --> H[Render canonical content<br>URL stays localized]
F -- No --> I[Return 404 or continue normal]
Flowchart Example
File Structure Example
Dynamic Routes
Analogy: next-intl for Next.js
Why Framework-level Support?
Let me know if you'd like code samples, a reference implementation, or further technical details! |
Beta Was this translation helpful? Give feedback.
-
I definitely want a better story for translated paths in astro, no matter if it's in core or an integration. I think nuxt's API is pretty good (eg. |
Beta Was this translation helpful? Give feedback.
-
I am very glad for your warm approach. What do you think about getting a roadmap? |
Beta Was this translation helpful? Give feedback.
-
Great proposal! I really agree with everything that is written here. The biggest painpoint with native solution is duplication of logic. Adding any new language requires adding whole folder for this language and it starts to be unmaintainable really fast. Page should just look for specific translations in .json files and config should take care of routing. I am starting a new project with 2 languages but soon I will be adding 2-5 more. Thinking about the organization of this project for maintainability is quite a big headache |
Beta Was this translation helpful? Give feedback.
-
Thanks for this comprehensive proposal! While I appreciate the effort to bring pathname-based i18n routing to Astro, I'd like to suggest looking at next-international as an alternative inspiration rather than next-intl. Here's why I think next-international's approach might be better suited for Astro: 1. Simplicity First
2. Performance Benefits
3. Developer Experience
4. Practical Considerations
Alternative Suggestion:
The beauty of next-international is that it proves you can have excellent i18n without the complexity of pathname translation. For the majority of use cases, this simpler approach might actually be preferable. What do you think about keeping Astro's i18n routing closer to next-international's philosophy while offering pathname translation as an opt-in feature? (This is an excellent proposal—I truly hope it finds its way into Astro in one form or another.) |
Beta Was this translation helpful? Give feedback.
-
It would be absolutely amazing to have more native i18n features. At the moment, features such as hreflang or translated paths do require implementing a lot of custom code or an integration. Unfortunately (but understandably, i18n is very complex), the more comprehensive integrations that I know of (i18n for Astro and astro-i18next)are unmaintained. |
Beta Was this translation helpful? Give feedback.
-
The reason why localised paths weren't added as part of the core was that:
However, core now has the infrastructure to support such a feature. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Introduce a configurable i18n routing system to Astro, enabling developers to define language-specific pathnames for their routes—similar to how Next.js handles internationalized URLs. This would allow for clean, localized URLs (e.g.
/giris
instead of/auth
) mapped to the same page logic, improving both SEO and user experience.Background & Motivation
Currently, implementing internationalized routing in Astro requires significant custom logic, especially for projects that want localized URLs for each language (not just a locale prefix or domain).
Many web applications—especially those migrating from Next.js or targeting international audiences—need the ability to map paths like
/about-us
(en) and/hakkimizda
(tr) to the same content.Today, achieving this in Astro is complex and involves manual rewrites, redirects, and maintaining multiple routes for the same page. There is no “official” or ergonomic way to manage locale-specific pathnames.
Goals
/places/[slug]
→/yerler/[slug]
).Example
Developers could define the mapping either directly inside
astro.config.ts
in thei18n
section,or import an external config file if needed (for large mappings):
Astro would use this config to handle:
/giris/dogrula
) are mapped to the actual page logic (/auth/verify
)./yerler/istanbul
→/places/[slug]:istanbul
).Integration with Astro's i18n and Middleware
astro.config.ts
under the existingi18n
section, keeping everything unified.i18n.config.ts
file is optional and follows normal TypeScript/ESM patterns.How the Middleware Works
canonicalPath
) and which localized URL to show (localizedPath
)./places/[slug]
→/yerler/[slug]
).Example Middleware Flow
Directory Structure Example
Mermaid Flowchart
Why Framework-level Support Matters
Beta Was this translation helpful? Give feedback.
All reactions