Default encodings for repository files can now be set in application settings (Admin -> Settings -> Repositories encodings).

These encodings are used to convert files content and diff to UTF-8 so that they're properly displayed.
Multiple values are allowed (comma separated).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@814 e93f8b46-1217-0410-a6f0-8f06a7374b81
pull/351/head
Jean-Philippe Lang 17 years ago
parent bb724e75c0
commit cdb2781b48
  1. 14
      app/helpers/repositories_helper.rb
  2. 8
      app/views/repositories/diff.rhtml
  3. 2
      app/views/repositories/entry.rhtml
  4. 3
      app/views/settings/edit.rhtml
  5. 4
      config/settings.yml
  6. 1
      lang/bg.yml
  7. 1
      lang/cs.yml
  8. 1
      lang/de.yml
  9. 1
      lang/en.yml
  10. 1
      lang/es.yml
  11. 1
      lang/fr.yml
  12. 1
      lang/it.yml
  13. 1
      lang/ja.yml
  14. 1
      lang/nl.yml
  15. 1
      lang/pl.yml
  16. 1
      lang/pt-br.yml
  17. 1
      lang/pt.yml
  18. 1
      lang/ro.yml
  19. 1
      lang/sv.yml
  20. 1
      lang/zh.yml

@ -17,6 +17,7 @@
require 'coderay'
require 'coderay/helpers/file_type'
require 'iconv'
module RepositoriesHelper
def syntax_highlight(name, content)
@ -24,6 +25,19 @@ module RepositoriesHelper
type ? CodeRay.scan(content, type).html : h(content)
end
def to_utf8(str)
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
@encodings.each do |encoding|
begin
return Iconv.conv('UTF-8', encoding, str)
rescue Iconv::Failure
# do nothing here and try the next encoding
end
end
str
end
def repository_field_tags(form, repository)
method = repository.class.name.demodulize.underscore + "_field_tags"
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)

@ -34,13 +34,13 @@
<%= table_file[key].nb_line_left %>
</th>
<td class="line-code <%= table_file[key].type_diff_left %>">
<pre><%= table_file[key].line_left %></pre>
<pre><%=to_utf8 table_file[key].line_left %></pre>
</td>
<th class="line-num">
<%= table_file[key].nb_line_right %>
</th>
<td class="line-code <%= table_file[key].type_diff_right %>">
<pre><%= table_file[key].line_right %></pre>
<pre><%=to_utf8 table_file[key].line_right %></pre>
</td>
</tr>
<% end %>
@ -72,11 +72,11 @@
</th>
<% if table_file[key].line_left.empty? %>
<td class="line-code <%= table_file[key].type_diff_right %>">
<pre><%= table_file[key].line_right %></pre>
<pre><%=to_utf8 table_file[key].line_right %></pre>
</td>
<% else %>
<td class="line-code <%= table_file[key].type_diff_left %>">
<pre><%= table_file[key].line_left %></pre>
<pre><%=to_utf8 table_file[key].line_left %></pre>
</td>
<% end %>
</tr>

@ -9,7 +9,7 @@
</thead>
<tbody>
<% line_num = 1 %>
<% syntax_highlight(@path, @content).each_line do |line| %>
<% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
<tr>
<th class="line-num"><%= line_num %></th>
<td class="line-code"><pre><%= line %></pre></td>

@ -48,6 +48,9 @@
<p><label><%= l(:setting_sys_api_enabled) %></label>
<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p>
<p><label><%= l(:setting_repositories_encodings) %></label>
<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %><br /><em><%= l(:text_comma_separated) %></em></p>
</div>
<fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend>

@ -88,4 +88,8 @@ issue_list_default_columns:
- subject
- assigned_to
- updated_on
# encodings used to convert repository files content to UTF-8
# multiple values accepted, comma separated
repositories_encodings:
default: ''

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -182,6 +182,7 @@ setting_autologin: Autologin
setting_date_format: Date format
setting_cross_project_issue_relations: Allow cross-project issue relations
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings
label_user: User
label_user_plural: Users

@ -517,3 +517,4 @@ button_reset: Reset
label_added_time_by: Added by %s %s ago
field_estimated_hours: Estimated time
label_changeset_plural: Changesets
setting_repositories_encodings: Repositories encodings

@ -182,6 +182,7 @@ setting_autologin: Autologin
setting_date_format: Format de date
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets
setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes
setting_repositories_encodings: Encodages des dépôts
label_user: Utilisateur
label_user_plural: Utilisateurs

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: 問題の一覧で表示する項目
setting_repositories_encodings: Repositories encodings

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Zestawienia zmian
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -514,3 +514,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -515,3 +515,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

@ -517,3 +517,4 @@ label_changeset_plural: Changesets
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings

Loading…
Cancel
Save