我已下载丹麦语语言环境(da.yml)并将其放入config / locales
我收到此错误:无法在第20行第14列解析YAML
与Rails 3 simple form error : couldn't parse YAML
的简单形式相同,这是一个错误我的application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module App
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :da
# JavaScript files you want as :defaults (application.js is always included).
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
end
end
我的观点文件:
<% @konkurrancer.each do |vind| %>
<tr onclick="window.open('<%= vind.tracking %>')"
<td><%= vind.udtraekkes.strftime("%d %B") %></td>
</tr>
<% end %>
以下时出错:
C:\Rails\app>rails console
Loading development environment (Rails 3.0.3)
irb(main):001:0> I18n.l Time.now, :format => :short
Psych::SyntaxError: couldn't parse YAML at line 0 column 0
from C:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse'
from C:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from C:/Ruby192/lib/ruby/1.9.1/psych.rb:119:in `parse'
from C:/Ruby192/lib/ruby/1.9.1/psych.rb:106:in `load'
from C:/Ruby192/lib/ruby/1.9.1/psych.rb:205:in `load_file'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:170:in `load_yml'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:156:in `load_file'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:15:in `block in load_translations'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:15:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:15:in `load_translations'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/sim
ple.rb:55:in `init_translations'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/sim
ple.rb:69:in `lookup'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:26:in `translate'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n.rb:155:in `
translate'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n/backend/bas
e.rb:55:in `localize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/i18n-0.5.0/lib/i18n.rb:235:in `
localize'
from (irb):1
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds/console.rb:44:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds/console.rb:8:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):002:0>
但我在视图中的日期名称不会改变。 我的丹麦语语言环境文件http://pastie.org/1651134
答案 0 :(得分:1)
您需要使用l
翻译助手来表示日期,而不是使用strftime(请参阅here)。
所以如果你的语言环境中有这个:
da:
time:
formats:
short: "arrrround %H"
然后在您看来,您将使用:
<%= l vind.udtraekkes, :format => :short %>