From cdb2781b48f2a3ee2ba7d04574671ee195f7006f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 7 Oct 2007 15:21:40 +0000 Subject: [PATCH] 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 --- app/helpers/repositories_helper.rb | 16 +++++++++++++++- app/views/repositories/diff.rhtml | 8 ++++---- app/views/repositories/entry.rhtml | 2 +- app/views/settings/edit.rhtml | 3 +++ config/settings.yml | 4 ++++ lang/bg.yml | 1 + lang/cs.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fr.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/nl.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/sv.yml | 1 + 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 %> -
<%= table_file[key].line_left %>
+
<%=to_utf8 table_file[key].line_left %>
<%= table_file[key].nb_line_right %> -
<%= table_file[key].line_right %>
+
<%=to_utf8 table_file[key].line_right %>
<% end %> @@ -72,11 +72,11 @@ <% if table_file[key].line_left.empty? %> -
<%= table_file[key].line_right %>
+
<%=to_utf8 table_file[key].line_right %>
<% else %> -
<%= table_file[key].line_left %>
+
<%=to_utf8 table_file[key].line_left %>
<% end %> 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 @@ <% line_num = 1 %> - <% syntax_highlight(@path, @content).each_line do |line| %> + <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %> <%= line_num %>
<%= line %>
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 @@

<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %>

+ +

+<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>

<%= l(:setting_issue_list_default_columns) %> 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 -- 2.39.5