Giter VIP home page Giter VIP logo

Comments (2)

tagliala avatar tagliala commented on July 18, 2024

Hi,

this is caused by the following method:

def available_locales
locales = RouteTranslator.available_locales
# Make sure the default locale is translated in last place to avoid
# problems with wildcards when default locale is omitted in paths. The
# default routes will catch all paths like wildcard if it is translated first.
locales.delete I18n.default_locale
locales.push I18n.default_locale
end

This change was introduced in #28, but at the time it was not possible to configure available_locales specific to route translator

I understand that the current route translator behavior is not expected, but I'm afraid of the consequences of excluding the default locale from the available locales

I've tried to add

      locales = RouteTranslator.available_locales
+     return locales unless locales.include?(I18n.default_locale)
+

and there are two failing specs

Error:
TranslateRoutesTest#test_path_helper_arguments_fallback:
NoMethodError: undefined method `product_it_path' for module #<Module:0x0000000126c424e0>


bin/rails test /Users/geremia/dev/route_translator/test/routing_test.rb:543

Error:
TranslateRoutesTest#test_path_helper_arguments_fallback_with_hosts:
NoMethodError: undefined method `product_it_path' for module #<Module:0x00000001269efaa8>

bin/rails test /Users/geremia/dev/route_translator/test/routing_test.rb:559

The failure is due to the fact that if there isn't a default route, the system does not know how to build a route for something that should be legit.

In rails, if I do not put the default locale among available locales I have a got a I18n::InvalidLocale error when using I18n.t without arguments

Since I'm not using this gem in a production environment, a PR with proper tests and a brief analysis of the consequences of removing the default locale from available locales is welcomed

from route_translator.

cbillen avatar cbillen commented on July 18, 2024

Ok, thank you for the explanation

The simplest in my case is to set the default locale to en-US and config.force_locale = true

This then generates the expected routes

free_consultation_en_ca GET /en-CA/free-consultation(.:format) www/leads#consultation {:locale=>"en-CA"}
free_consultation_en_us GET /en-US/free-consultation(.:format) www/leads#consultation {:locale=>"en-US"}

However what it misses is the default route name

free_consultation_path() which could take a locale as a parameter

we're trying to migrate from routing-filter to this gem so we can have route translations as well

from route_translator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.