Commit c4d4eae3f9b66c0216c929ddcaccf42ab5231f13

Authored by Antonio Terceiro
1 parent 91eaaa66

Remove interpolation from translatable strings

Also added test/unit/i18n_test.rb which will warn us if any others pop
up.
app/controllers/my_profile/profile_editor_controller.rb
@@ -109,7 +109,7 @@ class ProfileEditorController < MyProfileController @@ -109,7 +109,7 @@ class ProfileEditorController < MyProfileController
109 profile = environment.profiles.find(params[:id]) 109 profile = environment.profiles.find(params[:id])
110 if profile.disable 110 if profile.disable
111 profile.save 111 profile.save
112 - session[:notice] = _("The profile '#{profile.name}' was deactivated.") 112 + session[:notice] = _("The profile '%s' was deactivated.") % profile.name
113 else 113 else
114 session[:notice] = _('Could not deactivate profile.') 114 session[:notice] = _('Could not deactivate profile.')
115 end 115 end
@@ -123,7 +123,7 @@ class ProfileEditorController < MyProfileController @@ -123,7 +123,7 @@ class ProfileEditorController < MyProfileController
123 profile = environment.profiles.find(params[:id]) 123 profile = environment.profiles.find(params[:id])
124 124
125 if profile.enable 125 if profile.enable
126 - session[:notice] = _("The profile '#{profile.name}' was activated.") 126 + session[:notice] = _("The profile '%s' was activated.") % profile.name
127 else 127 else
128 session[:notice] = _('Could not activate the profile.') 128 session[:notice] = _('Could not activate the profile.')
129 end 129 end
app/views/content_viewer/article_versions.html.erb
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 <li> 12 <li>
13 <%= radio_button_tag 'v1', v.version, false, :onclick => 'versionInputClicked(this)' %> 13 <%= radio_button_tag 'v1', v.version, false, :onclick => 'versionInputClicked(this)' %>
14 <%= radio_button_tag 'v2', v.version, false, :onclick => 'versionInputClicked(this)' %> 14 <%= radio_button_tag 'v2', v.version, false, :onclick => 'versionInputClicked(this)' %>
15 - <%= link_to(_("Version #{v.version}"), @page.url.merge(:version => v.version)) %> 15 + <%= link_to(_("Version %s") % v.version, @page.url.merge(:version => v.version)) %>
16 <%= @page.version == v.version ? _('(current)') : '' %> 16 <%= @page.version == v.version ? _('(current)') : '' %>
17 <span class='updated-by'><%= _('by %{author}') % {:author => link_to(@page.author_name(v.version), @page.author_url(v.version))} %></span> 17 <span class='updated-by'><%= _('by %{author}') % {:author => link_to(@page.author_name(v.version), @page.author_url(v.version))} %></span>
18 <span class='updated-on'><%= show_time(v.updated_at) %></span> 18 <span class='updated-on'><%= show_time(v.updated_at) %></span>
app/views/profile_roles/destroy.html.erb
1 -<h1> <%= _("Deleting #{@role.name}") %> </h1> 1 +<h1> <%= _("Deleting %s") % @role.name %> </h1>
2 2
3 <% if @members.nil? || @members.empty? %> 3 <% if @members.nil? || @members.empty? %>
4 <p><%= _('This role is not being currently used.')%></p> 4 <p><%= _('This role is not being currently used.')%></p>
app/views/profile_roles/edit.html.erb
1 -<h1> <%= _("Editing #{@role.name}") %> </h1> 1 +<h1> <%= _("Editing %s") % @role.name %> </h1>
2 2
3 <%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => [@role.kind] } %> 3 <%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => [@role.kind] } %>
app/views/role/edit.html.erb
1 -<h2> <%= _("Editing #{@role.name}") %> </h2> 1 +<h2> <%= _("Editing %s") % @role.name %> </h2>
2 2
3 <%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => role_available_permissions(@role) } %> 3 <%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => role_available_permissions(@role) } %>
app/views/shared/_content_item.html.erb
@@ -6,6 +6,6 @@ @@ -6,6 +6,6 @@
6 <span class="item-description"> 6 <span class="item-description">
7 <%= link_to(content.name, content.url) %> 7 <%= link_to(content.name, content.url) %>
8 </span> 8 </span>
9 - <span class="item-date"><%= _("Published at: #{show_date(content.updated_at)}") %></span> 9 + <span class="item-date"><%= _("Published at: %s") % show_date(content.updated_at) %></span>
10 </div> 10 </div>
11 </div> 11 </div>
lib/tasks/gettext.rake
@@ -60,6 +60,8 @@ task :updatepo do @@ -60,6 +60,8 @@ task :updatepo do
60 60
61 puts 'Extracting strings from source. This may take a while ...' 61 puts 'Extracting strings from source. This may take a while ...'
62 62
  63 + # XXX this list is duplicated in test/unit/i18n_test.rb; if you change it
  64 + # here, please also update it there.
63 files_to_translate = [ 65 files_to_translate = [
64 "{app,lib}/**/*.{rb,rhtml,erb}", 66 "{app,lib}/**/*.{rb,rhtml,erb}",
65 'config/initializers/*.rb', 67 'config/initializers/*.rb',
plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
@@ -29,7 +29,7 @@ class OauthClientPluginPublicController &lt; PublicController @@ -29,7 +29,7 @@ class OauthClientPluginPublicController &lt; PublicController
29 if user_provider.enabled? && provider.enabled? 29 if user_provider.enabled? && provider.enabled?
30 session[:user] = user.id 30 session[:user] = user.id
31 else 31 else
32 - session[:notice] = _("Can't login with #{provider.name}") 32 + session[:notice] = _("Can't login with %s") % provider.name
33 end 33 end
34 34
35 redirect_to :controller => :account, :action => :login 35 redirect_to :controller => :account, :action => :login
plugins/oauth_provider/views/doorkeeper/authorizations/new.html.erb
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 6
7 <main role="main"> 7 <main role="main">
8 <p class="h4"> 8 <p class="h4">
9 - <%= _('Authorize %s to use your account?' % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>") %> 9 + <%= _('Authorize %s to use your account?') % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>" %>
10 </p> 10 </p>
11 11
12 <% if @pre_auth.scopes %> 12 <% if @pre_auth.scopes %>
plugins/sub_organizations/lib/related_organizations_block.rb
@@ -24,7 +24,7 @@ class RelatedOrganizationsBlock &lt; ProfileListBlock @@ -24,7 +24,7 @@ class RelatedOrganizationsBlock &lt; ProfileListBlock
24 end 24 end
25 25
26 def help 26 def help
27 - _("This block displays #{display_type[:title]} organizations of this organization") 27 + _("This block displays %s organizations of this organization") % display_type[:title]
28 end 28 end
29 29
30 def profiles 30 def profiles
plugins/sub_organizations/views/sub_organizations_plugin_profile/_full_related_organizations.html.erb
1 <% extend SubOrganizationsPlugin::SearchHelper %> 1 <% extend SubOrganizationsPlugin::SearchHelper %>
2 <div class="related-organizations-list-block"> 2 <div class="related-organizations-list-block">
3 3
4 - <h1><%= _("#{profile.name}'s sub-#{organization_type.pluralize}") %></h1> 4 + <h1><%= _("%s's sub-%s") % [profile.name, organization_type.pluralize] %></h1>
5 <ul> 5 <ul>
6 <% organizations.each do |organization| %> 6 <% organizations.each do |organization| %>
7 <li class="related-organizations-item"> 7 <li class="related-organizations-item">
@@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
53 53
54 <% button_bar(:class => "related-organizations-button-bar") do %> 54 <% button_bar(:class => "related-organizations-button-bar") do %>
55 <%= button :back, c_('Go back'), { :controller => 'profile' } %> 55 <%= button :back, c_('Go back'), { :controller => 'profile' } %>
56 - <%= button :add, _("Add a new #{organization_type}"), :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %> 56 + <%= button :add, _("Add a new %s") % organization_type, :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %>
57 57
58 <% if !@full %> 58 <% if !@full %>
59 <%= button :more, c_('View all'), { :controller => 'sub_organizations_plugin_profile', :action => params[:action], :type => organization_type } %> 59 <%= button :more, c_('View all'), { :controller => 'sub_organizations_plugin_profile', :action => params[:action], :type => organization_type } %>
plugins/sub_organizations/views/sub_organizations_plugin_profile/_related_organizations.html.erb
1 <div class="common-profile-list-block"> 1 <div class="common-profile-list-block">
2 - <h1><%= _("#{profile.name}'s sub-#{organization_type.pluralize}") %></h1> 2 + <h1><%= _("%s's sub-%s") % [profile.name, organization_type.pluralize] %></h1>
3 3
4 <ul class='profile-list'> 4 <ul class='profile-list'>
5 <% organizations.each do |organization| %> 5 <% organizations.each do |organization| %>
@@ -7,11 +7,11 @@ @@ -7,11 +7,11 @@
7 <% end %> 7 <% end %>
8 </ul> 8 </ul>
9 <% if organizations.length == 0 %> 9 <% if organizations.length == 0 %>
10 - <li><%= _("There are no sub-#{organization_type.pluralize} yet. " ) %></li> 10 + <li><%= _("There are no sub-%s yet.") % organization_type.pluralize %></li>
11 <% end %> 11 <% end %>
12 <% button_bar(:class => "related-organizations-button-bar") do %> 12 <% button_bar(:class => "related-organizations-button-bar") do %>
13 <%= button :back, c_('Go back'), { :controller => 'profile' } %> 13 <%= button :back, c_('Go back'), { :controller => 'profile' } %>
14 - <%= button :add, _("Add a new #{organization_type}"), :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %> 14 + <%= button :add, _("Add a new %s") % organization_type, :controller => 'sub_organizations_plugin_myprofile', :action => 'index' if logged_in? && user.has_permission?(:edit_profile, profile) && !environment.enabled?("disable_asset_#{organization_type.pluralize}") %>
15 15
16 <% if !@full %> 16 <% if !@full %>
17 <%= button :more, c_('View all'), { :controller => 'sub_organizations_plugin_profile', :action => params[:action], :type => organization_type } %> 17 <%= button :more, c_('View all'), { :controller => 'sub_organizations_plugin_profile', :action => params[:action], :type => organization_type } %>
test/unit/i18n_test.rb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +require_relative "../test_helper"
  2 +
  3 +class I18nTest < ActiveSupport::TestCase
  4 +
  5 + # XXX this duplicates the list from lib/tasks/gettext.rake
  6 + files_to_translate = [
  7 + "{app,lib}/**/*.{rb,rhtml,erb}",
  8 + 'config/initializers/*.rb',
  9 + 'public/*.html.erb',
  10 + 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}',
  11 + ].map { |pattern| Dir.glob(pattern) }.flatten
  12 +
  13 + plugins_files_to_translate = Dir.glob("plugins/**/*.{rb,html.erb}")
  14 +
  15 + (files_to_translate + plugins_files_to_translate).each do |f|
  16 + test "translation marks in #{f}" do
  17 + lines = File.readlines(f).select do |line|
  18 + line =~ /\b_\(["'][^)]*#\{/
  19 + end
  20 + assert lines == [], "found interpolation in translatable strings:\n" + lines.join("\n")
  21 + end
  22 + end
  23 +
  24 +end
  25 +