Use helper methods inside local file?

I am trying to start Gitorious using Rails 3 but I am having a problem.

I have this line in a view.

<p><%= t("views.commits.message").call(self, tree_path(@commit.id)) %></p> 

The corresponding locale line looks like this [ config/locales/en.rb ]

  :message => lambda { |this, path| "This is the initial commit in this repository, " + this.link_to( "browse the initial tree state", path ) + "." } 

The problem is that the lambda method is not called using #call in the view, which is called by someone else, which means that this not self , which is passed to it.

this contains views.commits.message and path contains {:rescue_format=>:html} . The Gitorious team used this approach throughout the application, which means that I can’t just move the logic to a helper method without taking the day the form works.

I did some research and found this thread about the exact string.

This was a problem with the problem.

This means that you have i18n gem installed on your system; This gem is incompatible with Gitorious. Removing this problem with Rubygems should fix the problem.

I tried uninstalling i18n , but running bundle install just installs it again.

How can I solve this problem without refactoring the LAN file 700?

+4
source share
1 answer

This is a common problem, how to break complex nested fragments of text.

Using markdowns to simplify it

 This is the initial commit in this repository [browse the initial tree state](http://example.com/some/path) . 

Perhaps in Chinese you say instead

 这是第一个提交在这个知识库[看初始状态](http://example.com/some/path) 。 

We should consider 3 things:

  • External text
  • Link text
  • Order and position of these two

If the position of the link relative to the text does not need to be changed, then @WattsInABox is correct.

 views.commits.message: "This is the initial commit in this repository" views.commits.browse: "browse the initial tree state" 

Then we just make

 <p> <%= t "views.commits.message" %> <%= link_to t("views.commits.browse"), tree_path(@commit.id) %> . </p> 

But sometimes order and position matter, in which case we can try to be more intelligent.

 views.commits.message: "This is the initial commit in this repository %{link}" views.commits.browse: "browse the initial tree state" 

Then we can interpolate the link in the right place

 <p> <%= t "views.commits.message", link: link_to(t("views.commits.browse"), tree_path(@commit.id)) %> </p> 
+1
source

Source: https://habr.com/ru/post/1394295/


All Articles