Link Search Menu Expand Document

Translations (experimental)

To use experimental support for I18n translations, include ViewComponent::Translatable:

# app/components/example_component.rb
module ExampleComponent < ApplicationComponent
  include ViewComponent::Translatable

Add a sidecar YAML file with translations for the component:

# app/components/example_component.yml
  hello: "Hello world!"

Access component-local translations with a leading dot:

<%# app/components/example_component.html.erb %>
<%= t(".hello") %>

Global Rails translations are available as well:

<%# app/components/example_component.html.erb %>
<%= t("") %>

Global translations shadowed by sidecar translations can be accessed with helpers or I18n:

<%# app/components/example_component.html.erb %>
<%= helpers.t("hello") %>
<%= I18n.t("hello") %>