Vagrant comes setup with the Ruby I18n (internationalization) library, which allows you to store all your strings in a YAML file. While it’s not required, there are many benefits to this:
Again, it’s completely optional, but using it is so easy that is recommended.
First, define your translations in a file, which I typically name en.yml
(since it’s for the en
locale). It looks like this:
en:
vagrant:
plugins:
my_plugin:
hello: "Hello, %{name}!"
Once that is defined, you have to add that file to the I18n load path:
I18n.load_path << "/path/to/my/en.yml"
Then, once it’s adding, you can use your translations anywhere you’d like:
I18n.t("vagrant.plugins.my_plugin.hello", :name => "Mitchell")
The second parameter is an optional hash of interpolation variables, which are interpolated into the translation. The %{name}
is replaced with the name
interpolation variable. If you don’t have any variables to interpolate, you can just omit the parameter.