Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Translating ruby OSS

Slides from my presentation for #parisrb on the 6th Feb 2012

  • Login to see the comments

Translating ruby OSS

  1. 1. TRANSLATING RUBY OSS Christopher Dell @tigrish
  2. 2. DISCLAIMER WOW!I cofounded this Try it, it’s awesome! http://www.localeapp.com
  3. 3. SOME TRANSLATED PROJECTS
  4. 4. SOME TRANSLATED PROJECTS Gems- rails- devise- will-paginate
  5. 5. SOME TRANSLATED PROJECTS Gems Apps- rails - ChiliProject- devise - Spree- will-paginate - LocomotiveCMS
  6. 6. SOME TRANSLATED PROJECTS Gems Apps CLIs- rails - ChiliProject - remarkable- devise - Spree -?- will-paginate - LocomotiveCMS
  7. 7. SOME TRANSLATED PROJECTS Gems Apps CLIs- rails - ChiliProject - remarkable- devise - Spree -?- will-paginate - LocomotiveCMS i18n gem
  8. 8. THE TERRIBLE TWO Terrance Phillip“the translator” “the programmer”
  9. 9. THE PROGRAMMER
  10. 10. THE PROGRAMMERis involved in internationalization
  11. 11. THE PROGRAMMERis involved in internationalization i18n
  12. 12. THE TRANSLATOR
  13. 13. THE TRANSLATOR is involved in localization
  14. 14. THE TRANSLATOR is involved in localization l10n
  15. 15. FIGHT!
  16. 16. heart will go on editionnot a real project celine-db
  17. 17. heart will go on editionnot a real project celine-db-i18n
  18. 18. What should our default language be?
  19. 19. What should our default language be? ...probably English
  20. 20.
  21. 21. ✔ ✔
  22. 22. ✔ ✔ ?
  23. 23. PROO00OOOOOT
  24. 24. All your base are belong to en-US
  25. 25. Colour ColourLocalisation Localization
  26. 26. Colour ColourLocalisation LocalizationJam Jelly
  27. 27. Colour ColourLocalisation LocalizationJam JellyJelly Jell-o
  28. 28. Colour Colour Localisation Localization Jam Jelly Jelly Jell-o06/02/2012 6th Feb 2012 2nd Jun 2012
  29. 29. LANGUAGES ≠LOCALES
  30. 30. Let’s use YAML for storage and distribution
  31. 31. Let’s use YAML for storage and distribution• Ruby std lib
  32. 32. Let’s use YAML for storage and distribution• Ruby std lib• Used by i18n’s Simple Backend
  33. 33. Let’s use YAML for storage and distribution• Ruby std lib• Used by i18n’s Simple Backend• Text file, simple structure
  34. 34. /lib/ruby/1.9.2/psych.rb:148:in `parse: couldnt parse YAML at line 182 column 9 (Psych::SyntaxError)
  35. 35. I18N-SPECgithub.com/tigrish/i18n-spec
  36. 36. I18N-SPEC github.com/tigrish/i18n-specdescribe "config/locales/en.yml" do it { should be_parseable } it { should have_valid_pluralization_keys } it { should have_one_top_level_namespace } it { should be_named_like_top_level_namespace } it { should_not have_legacy_interpolations }end
  37. 37. I18N-SPEC github.com/tigrish/i18n-specdescribe "config/locales/en.yml" do it { should be_parseable } it { should have_valid_pluralization_keys } it { should have_one_top_level_namespace } it { should be_named_like_top_level_namespace } it { should_not have_legacy_interpolations }endDir.glob(config/locales/*.yml) do |locale_file| describe "a locale file" do it_behaves_like a valid locale file, locale_file endend
  38. 38. I18N-SPECgithub.com/tigrish/i18n-spec
  39. 39. I18N-SPEC github.com/tigrish/i18n-specdescribe "config/locales/fr.yml" do it { should be_a_subset_of ‘config/locales/en.yml’ }end
  40. 40. I18N-SPEC github.com/tigrish/i18n-specdescribe "config/locales/fr.yml" do it { should be_a_subset_of ‘config/locales/en.yml’ }enddescribe "config/locales/fr.yml" do it { should be_a_complete_translation_of ‘config/locales/en.yml’ }end
  41. 41. There’s a grammar error !
  42. 42. There’s a grammar error ! In French, the phrase :“1.2 regards fataux” should be : “1.2 regard fatal”
  43. 43. <?= t(:regard_fatal, :count => 1.2) ?>
  44. 44. <?= t(:regard_fatal, :count => 1.2) ?>regard_fatal: one: 1 regard fatal other: %{count} regards fataux
  45. 45. <?= t(:regard_fatal, :count => 1.2) ?> WTF?regard_fatal: one: 1 regard fatal other: %{count} regards fataux
  46. 46. CLDRUnicode Common Locale Data Repository cldr.unicode.org
  47. 47. CLDRUnicode Common Locale Data Repository cldr.unicode.org • Dates, Times, Time Zones • Numbers, Currencies • Sorting • Languages, Countries • Pluralizations • Charsets, Collations • Transliterations
  48. 48. CLDR
  49. 49. CLDR
  50. 50. CLDRXML
  51. 51. CLDRXMLJava
  52. 52. RUBY-CLDRgithub.com/svenfuchs/ruby-cldr
  53. 53. data/fr/plurals.rb{ :fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n.between?(0, 2) && n != 2 :one : :other } } } }}
  54. 54. if n % 10 == 1 && n % 100 != 11 :oneelsif [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) :fewelsif n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) :manyelse :otherend
  55. 55. if n % 10 == 1 && n % 100 != 11 :oneelsif [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) :fewelsif n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) :manyelse :otherend0 : many 10 : many 20 : many 30 : many1 : one 11 : many 21 : one 30.5 : other2 : few 12 : many 22 : few3 : few 13 : many 23 : few4 : few 14 : many 24 : few5 : many 15 : many 25 : many6 : many 16 : many 26 : many7 : many 17 : many 27 : many8 : many 18 : many 28 : many9 : many 19 : many 29 : many
  56. 56. kittens: zero: Sorry, no kittens other: %{count} kittens
  57. 57. <? if kittens.size > 0 ?> <?= t :kittens,kittens: :count => kittens.size ?%> zero: Sorry, no kittens <? else ?> other: %{count} kittens <?= t :no_kittens ?%> <? end ?>
  58. 58. <? if kittens.size > 0 ?> <?= t :kittens,kittens: :count => kittens.size ?%> zero: Sorry, no kittens <? else ?> other: %{count} kittens <?= t :no_kittens ?%> <? end ?>kittens: one: One kitten other: %{count} kittens
  59. 59. <? if kittens.size > 0 ?> <?= t :kittens,kittens: :count => kittens.size ?%> zero: Sorry, no kittens <? else ?> other: %{count} kittens <?= t :no_kittens ?%> <? end ?>kittens: kittens: one: One kitten one: %{count} kitten other: %{count} kittens other: %{count} kittens
  60. 60. v1.0
  61. 61. v1.0celine-db-i18n
  62. 62. MANUAL
  63. 63. MANUAL✓ Only use what you need
  64. 64. MANUAL✓ Only use what you need✓ Good translation visibility
  65. 65. MANUAL✓ Only use what you need X Need to repeat for each additional locale✓ Good translation visibility
  66. 66. MANUAL✓ Only use what you need X Need to repeat for each additional locale✓ Good translation visibility X Need to repeat with each update
  67. 67. BUNDLER
  68. 68. BUNDLER✓ All locales included
  69. 69. BUNDLER✓ All locales included✓ Easy updates
  70. 70. BUNDLER✓ All locales included X Memory usage✓ Easy updates
  71. 71. BUNDLER✓ All locales included X Memory usage✓ Easy updates X Load path issues
  72. 72. LOCALE
  73. 73. LOCALE✓ Good translation visibility
  74. 74. LOCALE✓ Good translation visibility✓ Easy updates
  75. 75. LOCALE✓ Good translation visibility X Small selection of libraries✓ Easy updates
  76. 76. • locale : http://www.localeapp.com/• i18n : https://github.com/svenfuchs/i18n• rails-i18n : https://github.com/svenfuchs/rails-i18n• i18n-spec : https://github.com/tigrish/i18n-spec• cldr : http://cldr.unicode.org/• ruby-cldr : https://github.com/svenfuchs/ruby-cldr• devise-i18n : https://github.com/tigrish/devise-i18n• will-paginate-i18n : https://github.com/tigrish/will-paginate-i18n

×