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
ellmetha opened this issue Nov 24, 2022 · 0 comments
Open

Add support for localized route paths #52

ellmetha opened this issue Nov 24, 2022 · 0 comments

Comments

@ellmetha
Copy link
Member

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.

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

No branches or pull requests

1 participant