Posts

Showing posts with the label i18n

Sending an Email Confirmation Link with the Right Locale (with Devise)

(This post will be short.) I have followed Railscast to configure I18n for my app, but I soon realized the link included inside the confirmation emails (sent through Devise) would direct the use to the default locale/language (i.e. English) instead of the locale that the user is using. This is my fix: In the mailer template (in devise, it would be devise/mailer/confirmation_instructions.html.erb), just pass in the user locale in the rails url helper: 1 2 3 4 5 <% user_name = ( @user . full_name . empty?) ? @user . email : @user . full_name %> <p> <%= t( '.greeting' , recipient : user_name) %> </p> <p> <%= t( '.instruction' ) %> </p> <p> <%= link_to t( '.action' ), confirmation_url( @resource , confirmation_token: @token , locale : I18n . locale) %> </p> Done.

I18n Country & City Select Fields - Reconstructing Carmen-Rails from Scratch

Image
One would think that Country/City selection fields are something so common that someone must have created a simple method to implement it. That may true to a point, but it turns out the City-State gem only provides English names, while the Carmen-Rails gem   - despite having I18n support - due to its dependence on the Carmen gem(https://github.com/carmen-ruby/carmen) - is no longer actively maintained. So, there's a few ways to get a working I18n Country/City select field working. The simplest might be to unpack the Carmen-Rails gem, change it to support Rails 5 with this fix , then install it by telling the Gemfile to install from local file. I did that initially,  but that didn't feel exactly right. So, I decided to reinvent the wheel and write the code from scratch. Now there are other gems that return country/subregions information with I18n support, such as the Countries gem and the Cities gem . However, for the purpose of making select fields, I found these gems ret...