From: Go MAEDA Date: Thu, 10 Sep 2020 07:19:21 +0000 (+0000) Subject: Internationalize error messages for wiki macros (#33426). X-Git-Tag: 4.2.0~800 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=58eca8190e22e0c0ca83386ebea49b07c05dc0e1;p=redmine.git Internationalize error messages for wiki macros (#33426). Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@20013 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/config/locales/en.yml b/config/locales/en.yml index 7e7def09a..559672371 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -233,6 +233,16 @@ en: error_can_not_delete_auth_source: "This authentication mode is in use and cannot be deleted." error_spent_on_future_date: "Cannot log time on a future date" error_not_allowed_to_log_time_for_other_users: "You are not allowed to log time for other users" + error_can_not_execute_macro_html: "Error executing the %{name} macro (%{error})" + error_macro_does_not_accept_block: "This macro does not accept a block of text" + error_invalid_macro_name: "Invalid macro name: %{name} (only 0-9, A-Z, a-z and _ characters are accepted)" + error_can_not_create_macro_without_block: "Can not create a macro without a block!" + error_childpages_macro_no_argument: "With no argument, this macro can be called from wiki pages only" + error_circular_inclusion: "Circular inclusion detected" + error_page_not_found: "Page not found" + error_filename_required: "Filename required" + error_invalid_size_parameter: "Invalid size parameter" + error_attachment_not_found: "Attachment %{name} not found" mail_subject_lost_password: "Your %{value} password" mail_body_lost_password: 'To change your password, click on the following link:' diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index c34e404e2..03eeecde9 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -45,12 +45,12 @@ module Redmine if self.class.instance_method(method_name).arity == 3 send(method_name, obj, args, text) elsif text - raise "This macro does not accept a block of text" + raise t(:error_macro_does_not_accept_block) else send(method_name, obj, args) end rescue => e - "
Error executing the #{h name} macro (#{h e.to_s})
".html_safe + %|
#{t(:error_can_not_execute_macro_html, :name => name, :error => e.to_s)}
|.html_safe end end @@ -152,10 +152,10 @@ module Redmine def macro(name, options={}, &block) options.assert_valid_keys(:desc, :parse_args) unless /\A\w+\z/.match?(name.to_s) - raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)" + raise t(:error_invalid_macro_name, :name => name) end unless block_given? - raise "Can not create a macro without a block!" + raise t(:error_can_not_create_macro_without_block) end name = name.to_s.downcase.to_sym available_macros[name] = {:desc => @@desc || ''}.merge(options) @@ -204,9 +204,9 @@ module Redmine elsif obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version) page = obj.page else - raise 'With no argument, this macro can be called from wiki pages only.' + raise t(:error_childpages_macro_no_argument) end - raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) + raise t(:error_page_not_found) if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) pages = page.self_and_descendants(options[:depth]).group_by(&:parent_id) render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id) end @@ -216,9 +216,9 @@ module Redmine "{{include(projectname:Foo)}} -- to include a page of a specific project wiki" macro :include do |obj, args| page = Wiki.find_page(args.first.to_s, :project => @project) - raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) + raise t(:error_page_not_found) if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) @included_wiki_pages ||= [] - raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.id) + raise t(:error_circular_inclusion) if @included_wiki_pages.include?(page.id) @included_wiki_pages << page.id out = textilizable(page.content, :text, :attachments => page.attachments, :headings => false, :inline_attachments => @@inline_attachments) @included_wiki_pages.pop @@ -247,9 +247,9 @@ module Redmine macro :thumbnail do |obj, args| args, options = extract_macro_options(args, :size, :title) filename = args.first - raise 'Filename required' unless filename.present? + raise t(:error_filename_required) unless filename.present? size = options[:size] - raise 'Invalid size parameter' unless size.nil? || /^\d+$/.match?(size) + raise t(:error_invalid_size_parameter) unless size.nil? || /^\d+$/.match?(size) size = size.to_i size = 200 unless size > 0 if obj && obj.respond_to?(:attachments) && attachment = Attachment.latest_attach(obj.attachments, filename) @@ -260,7 +260,7 @@ module Redmine img = image_tag(thumbnail_url, :alt => attachment.filename) link_to(img, image_url, :class => 'thumbnail', :title => title) else - raise "Attachment #{filename} not found" + raise t(:error_attachment_not_found, :name => filename) end end