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 localized route paths #52

Open
1 of 4 tasks
ellmetha opened this issue Nov 24, 2022 · 3 comments
Open
1 of 4 tasks

Add support for localized route paths #52

ellmetha opened this issue Nov 24, 2022 · 3 comments
Assignees
Milestone

Comments

@ellmetha
Copy link
Member

ellmetha commented Nov 24, 2022

Description

The framework should let users easily configure localized routes. There are two types of localized routes to consider:

  1. localized routes whose paths are translated (eg. /cars and /voitures)
  2. localized routes whose paths are translated and that are prefixed by the current locale (eg. /en/cars and /fr/voitures)

In order to let users define such routes, let's add the ability to leverage a #localized block when defining routes. For example:

Marten.routes.draw do
  localized(prefix: true) do
    path "routes.article_list", ArticleListHandler, name: "article_list"
    path "routes.article_detail", ArticleDetailHandler, name: "article_detail"
    path "routes.my_app", MyApp::ROUTES, name: "my_app"
  end
end

This method should accept the following arguments:

  • prefix - whether or not a locale prefix (eg. /en/ or /fr/ depending on the activated locales) should be used for the generated routes (should default to false)
  • prefix_default_locale - whether or not the default locale should be prefixed when prefix: true is used

Using #localized would instruct the routing map that the wrapped path must be localized and that their actual "paths" must be treated as localization paths. For example, the associated translations could look like this:

en:
  routes:
    article_list: /articles
    article_detail: /articles/<pk:int>
    my_app: /my-app

When generating the full URL of localized routes, the associated translations should be used in order to generate the localized URL and (optionally) prefix it with the current locale.

Implementation

  • Make it possible to define translated route paths.
  • Make it possible to define route paths prefixed with locales.
  • Make sure that the I18n middleware can activate specific locales when locale route prefixes are used.
  • Document these new capabilities in the routing documentation section.
@kates
Copy link
Contributor

kates commented Jun 3, 2024

@ellmetha I've started some work on this. I needed a few clarifications.

  • Accept-Language vs localized route - when Accept-Language is fr but localized route is /de/post/1, what will the content be translated into? My guess is to follow the de but just in case my assumptions are wrong.

@ellmetha
Copy link
Member Author

ellmetha commented Jun 7, 2024

@kates Thanks for looking into that! To answer your question, the language extracted from the route path should always have precedence.

@ellmetha ellmetha added this to the v0.6.0 milestone Jul 11, 2024
@kates
Copy link
Contributor

kates commented Aug 15, 2024

@ellmetha Hey, sorry, I wasn't able to finish the work. I've been moved to a Go language in my work. BTW, what seem to be a simple setting of locale context is now an exercise in dealing with reverse path lookup.

@ellmetha ellmetha self-assigned this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants