我是使用ruby和中间商的新手,我已经创建了我的项目,而且都很好,但是当我去/es路径时,我没有得到任何翻译。我在没有任何结果的情况下搜索信息,并试图在文件夹、测试、信任和任何东西之间移动代码。
我的文件夹结构是:
|locales
|---en.yml
|---es.yml
|source
|es
|---index.html.haml
|layouts
|---layout.html.haml
|partials
|_header.html.haml
|_navigation.html.haml
|---index.html.haml我的YAML文件
en.yml
en:
home: 'Home'es.yml
es:
home: 'Inicio'我的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/'}"我的配置
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发布于 2016-02-08 10:12:43
我不能写评论,但我认为这可能是你的es.yml错误的原因,因为它开始于en:
en:
home: 'Inicio'不是应该吗
es:
home: 'Inicio'发布于 2016-08-22 06:33:36
我知道这个问题已经存在了几个月,但我只是遇到了同样的问题,我在网上搜索了几个小时,试图找到并回答这个问题,并在激活i18n之后添加了这些参数来解决这个问题。
config.rb
configure :build do
activate :i18n,
:mount_at_root => 'en',
:lang_map => { :'en' => 'en', :'es' => 'es' },
:path => '/'
end显然,如果您希望"es"成为您的默认值,请更改mount_at_root。
希望这能有所帮助。
发布于 2017-01-26 20:31:07
我通过以下方式实现了英文和西班牙文的本地化路径
在源目录根目录中添加index.es.html.erb
并设置activate :i18n,:path =>“/:locale/”config.rb中的
在浏览器中,我的语言选择器将用户发送到/或/es。
英语
http://website.com/西班牙语
http://website.com/es文件夹结构
|data
|---home.json
|locales
|---en.yml
|---es.yml
|source
|---index.html.erb
|---index.es.html.erb
|---_slide.erb
|---config.rbconfig.rb
configure :build do
activate :i18n, :path => "/:locale/"
activate :directory_indexes
...
endslide.erb
使用t作为I18n.t的快捷方式,通过数据动态引用转换的值。
<%= link_to t([data.link.text]),
data.link.href,
:id => data.link.id,
:class => 'btn btn-primary btn-lg btn-dark'
%>home.json
"text“的值与.yml文件中的键相关。
{
"slides": [
{
"text": "slides.learnMore",
...
},
...
]
}en.yml
en:
slides:
learnMore: "LEARN MORE"
...es.yml
es:
slides:
learnMore: "APRENDE MÁS"
...https://stackoverflow.com/questions/35102134
复制相似问题