balinterdi / i15r

Replaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations (i15r = internationalizer)
MIT License
113 stars 30 forks source link

Parsing issue #20

Open zyphlar opened 11 years ago

zyphlar commented 11 years ago

Unknown why i15r had issues with this line. Maybe it's because of the custom form generator we're using that provides a :label attribute? A very interesting failure mode.

-<%= f.text_field :feature_list, :size=>60, :label=>'Feature flags', :append=>' (space separated)', :help=>"Known: #{@features.join(', ')}" %> +<%= f.text_field :feature_list, :size=>60, :label=>I18n.t("admin.accounts.form.feature_flags_append=>_space_separatedhelp=>known{@featuresjoin_", :default => 'Feature flags', :append=>' (space separated)', :help=>"Known: #{@features.join(', '))}" %>

-<%= f.text_field :account_id, :label=>'Account ID', :size=>12, :readonly=>true, :clear=>false %> +<%= f.text_field :account_id, :label=>'Account ID', I18n.t("admin.guests.form.size", :default => "size")=>12, :readonly=>true, :clear=>false %>

-<%= f.text_field :cluster_name, :label=>'Location', :size=>12, :readonly=>true %> +<%= f.text_field :cluster_name, :label=>'Location', I18n.t("admin.guests.form.size", :default => "size")=>12, :readonly=>true %>

zyphlar commented 11 years ago

Also (probably because of the <%= label %> syntax)

-<%= label nil, :new_host_id, 'New host' %> +<%= label nil, I18n.t("admin.guests.relocate.new_host_id", :default => "new_host_id"), 'New host' %>

zyphlar commented 11 years ago

This one is interesting. It seems to have keyed in on the plaintext "qux" but then symbolized the first AND second instances of "qux."

-<%=h foo.foo_bar %>; <%=h foo.foo_baz %>; <%=h foo.foo_quxes %>qux +<%=h foo.foo_bar %>; <%=h foo.foo_baz %>; <%=h foo.<%= I18n.t("admin.foo.index.qux", :default => "qux") %>es %><%= I18n.t("admin.foo.index.qux", :default => "qux") %>

zyphlar commented 11 years ago

And another. Maybe some kind of catchall or <br> detection?

       <%= show(@plan, :subscription_options) do |p|
         p.subscription_options.map do |so|
           "#{pluralize so[:interval], 'month'}: #{number_to_currency so[:cost]}"
-        end.join('<br />')
+        <%= I18n.t("admin.plans.show.endjoin", :default => "end.join('") %><br />')
       end %>
zyphlar commented 11 years ago

Don't mind me, just documenting interesting stuff I find :) I understand the 80/20 rule.

-<%= [:notice, :warning, :error].collect {|f| "<div class=\"messaging #{f}\">#{h flash[f]}</div>\n" if flash[f] }.compact.join %>
+<%= [:notice, :warning, :error].collect {|f| "<div class=\"messaging #{f}\"><%= I18n.t("foo.bar.{h_flash[f]}", :default => "#{h flash[f]}") %></div>\n" if flash[f] }.compact.join %>

[brackets] and other symbols aren't valid yml

<td colspan="2">&nbsp;</td>
<td colspan="2"><%= I18n.t("foo.bar.&nbsp", :default => "&nbsp;") %></td>
<%= link_to '[admin]', :controller=>'/admin' %>
<%= link_to I18n.t("foo.bar.[admin]", :default => '[admin]'), :controller=>'/admin' %>
Arpsara commented 10 years ago

Hi ! :) Thank you for this very useful gem ! Here is some other bug that concerns strings that should not have been replaced or ones that have been replaced incorrectly. (Actually, it's the same than zyphlar.)

It seems that if there are some code after the :label => " ", the remplacement fails.

In a form with semantic_form_for :

<%= f.input :email, :as => :email, :label => false, :input_html => { :placeholder => "Votre mail" } %>  
<%= f.input :email, :as => :email, :label => false, I18n.t("pages.contact.input_html") => { :placeholder => "Votre mail" } %>
<%= f.action :submit, :label =>"Envoyer", :button_html => {:class => "button"} %>
<%= f.action :submit, :label =>I18n.t("pages.contact.envoyer_button_html_=>_{class_=>_", :default => "Envoyer", :button_html => {:class => ")button"} %>
Arpsara commented 10 years ago

Here is some others bugs :

<%= link_to "Editer l'article", edit_admin_article_path(@article) %>
<%= link_to I18n.t("articles.show.editer_l")article", edit_admin_article_path(@article) %>

It doesn't seem to like the ' . :)

zyphlar commented 10 years ago

Is there some way we can parse ERB just like Rails does, rather than trying to use Regex to parse? I think we'll always run into issues as long as we use regex. On Jan 29, 2014 2:54 AM, "Arpsara" notifications@github.com wrote:

Here is some others bugs :

''' <%= link_to "Editer l'article", edit_admin_article_path(@articlehttps://github.com/article) %> <%= link_to I18n.t("articles.show.editer_l")article", edit_admin_article_path(@article https://github.com/article) %> ''' It doesn't seem to like the ' . :)

Reply to this email directly or view it on GitHubhttps://github.com/balinterdi/i15r/issues/20#issuecomment-33570109 .

EddieDee commented 9 years ago

Same thing happening to me, trying to figure it out with http://rubular.com, but Regex is hard haha this guy is awesome, will be cool to add type of strings to the reserve words