Hyperstack
  • Welcome
  • Rails Installation and Configuration
    • Prerequisites
    • Using the Hyperstack Installer
    • Using the Generators
    • File Structure
    • Routing and Mounting Components
    • Other Rails Configuration Details
    • Why Rails? Other Frameworks?
  • HyperComponent
    • Component Classes
    • HTML Tags & CSS Classes
    • Component Children, Keys and Fragments
    • Component Params
    • Lifecycle Methods
    • Component State
    • Events and Callbacks
    • Interlude: Tic Tac Toe
    • Recovering from Errors
    • JavaScript Components
    • Elements and Rendering
    • Summary of Methods
    • List of Predefined Tags & Components
    • Predefined Events
    • Notes
    • Further Reading
  • HyperState
  • HyperRouter
  • HyperModel
  • Operations
  • Policies
  • Internationalization
  • Development Tools, Workflow and Procedures
    • Debugging
    • HyperTrace
    • HyperSpec
      • Installation
      • Tutorial
      • Methods and Features
      • Using with Rack
    • Deploy To Heroku
  • Tutorial
    • TodoMVC Tutorial Part I
    • TodoMVC Tutorial Part II
  • Community
Powered by GitBook
On this page
  • This Page Under Construction
  • Installation and Setup
  • Usage
  • Server Rendering

Was this helpful?

Internationalization

PreviousPoliciesNextDevelopment Tools, Workflow and Procedures

Last updated 4 years ago

Was this helpful?

HyperI18n seamlessly brings Rails I18n into your Hyperstack application.

This Page Under Construction

Installation and Setup

TODO these steps are wrong

  1. Add gem 'hyper-i18n', git: 'https://github.com/ruby-Hyperstack/hyper-i18n.git' to your Gemfile

  2. Install the Gem: bundle install

  3. Add require 'hyper-i18n' to your components manifest

Usage

Hyper-I18n brings in the standard ActiveSupport API.

ActiveRecord Models

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'

Views

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>

Server Rendering

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.