Work in progress - ALPHA (docs and code)
HyperI18n seamlessly brings Rails I18n into your Hyperstack application.
TODO these steps are wrong
- Add
gem 'hyper-i18n', git: 'https://github.com/ruby-Hyperstack/hyper-i18n.git'to yourGemfile - Install the Gem:
bundle install - Add
require 'hyper-i18n'to your components manifest
This gem is in it's very early stages, and only a handful of the API has been implemented. Contributions are very welcome!
Hyper-I18n brings in the standard ActiveSupport API.
The methods Model.model_name.human and Model.human_attribute_name are available:
# config/locales/models/en.yml
en:
activerecord:
models:
user: 'Customer'
attributes:
name: 'Name'User.model_name.human
# 'Customer'
User.human_attribute_name(:name)
# 'Name'Hyper-I18n makes available the method t to components, just as ActiveSupport does for views. It also implements the same lazy-loading pattern, so if you name space your locale file the same as your components, it will just work:
# config/locales/views/en.yml
en:
users:
show:
title: 'Customer View'module Users
class Show < Hyperstack::Component
render do
H1 { t(:title) }
end
end
end
# <h1>Customer View</h1>HyperI18n is fully compatible with server rendering! All translations are also sent to the client, so as to bypass fetching/rendering again on the client.