trying to make sense of how /pt/ or /en/ gets inserted into links

38 views
Skip to first unread message

Mike M

unread,
Mar 2, 2017, 9:48:15 AM3/2/17
to Catarse Dev
hi catarse folks,

wondering if someone on here could help me make sense of how /pt/ or /en/ gets inserted into urls around the application

for instance, when I create a project from the /start page, i get dropped at www.catarse.me/en/projects/1/insights

i don't see this in the routing and while I expect it to be in the controllers, I can't seem to find it

i was looking for something that does a redirect and insert's the user's locale unless an alternative is provided which lead me to this method in the application.rb

# def set_locale
# return redirect_to url_for(locale: I18n.default_locale, only_path: true) unless is_locale_available?
# I18n.locale = params[:locale] || I18n.default_locale
# end

yet i have commented it out and links are still being inserted with locales

this creates problems in the JS app front end which seems brittle when URLs don't present exactly as they are expected to...

if you can help me understand the architecting of this, I would be very grateful

my understanding is that the following flow takes place
   a. user signs up and is by default assigned a locale of 'pt'
   b. but if the user visits a url w/ 'en' or 'es', the application servers the expected translation

ANOTHER EXAMPLE:

the logout link in the user menu is declared as:

        m(`a.alt-link[href='/logout']`,

from the template in the js app at ~/src/c/menu-profile.js

but the link generated by rails is https://www.citizensupported.org/en/logout which destroys the sessions and drops the user here: https://www.citizensupported.org/en

this seems to break the routing in the JS app and the user is looking at a broken page .

i'd like to understand the mechanics of the how these locales are being inserted into the routing

thanks!

mike








Reply all
Reply to author
Forward
0 new messages