Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Is Enterprise So You Might Internationalise* Your App

Rails Is Enterprise So You Might Internationalise* Your App

* Note the British spelling

David Celis

March 07, 2014
Tweet

More Decks by David Celis

Other Decks in Programming

Transcript

  1. <!-- GET /welcome?locale=es --> <h1>hola mundo</h1> <!-- Template --> <h1><%=t

    :greeting %></h1> <!-- GET /welcome --> <h1>hello world</h1>
  2. es: datetime: distance_in_words: n_seconds: one: "1 segundo" other: "%{count} segundos"

    n_minutes: one: "1 minuto" other: "%{count} minutos" n_hours: one: "1 hora" other: "%{count} horas" n_days: one: "1 día" other: "%{count} días" n_weeks: one: "1 semana" other: "%{count} semanas" n_months: one: "1 mes" other: "%{count} meses" n_years: one: "1 año" other: "%{count} años" en: datetime: distance_in_words: n_seconds: one: "1 second" other: "%{count} seconds" n_minutes: one: "1 minute" other: "%{count} minutes" n_hours: one: "1 hour" other: "%{count} hours" n_days: one: "1 day" other: "%{count} days" n_weeks: one: "1 week" other: "%{count} weeks" n_months: one: "1 month" other: "%{count} months" n_years: one: "1 year" other: "%{count} years"
  3. <!-- GET /countdowns/summer-2014?locale=es --> <h1>3 meses</h1> <!-- Template --> <h1><%=t

    'datetime.distance_in_words.n_months', count: 3 %></h1> <!-- GET /countdowns/summer-2014 --> <h1>3 months</h1>
  4. ActiveSupport::Inflector.inflections(:es) do |inflect| inflect.plural(/$/, 's') inflect.plural(/([^aeéiou])$/i, '\1es') inflect.plural(/([aeiou]s)$/i, '\1') inflect.plural(/z$/i,

    'ces') inflect.plural(/á([sn])$/i, 'a\1es') inflect.plural(/é([sn])$/i, 'e\1es') inflect.plural(/í([sn])$/i, 'i\1es') inflect.plural(/ó([sn])$/i, 'o\1es') inflect.plural(/ú([sn])$/i, 'u\1es') ! inflect.singular(/s$/, '') inflect.singular(/es$/, '') ! inflect.irregular('el', 'los') end
  5. ActiveSupport::Inflector.inflections(:es) do |inflect| inflect.plural(/$/, 's') inflect.plural(/([^aeéiou])$/i, '\1es') inflect.plural(/([aeiou]s)$/i, '\1') inflect.plural(/z$/i,

    'ces') inflect.plural(/á([sn])$/i, 'a\1es') inflect.plural(/é([sn])$/i, 'e\1es') inflect.plural(/í([sn])$/i, 'i\1es') inflect.plural(/ó([sn])$/i, 'o\1es') inflect.plural(/ú([sn])$/i, 'u\1es') ! inflect.singular(/s$/, '') inflect.singular(/es$/, '') ! inflect.irregular('el', 'los') end
  6. ActiveSupport::Inflector.inflections(:es) do |inflect| inflect.plural(/$/, 's') inflect.plural(/([^aeéiou])$/i, '\1es') inflect.plural(/([aeiou]s)$/i, '\1') inflect.plural(/z$/i,

    'ces') inflect.plural(/á([sn])$/i, 'a\1es') inflect.plural(/é([sn])$/i, 'e\1es') inflect.plural(/í([sn])$/i, 'i\1es') inflect.plural(/ó([sn])$/i, 'o\1es') inflect.plural(/ú([sn])$/i, 'u\1es') ! inflect.singular(/s$/, '') inflect.singular(/es$/, '') ! inflect.irregular('el', 'los') end
  7. en: datetime: second: 'second' minute: 'minute' hour: 'hour' day: 'day'

    week: 'week' month: 'month' year: 'year' es: datetime: second: 'segundo' minute: 'minuto' hour: 'hora' day: 'día' week: 'semana' month: 'mes' year: 'año'
  8. <!-- Template --> <p> <%= count %> <%= t('datetime.month').pluralize(count, I18n.locale)

    %> <p> <!-- GET /countdowns/summer-2014 --> <p>3 months</p>
  9. <!-- Template --> <p> <%= count %> <%= t('datetime.month').pluralize(count, I18n.locale)

    %> <p> <!-- GET /countdowns/summer-2014?locale=es --> <p>3 meses</p> <!-- GET /countdowns/summer-2014 --> <p>3 months</p>