heroku不能加载语言文件

Heroku似乎没有加载config/locales/pt.yml 。 (语言正确设置为pt

I18n在localhost上完美工作,但不在我的heroku服务器上 。
代码位于https://github.com/aneves/deficit-puzzle

本地主机:

 $ rails console Loading development environment (Rails 3.0.5) irb(main):001:0> I18n.t(:Edit) => "Editar" 

Heroku的:

 $ heroku console Ruby console for deficit-puzzle.heroku.com >> I18n.t(:Edit) => "translation missing: pt.Edit" 

可能的dups:

有我的问题的SO匹配,但那些是死的线程。 我不想在一个没有回答OP的话题上打开一个赏金,我宁愿有一个好的问题跟进。 而且,这些问题并没有准确地指出问题,所以答案错过了这一点。

  1. 一个没有回答,OP没有跟进评论;
  2. 另一个只有一个答案忽略了这一点,OP也没有跟上最后的评论。

奇怪的是,数据出现在I18n.backend像预期的,但不能单独使用I18n.t选择

这导致认识到,加载路径必须配置正确的Rails找到翻译文件,但它没有正确解析它们。

这导致了@ANeves发现 物料清单破坏了Heroku解析文件的能力, 导致修复了删除有问题的BOM。


维基百科在UTF-8上的BOM

Unicode标准确实允许使用UTF-8的BOM ,但不要求或推荐使用。 字节顺序在UTF-8中没有意义,所以在UTF-8中,BOM仅用于将文本流或文件标识为UTF-8。

许多Windows程序(包括Windows记事本)默认添加BOM到UTF-8文件。

如果将来的读者是红宝石1.9考虑阅读常见的编码问题 。

@亚历山大·温佐夫斯基(Alexz Wenzowski)把我送上正轨。

似乎字节顺序标记搞乱了Heroku加载的本地化文件…
当我将文件转换为没有BOM时,使用Notepad ++,一切都被修复了。

起初我只是想为我检查一下这个新东西,然后我注意到我一见钟情的东西:即使数据在那里,也是被破坏了。

 >> I18n.backend => #<I18n::Backend::Simple:0x7f74643e2f08 @skip_syntax_deprecation=false, @translations={:"\357\273\277# Sample localization file for English. Add mor e files in this directory for other locales. # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.\nen"=>{:Dest roy=>"Remove", :suspend=>"suspend", :confirm=>"Are you sure?", :Admin=>"Administration", :suspended=>"%{model} was successfully suspended.", :Back=>"B ack", :updated=>"%{model} was successfully updated.", :html_title=>"DeficitPuzzle", :to_frontpage=>"to frontpage", :approve=>"approve", :Show=>"Show", :to_admin=>"to administration", :theme=>{:n=>{:one=>"1 theme", :other=>"%{count} themes"}, :List=>"Listing themes", :New=>"New theme", :Destroy_perma nently=>"Permanently remove this theme", :Editing=>"Editing theme", :_=>"Theme"}, :Progress=>"Progress", :Proposals=>"Proposals", :approved=>"%{model} was successfully approved.", :activerecord=>nil, :save_errors=>{:one=>"1 error prohibited this item from being saved", :other=>"%{count} errors prohi bited this item from being saved"}, :proposal=>{:n=>{:one=>"1 proposal", :other=>"%{count} proposals"}, :List=>"Listing proposals", :New=>"New proposa l", :Impact=>"Impact", :Destroy_permanently=>"Permanently remove this proposal.", :Editing=>"Editing proposal", :Approved=>"Approved", :"Approved?"=>" Approved?", :_=>"Proposal", :Title=>"Title", :Description=>"Description"}, :helpers=>{:submit=>nil}, :created=>"%{model} was successfully created.", : Edit=>"Edit", :title=>"Deficit puzzle: you fix the budget"}, :pt=>{:Destroy=>"Remover", :suspend=>"suspender", :confirm=>"De certeza?", :Admin=>"Ad ministração", :suspended=>"%{model} foi suspendida com sucesso.", :Back=>"Atrás", :updated=>"%{model} foi actualizada com sucesso.", :html_title=>" DeficitPuzzle", :to_frontpage=>"ir para página principal", :approve=>"aprovar", :Show=>"Mostrar", :to_admin=>"ir para administração", :theme=>{:n=> {:one=>"1 tema", :other=>"%{count} temas"}, :List=>"Listando temas", :New=>"Novo tema", :Destroy_permanently=>"Remover este tema permanentemente.", :E diting=>"Editando tema", :_=>"Tema"}, :Progress=>"Progressão", :Proposals=>"Propostas", :approved=>"%{model} foi aprovada com sucesso.", :activerecor d=>{:attributes=>{:theme=>{:title=>"Título"}, :proposal=>{:impact=>"Impacto", :description=>"Descrição", :title=>"Título"}}, :models=>{:theme=>"Te ma", :proposal=>"Proposta"}}, :save_errors=>{:one=>"1 erro impediu este item de ser salvo", :other=>"%{count} erros impediram este item de ser salvo"} , :proposal=>{:n=>{:one=>"1 proposta", :other=>"%{count} propostas"}, :List=>"Listando propostas", :New=>"Nova proposta", :Impact=>"Impacto", :Destroy _permanently=>"Remover permanentemente esta proposta.", :Editing=>"Editando proposta", :Approved=>"Aprovada", :"Approved?"=>"Aprovada?", :_=>"Proposta ", :Title=>"Título", :Description=>"Descrição"}, :helpers=>{:submit=>{:update=>"Actualizar %{model}", :create=>"Criar %{model}"}}, :created=>"%{mod el} foi criada com sucesso.", :Edit=>"Editar", :title=>"Deficit puzzle: tu consertas o orçamento"}, :en=>{:support=>{:array=>{:words_connector=>", ", :two_words_connector=>" and ", :last_word_connector=>", and "}}, :number=>{:precision=>{:format=>{:delimiter=>""}}, :format=>{:separator=>".", :delim iter=>",", :precision=>3, :significant=>false, :strip_insignificant_zeros=>false}, :human=>{:storage_units=>{:units=>{:byte=>{:one=>"Byte", :other=>"B ytes"}, :kb=>"KB", :mb=>"MB", :gb=>"GB", :tb=>"TB"}, :format=>"%n %u"}, :format=>{:delimiter=>"", :precision=>3, :significant=>true, :strip_insignific ant_zeros=>true}, :decimal_units=>{:units=>{:million=>"Million", :unit=>"", :billion=>"Billion", :trillion=>"Trillion", :quadrillion=>"Quadrillion", : thousand=>"Thousand"}, :format=>"%n %u"}}, :percentage=>{:format=>{:delimiter=>""}}, :currency=>{:format=>{:separator=>".", :unit=>"$", :delimiter=>", ", :precision=>2, :significant=>false, :strip_insignificant_zeros=>false, :format=>"%u%n"}}}, :datetime=>{:distance_in_words=>{:about_x_hours=>{:one=> "about 1 hour", :other=>"about %{count} hours"}, :about_x_years=>{:one=>"about 1 year", :other=>"about %{count} years"}, :x_days=>{:one=>"1 day", :oth er=>"%{count} days"}, :over_x_years=>{:one=>"over 1 year", :other=>"over %{count} years"}, :less_than_x_minutes=>{:one=>"less than a minute", :other=> "less than %{count} minutes"}, :about_x_months=>{:one=>"about 1 month", :other=>"about %{count} months"}, :x_minutes=>{:one=>"1 minute", :other=>"%{co unt} minutes"}, :almost_x_years=>{:one=>"almost 1 year", :other=>"almost %{count} years"}, :x_months=>{:one=>"1 month", :other=>"%{count} months"}, :l ess_than_x_seconds=>{:one=>"less than 1 second", :other=>"less than %{count} seconds"}, :half_a_minute=>"half a minute", :x_seconds=>{:one=>"1 second" , :other=>"%{count} seconds"}}, :prompts=>{:day=>"Day", :minute=>"Minute", :month=>"Month", :year=>"Year", :hour=>"Hour", :second=>"Seconds"}}, :time= >{:formats=>{:default=>"%a, %d %b %Y %H:%M:%S %z", :short=>"%d %b %H:%M", :long=>"%B %d, %Y %H:%M"}, :pm=>"pm", :am=>"am"}, :date=>{:formats=>{:defaul t=>"%Y-%m-%d", :short=>"%b %d", :long=>"%B %d, %Y"}, :abbr_day_names=>["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], :order=>[:year, :month, :day] , :day_names=>["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], :abbr_month_names=>[nil, "Jan", "Feb", "Mar", "Apr", "Ma y", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], :month_names=>[nil, "January", "February", "March", "April", "May", "June", "July", "August", "S eptember", "October", "November", "December"]}, :errors=>{:format=>"%{attribute} %{message}", :messages=>{:even=>"must be even", :confirmation=>"doesn 't match confirmation", :greater_than_or_equal_to=>"must be greater than or equal to %{count}", :accepted=>"must be accepted", :equal_to=>"must be equ al to %{count}", :not_an_integer=>"must be an integer", :empty=>"can't be empty", :wrong_length=>"is the wrong length (should be %{count} characters)" , :less_than=>"must be less than %{count}", :blank=>"can't be blank", :too_short=>"is too short (minimum is %{count} characters)", :exclusion=>"is res erved", :inclusion=>"is not included in the list", :less_than_or_equal_to=>"must be less than or equal to %{count}", :not_a_number=>"is not a number", :too_long=>"is too long (maximum is %{count} characters)", :invalid=>"is invalid", :odd=>"must be odd", :greater_than=>"must be greater than %{count} "}}, :activerecord=>{:errors=>{:messages=>{:record_invalid=>"Validation failed: %{errors}", :taken=>"has already been taken"}}}, :helpers=>{:submit=>{ :submit=>"Save %{model}", :update=>"Update %{model}", :create=>"Create %{model}"}, :select=>{:prompt=>"Please select"}}}}, @initialized=true> 

这个问题似乎并不是Heroku特有的,并且会在任何与Ruby / i18n混合的Windows / UNIX上发生。

写这一行也将解决您的application.rb中的问题

 config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 

我遇到了类似的问题,但我的重复键是由于。

在一个文件中,我们定义了这个:

 en: dashboard: "Dashboard" 

而另一个我们定义

 en: dashboard: title: "Some Title" 

在本地, I18n.t("dashboard.title")工作得很好,但在生产上没有。 原因可能是由于Heroku和我的开发机器之间的加载顺序不同。

我通过更改第一个dashboard键的名称来修复它,所以不再有重叠。