0

I'm newbie using ruby and middleman, I've created my project and all are working fine, but when I go to /es path I don't get any translation. I've searched for info without any results and tried to move code between folders testing configs and nothing.

My folder structure is:

|locales
  |---en.yml
  |---es.yml
|source
  |es
    |---index.html.haml
  |layouts
    |---layout.html.haml
  |partials
    |_header.html.haml
    |_navigation.html.haml
  |---index.html.haml

My YAML files

en.yml

en:
  home: 'Home'

es.yml

es:
  home: 'Inicio'

My HAML

%nav
   = link_to t(:home), '/', class: "#{'active' if current_page.url == '/'}"
   = link_to 'Portfolio', '/portfolio', class: "#{'active' if current_page.url == '/portfolio/'}"
   = link_to t(:skills), '/skills', class: "#{'active' if current_page.url == '/skills/'}"
   = link_to t(:about), '/about', class: "#{'active' if current_page.url == '/about/'}"
   = link_to t(:contact), '/contact', class: "#{'active' if current_page.url == '/contact/'}"

My config

config.rb

###
# Page options, layouts, aliases and proxies
###

# Per-page layout changes:
#
# With no layout
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false

# With alternative layout
# page "/path/to/file.html", layout: :otherlayout

# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", locals: {
#  which_fake_page: "Rendering a fake page with a local variable" }

# General configuration
set :partials_dir, 'partials'
activate :i18n, :templates_dir => 'partials'
activate :directory_indexes

# Reload the browser automatically whenever files change
configure :development do
  activate :livereload
end

###
# Helpers
###

# Methods defined in the helpers block are available in templates
# helpers do
#   def some_helper
#     "Helping"
#   end
# end

# Build-specific configuration
configure :build do
  # Minify CSS on build
  activate :minify_css

  # Minify Javascript on build
  activate :minify_javascript
end

4 Answers4

0

I couldn't write a comment, but I think this might be the reason, your es.yml is wrong, since it starts en:

 en:
    home: 'Inicio'

Shouldn't it be

 es:
    home: 'Inicio'
vickzzzzz
  • 33
  • 9
0

I know this question is months old but I just had the same problem, looked all over the web for hours trying to find and answer and managed to fix the issue by adding these parameters after activating i18n:

config.rb

configure :build do
   activate :i18n,
      :mount_at_root => 'en',
      :lang_map => { :'en' => 'en', :'es' => 'es' },
      :path => '/'
end

Obviously, if you want "es" to be your default, change mount_at_root.

Hope this helps.

CosmicDrawers
  • 43
  • 2
  • 5
0

I achieved localized paths with separate URLs for English and Spanish by
adding index.es.html.erb in the root of the source directory
and setting activate :i18n, :path => "/:locale/" in the config.rb

In the browser, my language selector sends users to / or /es:

English

http://website.com/

Spanish

http://website.com/es

Folder structure

|data
  |---home.json
|locales
  |---en.yml
  |---es.yml
|source
  |---index.html.erb
  |---index.es.html.erb
  |---_slide.erb
|---config.rb

config.rb

configure :build do
  activate :i18n, :path => "/:locale/"
  activate :directory_indexes
  ...
end

slide.erb
Using t as a shortcut for I18n.t, I dynamically reference the translated value through the data.

<%= link_to t([data.link.text]),
    data.link.href,
    :id => data.link.id,
    :class => 'btn btn-primary btn-lg btn-dark'
%>

home.json
The value of "text" correlates to the key in the .yml files.

{
  "slides": [
    {
      "text": "slides.learnMore",
      ...
    },
    ...
  ]
}

en.yml

en:
  slides:
    learnMore: "LEARN MORE"
    ...

es.yml

es:
  slides:
    learnMore: "APRENDE MÁS"
    ...
Alan Mabry
  • 167
  • 1
  • 5
0

Move all your .erb.html that require to be duplicated per language to the folder: /source/localizable as explained in the docs:

You can change this folder name using the modifier: templates_dir:

# Look in `source/language_specific` instead
activate :i18n, :templates_dir => "language_specific"
fguillen
  • 36,125
  • 23
  • 149
  • 210