DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
Internationalization with Rails
1. Welcome to the
Movember DRUG
Meetup!!!
Wifi Network: Neutron-Guest
Wifi Password: welcome2u
2. About me
My name is Katherine
Muedas.
I am from Peru.
Software developer - I love
ruby on rails.
Bachelor Degree in Business
Management.
Passion: Marketing, fashion
and coding.
Also, I love playing Ping Pong,
spending time with family and
traveling.
8. What is I18n?
The process of "internationalization" usually means
to abstract all strings and other locale specific bits
(such as date or currency formats) out of your
application. The process of "localization" means to
provide translations and localized formats for these
bits.
23. Setting locale in your routes
By Sub Domain
en.mysite.com
es.mysite.com peru.mysite.com
Cons
Does not work on Heroku without a domain.
A wild card SSL certificate is more expensive then a single domain certificate
Pros
Supports localization by country or by language
Cookies can be shared across all locales.
24. Setting locale in your routes
By Top-Level Domain
mysite.com
Cons
mysite.pe mysite.ca
Expensive and time consuming to buy many domains.
Cookies cannot be shared across multiple locales
Not a good option for localizing by language
Can not different languages for different countries.
Pros
Supports localization by country.
25. Setting locale in your routes
By Params
mysite.com?locale=en
Params get lost when redirecting
Bad for SEO
Quick to implement
Could be used to store locale
Info in a user cookie
mysite.com?locale=es
Cons
Pros
26. Setting locale in your routes
By Scoping Routes
mysite.com/en/contact
mysite.com/es
Pros
Easy to set up for hosting.
Locale is set in the url route so it will not get lost when you are
navigating to different pages.
The locale is in a better position based on a architectural
standpoint.
inside your rails project you have a english yml file
Inside your views you can use this translation by simply saying t and then whatever translation key you want to give the value for
To keep your translation organize you can nest the translations in different sections You can see here i have a header section, project section and about section and each of them have they own headline value so that means that in the view I can just call about.headline to get the headline of the about section.
To get this to work you need to have a translation key that ends with html so that means for different languages you can have difference html if you want it or need it
…this is even good to use even if you are not translating into diffrenten languages because it can help you clean up your html.
If you have text that have dynamic content in it you can use interpolation to pass the data to the translation file , in this case you want to tell the user the time in their language so you pass the time to the current time translation. You can see here when I am setting the time I use a “L” which is for setting localization which is use for changing time, dates and currentcy formats base on location.
if you click the link english, the param locale : en will be set and if you click the link spanish, the param locale : es will be set