Top Banner
Welcome to the Movember DRUG Meetup!!! Wifi Network: Neutron-Guest Wifi Password: welcome2u
31

Internationalization with Rails

Jul 05, 2015

Download

Internet

i18n for rails
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Internationalization with Rails

Welcome to the

Movember DRUG

Meetup!!!

Wifi Network: Neutron-Guest

Wifi Password: welcome2u

Page 2: Internationalization with Rails

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.

Page 3: Internationalization with Rails

I18n

Page 4: Internationalization with Rails
Page 5: Internationalization with Rails

Who can explain why

internationalization is

abbreviated as I18n?

Page 6: Internationalization with Rails

I N T E R N A T I O N A L I Z A T I O N

I 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 N

Page 7: Internationalization with Rails

What is

Internationalization?

Page 8: Internationalization with Rails

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.

Page 9: Internationalization with Rails

Why Use It?

Page 10: Internationalization with Rails

Why Use It?

Better UX

Makes your product or message more accessible

More customers == MOAR profits

For Translation… obviously

Page 11: Internationalization with Rails

All your static text is in one spot.

Easy to maintain and change

Keep code DRY

Organization

Why Use It?

Page 12: Internationalization with Rails

Let’s Get Started

Empezemos!

Page 13: Internationalization with Rails

Setting Up Your Translation File

/config/locale/en.yml

/config/locale/es.yml

Page 14: Internationalization with Rails

In Your Views…

views/home/_header.haml

Page 15: Internationalization with Rails

You can do more than just put

words or sentences in the

translation file…

Page 16: Internationalization with Rails

Nest translations for organization

config/locale/en.yml

views/home/_about

.html.haml

Page 17: Internationalization with Rails

You can change a photo based on

language

config/locale/en.yml

views/home/_header.haml

Page 18: Internationalization with Rails

and for spanish…

config/locale/es.yml

views/home/_header.haml

Page 19: Internationalization with Rails

You can put HTML inside

config/locale/en.yml

Page 20: Internationalization with Rails

Loop through a list

config/locale/en.yml views/about/_about.haml

Page 21: Internationalization with Rails

Interpolation

config/locale/es.yml

views/about/_about.haml

webpage

Page 22: Internationalization with Rails

Setting the Locale/

Language in your

Routes!

Page 23: Internationalization with Rails

By Sub Domainen.mysite.com

Does not work on Heroku without a domain.

A wild card SSL certificate is more expensive then a single domain certificate

Supports localization by country or by language

Cookies can be shared across all locales.

Setting locale in your routes

es.mysite.com peru.mysite.com

Cons

Pros

Page 24: Internationalization with Rails

By Top-Level Domain

Setting locale in your routes

mysite.com

Cons

Pros

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.

Supports localization by country.

mysite.pe mysite.ca

Page 25: Internationalization with Rails

By Paramsmysite.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

Setting locale in your routes

mysite.com?locale=es

Cons

Pros

Page 26: Internationalization with Rails

By Scoping Routesmysite.com/en/contact

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.

Setting locale in your routes

mysite.com/es

Pros

Page 27: Internationalization with Rails

How to setup scoped

routes ?

Page 28: Internationalization with Rails

Application.rb

config/application.rb

Page 29: Internationalization with Rails

Routes.rb

Optional language can be passed in

config/routes.rb

/admins/sign_in

/en/admins/sign_in

/es/admins/sign_in

Page 30: Internationalization with Rails

Links to change language

Page 31: Internationalization with Rails

Thank You!!