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

Translation Markup Language

Translation Markup Language

Translation Markup Language and Universal Translation Memory

Avatar for Ian McDaniel

Ian McDaniel

February 20, 2016

Other Decks in Programming

Transcript

  1. What would an ideal solution look like? • Consistency •

    Adaptability • Contextualization • Agility
  2. <%= tml_source('common/navigation') do %> <ul> <li><%= tr('Home') %></li> <li><%= tr('Features')

    %></li> <li><%= tr('Languages') %></li> <li><%= tr('Pricing') %></li> <li><%= tr('Docs') %></li> </ul> <% end %> Sources are arbitrary groups of related strings Sources & String Grouping
  3. <%= trh(source: 'common/navigation') do %> <ul> <li>Home</li> <li>Features</li> <li>Languages</li> <li>Pricing</li>

    <li>Docs</li> </ul> <% end %> Translation Blocks Entire blocks can be translated without markup.
  4. <%= trh(source: 'common/navigation') do %> <nav> <ul> <li>You have <a

    href=’/messages’>unread messages</a></li> <li><a href=’/logout’>Logout</a></li> </ul> </nav> <% end %> Blocks
  5. labels: messages: one: You have 1 message other: You have

    {count} messages <%= t('labels.messages', {count: 5}) %> :rule => lambda { |n| n == 1 ? :one : :other } Pluralization in Rails using YAML English
  6. Pluralization in Rails using YAML Russian labels: messages: one: У

    вас есть 1 сообщение few: У вас есть {count} сообщения other: У вас есть {count} сообщений <%= t('labels.messages', {count: 5}) %> :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other }
  7. Pluralization in Rails using TML Russian Translation 'У вас есть

    {count || сообщение, сообщения, сообщений}' У вас есть сообщений
  8. Pluralization with TML translations: [ {label: “You have one message”,

    context: {count: {number: ‘one’}}, {label: “You have {count} message”, context: {count: {number: ‘other’}}, ] <%= tr('You have {count} messages', {count: 5}) %> Expanded Translations
  9. Pluralization with TML <%= tr('You have {count} messages', {count: 5})

    %> translations: [ {label: “У вас есть {count} сообщение”, context: {count: {number: ‘one’}}, {label: “У вас есть {count} сообщения”, context: {count: {number: ‘few’}}, {label: “У вас есть {count} сообщений”, context: {count: {number: ‘other’}}, ] translations: [ {label: “תחא העדוה ךל שי”, context: {count: {number: ‘one’}}, {label: “העדוה יתש ךל שי”, context: {count: {number: ‘two’}}, {label: “תועדוה {count} ךל שי”, context: {count: {number: ‘other’}}, ] Expanded Translations
  10. Numeric Rules Definition one: (&& (= 1 (mod @n 10))

    (!= 11 (mod @n 100))) few: (&& (in '2..4' (mod @n 10)) (not (in '12..14' (mod @n 100)))) other: (|| (= 0 (mod @n 10)) (in '5..9' (mod @n 10)) (in '11..14' (mod @n 100))) one: (= @n 1) other: (true)
  11. Contextualization by Gender tr('{user} uploaded {count || photo}', {user: user,

    count: 3}) user = {name: ‘Michael’, gender: ‘male’}
  12. Contextualization by Gender загрузил фотографии '{user || загрузил, загрузила} {count

    || фотографию, фотографии, фотографий}' Russian Translation user count
  13. Contextualization by Gender <%= tr('{user} uploaded {count || photo}', {user:

    user, count: 3}) %> '{user || загрузил, загрузила} {count || фотографию, фотографии, фотографий}' Simplified
  14. Contextualization by Gender <%= tr('{user} uploaded {count || photo}', {user:

    user, count: 3}) %> translations: [ {label: “{user} загрузил {count} фотографию”, context: {count: {number: ‘one’}, user: {gender: ‘male’}}, {label: “{user} загрузил {count} фотографии”, context: {count: {number: ‘few’}, user: {gender: ‘male’}}, {label: “{user} загрузил {count} фотографий”, context: {count: {number: ‘other’}, user: {gender: ‘male’}}, {label: “{user} загрузила {count} фотографию”, context: {count: {number: ‘one’}, user: {gender: ‘female’}}, {label: “{user} загрузила {count} фотографии”, context: {count: {number: ‘few’}, user: {gender: ‘female’}}, {label: “{user} загрузила {count} фотографий”, context: {count: {number: ‘other’}, user: {gender: ‘female’}} ] By Context
  15. {date} = ‘{month_name} {days}, {years}’ Dates English Date Format tr('{user}

    was born on {date}', {user: user, date: user.birthday.tr(:verbose)}) %B = {month_name} %d = {days} %Y = {years} verbose = ‘%B %d, %Y’ #July 4, 2002
  16. Dates Russian Date Format родился Июля “{user || родился, родилась}

    {date::gen}” ‘%d %B, %Y’ #4 Июль, 2002 {date} = ‘{days} {month_name}, {years}’
  17. tr('[link: {user}] completed [bold: {count || mile}] on {user |

    his, her} last run.',{ user: [user, :name], count: 3, link: {href: ‘/profile’} }) Mixing it all together
  18. Mixing it all together Russian Translation пробежал мили в своем

    последнем забеге '[link: {user}] {user | пробежал, пробежала} [bold: {count || милю, мили, миль}] в своем последнем забеге.'