Skip to content

Instantly share code, notes, and snippets.

@haslinger
Last active December 31, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haslinger/7909337 to your computer and use it in GitHub Desktop.
Save haslinger/7909337 to your computer and use it in GitHub Desktop.
EnumStings in Hobo can be translated easily.

EmumStrings are an awesome feature of Hobo for a set of constants for select-options, that should be localized (gender, titles, types,...).

I didn't understand how to translate Hobo EnumStrings (I believe I saw other things on Hobocentral).

My thanks go to Iox, who helped me figure it out.

The most tricky part for me is the key: contentelement/markups: in the .yml file

  • The Model class is named ContentElement (so neither ContentElement nor content_elements is right here)
  • The attribute is named markup and it has to be pluralized.
  • The EnumString instance is named MarkupType but it is irrelevant for translation.
# I live in app/models/content_element.rb
class ContentElement < ActiveRecord::Base
hobo_model # Don't put anything above this
MarkupType = HoboFields::Types::EnumString.for("html", "markdown")
fields do
markup ContentElement::MarkupType
# more fields
timestamps
end
# other declarations
end
de:
# ...
activerecord:
# ...
attributes:
# ...
contentelement/markups:
html: "HTML-Seite"
markdown: "Markdown Seite"
# ...
Copy link

ghost commented Dec 11, 2013

+1, thanks for sharing :)

@iox
Copy link

iox commented Dec 12, 2013

Nice gist example Stefan. Just a small detail: the syntax for enumstring you used came from older Hobo versions. I think you could get the same result without using the MarkType constant:

class ContentElement < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    markup     enum_string(:html, :markdown)
  # more fields
    timestamps
  end

  # other declarations
end

Regards,
Ignacio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment