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

Ability to manually specify locale in SSR #29019

Open
demensky opened this issue Dec 3, 2024 · 4 comments
Open

Ability to manually specify locale in SSR #29019

demensky opened this issue Dec 3, 2024 · 4 comments
Labels
area: @angular/ssr feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature

Comments

@demensky
Copy link

demensky commented Dec 3, 2024

Description

There is no way to specify locale in AngularAppEngine#handle based on Accept-Language, Cookie, etc. The current implementation of AngularAppEngine chooses locale based on URL.

Describe the solution you'd like

Ability to specify an array of locales when calling handle:

 app.use('/**', (req, res, next) => {
   angularApp
-    .handle(req)
+    .handle(req, undefined, { locales: req.acceptsLanguages() })
     .then((response) =>
       response ? writeResponseToNodeResponse(response, res) : next(),
     )

As far as I understand, this will also require removing the locale prefix from <base href="…"/>.

Describe alternatives you've considered

No response

@alan-agius4
Copy link
Collaborator

It is not recommended to display application content based on the Cookie and Accept-Language headers while using the same URL. For more details, refer to Google's guidelines on managing multi-regional sites: Google's Multi-Regional Sites Documentation. Following this, I believe we should not add support for this, as it contradicts what's recommended.

However, an alternative feature could be implemented for cases where internationalization (i18n) is enabled. In this scenario, users can be redirected to their preferred language locale if no specific locale is included in the URL.

For example:

  • http://www.example.com/http://www.example.com/fr (if the user's preferred language is French).
  • http://www.example.com/http://www.example.com/en (if the user's preferred language is English).

@demensky
Copy link
Author

demensky commented Dec 3, 2024

@alan-agius4

This is relevant if the content is different in different locales. This is even stated in the link you provided:

If your site offers different content to users in different languages, countries, or regions, you can optimize Google Search results for your site.

Google recommends using different URLs for each language version of a page rather than using cookies or browser settings to adjust the content language on the page.

For example, I see different locales when I go to https://docs.google.com/, https://www.youtube.com/, https://translate.google.com/, etc. Even the link you provided opened in the locale that I use.

For example, in blogs, a link with a locale is quite relevant. But in admin panels, online stores, etc., this greatly interferes with users, because if they open a link from outside, we will show the UI not in the locale that is relevant for the user, but in the locale of the user who provided the link.

@alan-agius4
Copy link
Collaborator

This seems to be a rather specific use case, as Angular's build-time i18n generates separate files/routes for each locale, and these files are always located in different directories (including for client-side routing). This setup may not align well with your goal. Your use case might be better suited for runtime translations, where there are no separate resources nor route for each locale.

@alan-agius4 alan-agius4 added feature Issue that requests a new feature area: @angular/ssr and removed area: @angular/ssr feature Issue that requests a new feature labels Dec 11, 2024
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Dec 12, 2024
Copy link
Contributor

angular-robot bot commented Dec 12, 2024

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular/ssr feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

2 participants