【问题标题】:heroku not loading language fileheroku没有加载语言文件
【发布时间】:2011-10-23 18:45:56
【问题描述】:

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

I18n 在 localhost 上运行良好,但在 my heroku server 上却不行。
代码在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"

可能的重复:

我的问题有一些匹配项,但这些都是死线程。我不想在其 OP 未回答 cmets 的线程上打开赏金,我宁愿有一个很好的问题和良好的跟进。此外,问题并没有准确地指出问题所在,因此,答案没有抓住重点。

  1. One没有答案,OP没有跟进cmets;
  2. Another 只有一个没有抓住重点的答案,OP 也没有跟进最后的评论。

【问题讨论】:

  • 奇怪的是,所有翻译都出现在I18n.backend中,但不在I18n.t中
  • @AlexanderWenzowski,谢谢!在我的书中,您的评论绝对算作An explanation to the problem, a way to fix the problem even without understanding it, or even hints strongly inducive to such a fix.。但是赏金不能分配给 cmets。 ;) 你能发表评论作为答案吗? (自 8 月 28 日结束以来,这个 I18n 问题一直困扰着我……嗯)
  • 很高兴能够提供帮助!

标签: ruby-on-rails windows byte-order-mark


【解决方案1】:

奇怪的是,数据按预期出现在 I18n.backend 中,但无法使用 I18n.t 单独选择

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

led to @ANeves discoveringBOM 正在破坏 Heroku 解析 resulted in the fix 删除有问题的 BOM 的文件的能力。


UTF-8 中关于 BOM 的维基百科

Unicode 标准does permit the BOM in UTF-8,但does not require or recommend 使用它。字节顺序 has no meaning in UTF-8 所以在 UTF-8 中,BOM 仅用于识别文本流或 文件为 UTF-8。

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

如果未来的读者关注,请考虑阅读common encoding problems

【讨论】:

  • 而且我实际上认为这也是一个比我更好的答案。也标记为答案。
【解决方案2】:

@Alexander Wenzowski 让我走上了正轨。

似乎byte order mark 搞乱了 Heroku 本地化文件的加载...
当我使用 Notepad++ 将文件转换为没有 BOM 时,一切都得到了修复。

起初我只是想为我检查这个新东西,I18n.backend...然后我注意到我第一眼就错过了:即使数据在那里,它也被破坏了。

>> 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>

【讨论】:

    【解决方案3】:

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

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

    en:
      dashboard: "Dashboard"
    

    还有一个我们定义的

    en:
      dashboard:
        title: "Some Title"
    

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

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

    【讨论】:

    • 这正是我的问题。查找重复条目!
    【解决方案4】:

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

    【讨论】:

    • 非常自信。我是否正确地认为这个答案是出于个人经验? (使答案非常有用。:)
    • Heroku 使用标准的 Ruby 构建,因此这几乎可以肯定只是 Windows/UNIX 与 BOM 标记的区别。 Heroku 环境应该没有什么独特的地方可以在这​​里发挥作用。
    【解决方案5】:

    编写此行也将解决您的 application.rb 中的问题

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

    【讨论】:

    • 我认为您遇到了不同的问题,因为我的问题不是获取文件而是解析其内容:BOM 破坏了文件内容的加载。
    • 是的,heroku 没有读取我的语言环境文件,所以当我输入时,我为我工作
    猜你喜欢
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多