diff options
-rw-r--r-- | app/helpers/repositories_helper.rb | 16 | ||||
-rw-r--r-- | app/views/repositories/diff.rhtml | 8 | ||||
-rw-r--r-- | app/views/repositories/entry.rhtml | 2 | ||||
-rw-r--r-- | app/views/settings/edit.rhtml | 3 | ||||
-rw-r--r-- | config/settings.yml | 4 | ||||
-rw-r--r-- | lang/bg.yml | 1 | ||||
-rw-r--r-- | lang/cs.yml | 1 | ||||
-rw-r--r-- | lang/de.yml | 1 | ||||
-rw-r--r-- | lang/en.yml | 1 | ||||
-rw-r--r-- | lang/es.yml | 1 | ||||
-rw-r--r-- | lang/fr.yml | 1 | ||||
-rw-r--r-- | lang/it.yml | 1 | ||||
-rw-r--r-- | lang/ja.yml | 1 | ||||
-rw-r--r-- | lang/nl.yml | 1 | ||||
-rw-r--r-- | lang/pl.yml | 1 | ||||
-rw-r--r-- | lang/pt-br.yml | 1 | ||||
-rw-r--r-- | lang/pt.yml | 1 | ||||
-rw-r--r-- | lang/ro.yml | 1 | ||||
-rw-r--r-- | lang/sv.yml | 1 | ||||
-rw-r--r-- | lang/zh.yml | 1 |
20 files changed, 42 insertions, 6 deletions
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d82e16561..41218fa79 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -17,13 +17,27 @@ 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) diff --git a/app/views/repositories/diff.rhtml b/app/views/repositories/diff.rhtml index e982b6e13..5094f4713 100644 --- a/app/views/repositories/diff.rhtml +++ b/app/views/repositories/diff.rhtml @@ -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> diff --git a/app/views/repositories/entry.rhtml b/app/views/repositories/entry.rhtml index 7d8cbb318..94db240ab 100644 --- a/app/views/repositories/entry.rhtml +++ b/app/views/repositories/entry.rhtml @@ -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> diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml index c3e430c9b..2accdc715 100644 --- a/app/views/settings/edit.rhtml +++ b/app/views/settings/edit.rhtml @@ -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> diff --git a/config/settings.yml b/config/settings.yml index bac50e3d5..b5ed26a1f 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -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: ''
\ No newline at end of file diff --git a/lang/bg.yml b/lang/bg.yml index 3c6671f1e..fe9efff09 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -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 diff --git a/lang/cs.yml b/lang/cs.yml index 884530834..abf1f6e5a 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -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 diff --git a/lang/de.yml b/lang/de.yml index b7ae15e68..8345d99d4 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -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 diff --git a/lang/en.yml b/lang/en.yml index e3bb9abb8..34e49565f 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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 diff --git a/lang/es.yml b/lang/es.yml index c5fb1d89a..12a6518a2 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -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 diff --git a/lang/fr.yml b/lang/fr.yml index b2b338b51..566f6573a 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -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 diff --git a/lang/it.yml b/lang/it.yml index c6250837f..2d0e0a1d0 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -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 diff --git a/lang/ja.yml b/lang/ja.yml index 352dd1a66..c19199c4b 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -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 diff --git a/lang/nl.yml b/lang/nl.yml index 007e80c94..19c6a0de0 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -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 diff --git a/lang/pl.yml b/lang/pl.yml index 7dd04741c..9b0af1fda 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -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 diff --git a/lang/pt-br.yml b/lang/pt-br.yml index ebc8de173..b278edc58 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -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
diff --git a/lang/pt.yml b/lang/pt.yml index 549d3cd3a..da75aa99c 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -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 diff --git a/lang/ro.yml b/lang/ro.yml index cc0b85a7d..996df529d 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -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 diff --git a/lang/sv.yml b/lang/sv.yml index b26675f79..a457ca11a 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -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 diff --git a/lang/zh.yml b/lang/zh.yml index 08108ee42..ff0e12529 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -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 |