Notes on Programming in Japanese

Created at: 22 Mar 2024 Last updated: 22 Apr 2024

Here are some notes I think anyone who is programming in Japan may find useful, they (will) span across the full stack. At the time of posting this is a very small post, but this will be an ongoing project. I'll update it as I come back to issues again and again.

  • Because Japanese has so many characters using hefty webfonts can significantly slow down your application. A good webfont, like Google Noto Sans CJK, has 65,535 glyphs! So,
    • In general I recommend this old Stackoverflow post. But, here are two more links to useful articles on the topic: 1, 2.
    • There are of course exceptions for stylistic design choices, and I've found Adobe Fonts are not so bad, they have an option for lazy/selective loading.

  • For testing in a Ruby on Rails app: FFaker is better than Faker for dummy Japanese database input. This is an obscure reference, but it's just better. There's no additional setup, and to call a method with Japanese, it has it's own subclass, like: FFaker::AddressJA.method. It's a no brainer if you're using Rspec and FactoryBot.

  • Β Namespaced i18n (example is a polymorphic namedspaced model)
    • # ja.yml
      ja:
        activerecord:
          attributes:
            namespace/address:
              name: "名前"
              company: "会瀾名"
              address1: "町名・η•ͺ地"
              address2: "建物名・部屋η•ͺ号"
      
      # some_view.html.erb
      <%= form.fields_for :addresses, address do |address_fields| %>
        <%= address_fields.label :name %>
        <%= address_fields.text_field :name, class: 'form-control form-control-sm', value: address.name, placeholder: '名前' %>

Back