Project

General

Profile

Defect #43906 » wiki-help-fix-for-locales-with-region-subtag.patch

Go MAEDA, 2026-03-25 04:31

View differences:

app/controllers/help_controller.rb
19 19

  
20 20
class HelpController < ApplicationController
21 21
  def show_wiki_syntax
22
    type = params[:type].nil? ? "" : "#{params[:type]}_"
23

  
24
    lang = current_language.to_s
25
    template = "help/wiki_syntax/#{Setting.text_formatting}/#{lang}/wiki_syntax_#{type}#{Setting.text_formatting}"
26
    unless lookup_context.exists?(template)
27
      lang = "en"
28
    end
29
    render template: "help/wiki_syntax/#{Setting.text_formatting}/#{lang}/wiki_syntax_#{type}#{Setting.text_formatting}", layout: nil
22
    render template: wiki_syntax_template_for(params[:type]), layout: nil
30 23
  end
31 24

  
32 25
  def show_code_highlighting
33 26
    @available_lexers = Rouge::Lexer.all.sort_by(&:tag)
34 27
    render template: "help/wiki_syntax/code_highlighting_languages", layout: nil
35 28
  end
29

  
30
  private
31

  
32
  def wiki_syntax_template_for(type)
33
    # Region subtags are typically uppercase in locale tags (e.g., ta-IN),
34
    # but some help templates use lowercase locale directories, so try both.
35
    candidates = [current_language.to_s, current_language.to_s.downcase, "en"].uniq
36
    template_name = "wiki_syntax_#{type.present? ? "#{type}_" : ""}#{Setting.text_formatting}"
37

  
38
    candidates.each do |lang|
39
      template = "help/wiki_syntax/#{Setting.text_formatting}/#{lang}/#{template_name}"
40
      return template if lookup_context.exists?(template)
41
    end
42
  end
36 43
end
test/functional/help_controller_test.rb
66 66
    assert_select 'h1', :text => "Wiki Syntax Schnellreferenz (CommonMark Markdown (GitHub Flavored))"
67 67
  end
68 68

  
69
  def test_get_help_wiki_syntax_should_fallback_to_lowercase_region_locale_directory
70
    user = User.find(2)
71
    user.language = 'ta-IN'
72
    user.save!
73
    @request.session[:user_id] = 2
74

  
75
    with_settings :text_formatting => 'common_mark' do
76
      get :show_wiki_syntax
77
    end
78
    assert_response :success
79

  
80
    assert_select 'h1', :text => "விக்கி தொடரியல் விரைவு குறிப்பு (CommonMark Markdown (GitHub Flavored))"
81
  end
82

  
69 83
  def test_get_help_wiki_syntax_should_fallback_to_english
70 84
    user = User.find(2)
71 85
    user.language = 'ro'
72 86
    user.save!
73 87
    @request.session[:user_id] = 2
74 88

  
75
    get :show_wiki_syntax
89
    with_settings :text_formatting => 'common_mark' do
90
      get :show_wiki_syntax
91
    end
76 92
    assert_response :success
77 93

  
78 94
    assert_select 'h1', :text => "Wiki Syntax Quick Reference (CommonMark Markdown (GitHub Flavored))"
    (1-1/1)