-
Notifications
You must be signed in to change notification settings - Fork 143
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
Avoid duplicate routes in host locales #171
Comments
Is anybody using this version? |
Hi tagliala, I am using verson 5.5 to implement a custom locale identification, first based on url, if it is absent based on cookie, if it is absent based on browser language and based on domain at last. The rails app is serving two domains, domain.com and domain.com.br, and the locales en, pt-br and es. I've tried to implement the two domains with all languages using host_locales, but I couldn't do it because when I set I18n.default_locale = :'pt-BR' the gem doesn't gererate the route domain.com/pt-BR/something, on the other hand, setting I18n.default_locale = :en there is no route like domain.com.br/en/something. I think it is strange an url like this domain.com/empresas or domain.com.br/companies. There is no problem with es locale because the host_locales doesn't have an entry *.es, so the gem generates the routes domain.com/es/empresas and dmain.com.br/es/empresas. Is it suppose to be the right behavior ? Or I am doing something wrong. I can't upgrade to 6.0 because it has a completely different approach and will break my code. Is it possible to maint the current behavior in 6.0 ? Regards, |
Unfortunately the whole point of the 6.0 is that breaking change I would like to fix #87 and simplify the host locales feature for the basic use case (one domain per language). If there is a way to save locales without host, a PR would be appreciated Anyway, I could decide to not release 6.0 at all 🤷♂️ |
I guess the main point here is duplicated content and how to avoid it. Reading some google pages, Multi-regional and multilingual sites (https://support.google.com/webmasters/answer/182192?hl=en#3) and Use hreflang for language and regional URLs (https://support.google.com/webmasters/answer/189077) , I think we can have one domain and multiple languages since we provide an hreflang in the head with the prefered alternate language. This approach 5.5 version already has. So, one domain per language sure avoid content duplication, but forcing it when using host_locales I think limit to one use case. Please correct me if I am wrong, but using verify_host_path_consistency = true in version 5.5 avoid content duplication. In my use case, two domains and multiple languages, I am writing a custom code right now because a get the locale not only from host, take a look at this and, please, feel free to comment. I am skipping :set_locale_from_url and using do_check_locale instead:
Regards, |
This is a good workaround and that is what I was using to avoid penalties
Not entirely. It does not avoid both Using the current behavior for 6.0 would be possible by customizing the |
E.g.: /config/initializers/route_translator.rbRouteTranslator.config do |config|
# Do not set config.host_locales here, but you may want to hide or force locale
end /config/application.rbmodule MyApplication
class Application < Rails::Application
# ...
config.domain_language = {
'it.lvh.me' => :it,
'en.lvh.me' => :en,
'de.lvh.me' => :de
}
# ...
end
end /app/controllers/application_controller.rbclass ApplicationController < ActionController::Base
# ...
private
# Override Route Translator's method.
# Note that you may want some error management (eg: fallback on a default language)
def set_locale_from_url
I18n.with_locale(Rails.application.config.domain_language[request.host]) do
yield
end
end
# ...
end This will allow to use multiple languages for each host, with all the duplication. |
Thanks, I'll use custom solution with hreflang and redirects 301. |
@josefsj3m you're welcome. But it is not sure I'm going to release 6.0 at all. Things could change |
Yes, I know. What I am trying to do is a custom solution that is compliant with your development. I don't want to develop a route_translator from the ground, I have no time to do that. |
Fixes enriclluelles#91 and closes enriclluelles#171
The purpose of this refactor is to avoid duplicate routes. Previously, route_translator allowed duplicate routes `/cars` and `/en/cars` under the `en` domain when `host_locales` was set. Fixes enriclluelles#87 and fixes enriclluelles#171
Hi, please give a try to the new version of the gem, I've just released an alpha version.
Breaking changes are related to the Host-based Locale feature and Engine support:
verify_host_path_consistency
is a default and it cannot be disabled (Add verify_host_path_consistency option #167) (Issue with host-based locale and non-native routes #91)/route
and/en/route
on youren
domain) (Avoid generating duplicate routes? #87)In other words, you can use
host_locales
if you don't have a main domain likewww.example.com
and your subdomains have one language for each one it.example.com, es.example.com.If you have special needs (eg: main domain with all languages, subdomains with separate languages) please go for a custom solution.
The whole
native_path
stuff has been removed, each localized route only work for its own domain.Please use this thread to report issues and feedbacks
Having multiple languages for the same subdomain is out of the Route Translator's scope.
Anyway, there is a simple workaround to restore this feautre: #171 (comment)
The text was updated successfully, but these errors were encountered: