RAILS + REACTの実際のサービスでの国際化の話

RAILS + REACTの実際のサービスでの国際化の話

B333ca927c03d107c01641f3716ea744?s=128

Hiroyuki Shirakawa

June 08, 2017
Tweet

Transcript

  1. RAILS + REACT shrkw Meguro.rb#3 2017/05/24(Wed)

  2. Viibar Java, Scala, Python Viibar Ruby/Rails

  3. 4K

  4. Viibar 35 4K

  5. None
  6. I18N

  7. Rails i18n Rails (I18n) API | Rails svenfuchs/rails-i18n

  8. JS (ES2015, React) I18n.locale

  9. JS (ES2015, REACT)

  10. React React yahoo/react-intl i18next/react-i18next i18next

  11. JS fnando/i18n-js

  12. I18N-JS Rails JSON React

  13. export_i18n_js: false fallbacks: true translations: - file: "app/assets/javascripts/locales/%{locale}.js" only: -

    '*.js.*'
  14. locales ja: js: foo: bar: baz

  15. REACT i18n-js translations layout //= require i18n = javascript_include_tag "locales/#{I18n.default_locale}"

    - unless I18n.locale == I18n.default_locale = javascript_include_tag "locales/#{I18n.locale}"
  16. React ES2015 I18n.js global.I18n export default global.I18n;

  17. ES2015 i18n

  18. render() { return <div>{I18n.t('js.submit.close')}</div>; }

  19. JSON PRECOMPILE locale json config.middleware.use I18n::JS::Middleware if Rails.env.development?

  20. production assets:precompile sprockets task 'assets:precompile': 'i18n:js:export'

  21. None
  22. None
  23. ja en MissingTranslationData

  24. glebm/i18n-tasks

  25. unused, add-missing, find, remove-unused, normalize, mv missing unused JS

  26. unused #i18n-tasks-use t('activerecord.models.user') # let i18n-tasks know the User.model_name.human

  27. spec CI

  28. it '各locale.yml translation 欠落 ' do count = i18n.missing_keys.count unless

    count.zero? missing_list = "以下 locale 未設定 \n" i18n.missing_keys.each do |locale| locale.keys.each do |key| missing_list << "#{locale.key} | #{key}\n" end end fail missing_list end end
  29. None
  30. None
  31. locales YAML JS YAML

  32. YAML ja: # 両方 利用 設定 isomorphic: attributes: car: &isomorphic_attributes_car

    tire: # activerecord: attributes: car: <<: *isomorphic_attributes_car loof: 天井 # js: attributes: car:
  33. JSON

  34. I18N.LOCALE

  35. HTTP Accept-Language

  36. before_action :set_locale def set_locale I18n.locale = extract_locale_from_accept_language_header end def extract_locale_from_accept_language_header

    request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]\{2\}/).first end
  37. application_controller

  38. : DEVISE Devise::SessionsController flash application_controller class Devise::SessionsController < DeviseController prepend_before_action

    :require_no_authentication, only: [:new, prepend_before_action :allow_params_authentication!, only: :create prepend_before_action :verify_signed_out_user, only: :destroy if authenticated && resource = warden.user(resource_name) flash[:alert] = I18n.t("devise.failure.already_authenticated") redirect_to after_sign_in_path_for(resource) end
  39. rails_admin application_controller#set_locale

  40. Rack rack-contrib/locale.rb at master · rack/rack-contrib · GitHub

  41. DB

  42. DB

  43. None