require 'coderay'
require 'coderay/helpers/file_type'
+require 'iconv'
module RepositoriesHelper
def syntax_highlight(name, content)
type = CodeRay::FileType[name]
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)
<%= 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 %>
</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>
</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>
<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>
- subject
- assigned_to
- updated_on
+# encodings used to convert repository files content to UTF-8
+# multiple values accepted, comma separated
+repositories_encodings:
+ default: ''
\ No newline at end of file
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
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
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
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
label_added_time_by: Added by %s %s ago
field_estimated_hours: Estimated time
label_changeset_plural: Changesets
+setting_repositories_encodings: Repositories encodings
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
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
field_column_names: Columns
label_default_columns: Default columns
setting_issue_list_default_columns: 問題の一覧で表示する項目
+setting_repositories_encodings: Repositories encodings
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
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
field_column_names: Columns\r
label_default_columns: Default columns\r
setting_issue_list_default_columns: Default columns displayed on the issue list\r
+setting_repositories_encodings: Repositories encodings\r
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
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
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
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