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

[BalkanRuby 2019] Getting ready for I18n, Shopi...

[BalkanRuby 2019] Getting ready for I18n, Shopify case study

Avatar for Edouard Chin

Edouard Chin

May 17, 2019
Tweet

More Decks by Edouard Chin

Other Decks in Programming

Transcript

  1. Main location of hard-coded strings • HTML / ERB (Views)

    • Ruby (Helpers, Controllers) • Javascript
  2. Detect hard-coded strings visible by the user def my_endpoint if

    params['something'] render(plain: 'Hello World!') end end
  3. # @example # # bad # {a:3} # # #

    good # {a: 3} class SpaceAfterColon < Cop MSG = 'Space missing after colon.' def on_pair(node) return unless node.colon? colon = node.loc.operator add_offense(…) end # ... end
  4. ui_layout do |row| ui_data_table do |table| table.header do |section| section.row

    do |row| row.header('Hello') end row.header('data') end end end Nested blocks
  5. class UIRadioButtonHelper < Cop include BlockOutputHelperBehavior UI_HELPER_NAMES = { form_for:

    :ui_radio_button } def forbidden_kwarg?(kwarg) %w(label help_text).include?(kwarg) end def argument_check_required?(index) index > 0 end end
  6. def_node_matcher :ui_block_helper, <<-PATTERN (block { (send nil? #ui_helper_method_names ...) (send

    (lvar _) #ui_helper_method_names) } (args (arg $_)) $(...)) PATTERN RuboCop NodePattern https://rubocop.readthedocs.io/en/latest/node_pattern/
  7. en: path: to: file: my_l: 'My Link %{here}’ link_to("My Link

    #{here}", _) link_to(I18n.t('path.to.file.my_l', here: here), _)
  8. " #

  9. " %

  10. … name: 'United States' week_start_day: 'sunday' format: edit: "{firstName}{lastName}_{company}_{address1} _{address2}_{city}_{country}{province}{zip}_{phone}"

    show: "{firstName} {lastName}_{company}_{address1} _{address2}_{city} {province} {zip}_{country}_{phone}"
  11. const address = { company: 'Shopify', firstName: '恵⼦子', lastName: '⽥田中',

    address1: '⼋八重洲1-5-3', address2: '', city: '⽬目黒区', province: 'JP-13', zip: '100-8994', country: 'JP', phone: '', }; const addressFormatter = new AddressFormatter('ja'); await addressFormatter.format(address); /* => ⽇日本 〒100-8994東京都⽬目黒区⼋八重洲1-5-3 Shopify ⽥田中恵⼦子様 */