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

What's the best way to deal with more complex locales like 'ch-fr'? #69

Open
gpluess opened this issue Jan 9, 2023 · 1 comment
Open
Labels
feature request New feature or request

Comments

@gpluess
Copy link

gpluess commented Jan 9, 2023

I have a requirement to include the locale AND the country in the URL like this:

/ch-fr/entreprises
/de-en/companies
/at-de/unternehmen

I am also going to have multiple countries with the same locale:

/ch-de/unternehmen
/de-de/unternehmen
/at-de/unternehmen

This basically works by setting the supported-locales config value to something like this:

'supported-locales' => [
  'ch-de', 'ch-fr', 'ch-it', 'ch-en',
  'de-de', 'de-en',
  'at-de', 'at-de',
],

However, I think this has some disadvantages, for example, now I have to have 3 versions for German in the lang directory and keep them in sync: ch-de, de-de and at-de. Having only one de directory no longer works. Other third party packages like spatie/laravel-translatable do not work well with this approach.

In order to avoid duplication, I would have proposed a syntax like this:

'supported-locales' => [
  'de' => [
    'ch-de',
    'de-de',
    'at-de',
  ],
  'en' =>  [
    'ch-en',
    'de-en',
    'at-en',
  ],
  'fr' =>  [
    'ch-fr',
  ],
],

But I guess this would break the domains/subdomains feature. So I'm wondering what's the best approach to deal with this?

Any suggestions are highly appreciated!

@ivanvermeyen
Copy link
Contributor

Hello,

That's an interesting idea.
It is like the recent PR #70 but instead of a single prefix/slug, you want multiple slugs.

Now, I've been thinking about this for a short while and found a few complications...
Mainly I think I need to figure out a new and better way to map all the locale parts together in a flexible, yet not to complicated way. Also related to #20 and #21, but those ideas are not fully worked out yet either.

A slug in the URL needs to be connected to a locale for route names and translations (a sort of internal locale).
But when you generate a route('some-route'), this also needs to know what slug to use. That is currently not possible if multiple are connected to a single internal locale. So I think the slugs might need to become the source of truth, the unique "key" when looking up locale configurations.

I still need to work this out further, but I will certainly include your suggestion in the final result.

@ivanvermeyen ivanvermeyen added the feature request New feature or request label Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants