Skip to content

Commit 258c839

Browse files
committed
英語話者向けに統計ページの英語版を実装
- /english/stats ルートを追加 - StatsController に言語判定機能を追加(@lang パラメータ) - グラフタイトル、凡例、軸ラベルを英語対応 - ページ内のすべてのテキストを条件分岐で英語化 - 都道府県名の英語表記に対応(Hokkaido, Tokyo など) - 言語切り替えリンクを各ページの冒頭に追加 既存のコードパターンを活用し、DRY原則に従った最小限の実装。 将来的なi18n導入を見据えた設計となっている。
1 parent 24c2c6a commit 258c839

File tree

6 files changed

+182
-80
lines changed

6 files changed

+182
-80
lines changed

app/controllers/stats_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ class StatsController < ApplicationController
22

33
# GET /stats[.json]
44
def show
5+
# 言語設定
6+
@lang = params[:lang] || 'ja'
7+
58
# 2012年1月1日〜2024年12月31日までの集計結果
69
@period_start = 2012
710
@period_end = 2024
@@ -10,9 +13,9 @@ def show
1013

1114
# 推移グラフ
1215
@high_charts_globals = HighChartsBuilder.global_options
13-
@annual_dojos_chart = stats.annual_dojos_chart
14-
@annual_event_histories_chart = stats.annual_event_histories_chart
15-
@annual_participants_chart = stats.annual_participants_chart
16+
@annual_dojos_chart = stats.annual_dojos_chart(@lang)
17+
@annual_event_histories_chart = stats.annual_event_histories_chart(@lang)
18+
@annual_participants_chart = stats.annual_participants_chart(@lang)
1619

1720
# 最新データ
1821
@sum_of_dojos = Dojo.active_dojos_count
@@ -24,7 +27,8 @@ def show
2427
# 道場タグ分布
2528
@dojo_tag_chart = LazyHighCharts::HighChart.new('graph') do |f|
2629
number_of_tags = 10
27-
f.title(text: "CoderDojo タグ分布 (上位 #{number_of_tags})")
30+
title_text = @lang == 'en' ? "CoderDojo Tag Distribution (Top #{number_of_tags})" : "CoderDojo タグ分布 (上位 #{number_of_tags})"
31+
f.title(text: title_text)
2832

2933
# Use 'tally' method when using Ruby 2.7.0 or higher
3034
# cf. https://twitter.com/yasulab/status/1154566199511941120

app/helpers/application_helper.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,60 @@ def facebook_page_url; 'https://www.facebook.com/coderdojo.jp'; end
9494
def twitter_url; 'https://twitter.com/CoderDojoJapan'; end
9595
def youtube_url; 'https://youtube.com/CoderDojoJapan'; end
9696

97+
def prefecture_name_in_english(prefecture_name)
98+
# 都道府県名の英語表記を返す簡易マッピング
99+
# データベースには「県」「都」「府」が省略された形で保存されている
100+
prefecture_names = {
101+
'北海道' => 'Hokkaido',
102+
'青森' => 'Aomori',
103+
'岩手' => 'Iwate',
104+
'宮城' => 'Miyagi',
105+
'秋田' => 'Akita',
106+
'山形' => 'Yamagata',
107+
'福島' => 'Fukushima',
108+
'茨城' => 'Ibaraki',
109+
'栃木' => 'Tochigi',
110+
'群馬' => 'Gunma',
111+
'埼玉' => 'Saitama',
112+
'千葉' => 'Chiba',
113+
'東京' => 'Tokyo',
114+
'神奈川' => 'Kanagawa',
115+
'新潟' => 'Niigata',
116+
'富山' => 'Toyama',
117+
'石川' => 'Ishikawa',
118+
'福井' => 'Fukui',
119+
'山梨' => 'Yamanashi',
120+
'長野' => 'Nagano',
121+
'岐阜' => 'Gifu',
122+
'静岡' => 'Shizuoka',
123+
'愛知' => 'Aichi',
124+
'三重' => 'Mie',
125+
'滋賀' => 'Shiga',
126+
'京都' => 'Kyoto',
127+
'大阪' => 'Osaka',
128+
'兵庫' => 'Hyogo',
129+
'奈良' => 'Nara',
130+
'和歌山' => 'Wakayama',
131+
'鳥取' => 'Tottori',
132+
'島根' => 'Shimane',
133+
'岡山' => 'Okayama',
134+
'広島' => 'Hiroshima',
135+
'山口' => 'Yamaguchi',
136+
'徳島' => 'Tokushima',
137+
'香川' => 'Kagawa',
138+
'愛媛' => 'Ehime',
139+
'高知' => 'Kochi',
140+
'福岡' => 'Fukuoka',
141+
'佐賀' => 'Saga',
142+
'長崎' => 'Nagasaki',
143+
'熊本' => 'Kumamoto',
144+
'大分' => 'Oita',
145+
'宮崎' => 'Miyazaki',
146+
'鹿児島' => 'Kagoshima',
147+
'沖縄' => 'Okinawa'
148+
}
149+
150+
prefecture_names[prefecture_name] || prefecture_name
151+
end
152+
97153
end

app/models/high_charts_builder.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,54 @@ def global_options
88
end
99
end
1010

11-
def build_annual_dojos(source)
11+
def build_annual_dojos(source, lang = 'ja')
1212
data = annual_chart_data_from(source)
13+
title_text = lang == 'en' ? 'Number of Dojos' : '道場数の推移'
1314

1415
LazyHighCharts::HighChart.new('graph') do |f|
15-
f.title(text: '道場数の推移')
16+
f.title(text: title_text)
1617
f.xAxis(categories: data[:years])
17-
f.series(type: 'column', name: '増加数', yAxis: 0, data: data[:increase_nums])
18-
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
18+
f.series(type: 'column', name: lang == 'en' ? 'New' : '増加数', yAxis: 0, data: data[:increase_nums])
19+
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
1920
f.yAxis [
20-
{ title: { text: '増加数' }, tickInterval: 15, max: 75 },
21-
{ title: { text: '累積合計' }, tickInterval: 50, max: 250, opposite: true }
21+
{ title: { text: lang == 'en' ? 'New' : '増加数' }, tickInterval: 15, max: 75 },
22+
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 50, max: 250, opposite: true }
2223
]
2324
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
2425
f.colors(["#A0D3B5", "#505D6B"])
2526
end
2627
end
2728

28-
def build_annual_event_histories(source)
29+
def build_annual_event_histories(source, lang = 'ja')
2930
data = annual_chart_data_from(source)
31+
title_text = lang == 'en' ? 'Number of Events' : '開催回数の推移'
3032

3133
LazyHighCharts::HighChart.new('graph') do |f|
32-
f.title(text: '開催回数の推移')
34+
f.title(text: title_text)
3335
f.xAxis(categories: data[:years])
34-
f.series(type: 'column', name: '開催回数', yAxis: 0, data: data[:increase_nums])
35-
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
36+
f.series(type: 'column', name: lang == 'en' ? 'Events' : '開催回数', yAxis: 0, data: data[:increase_nums])
37+
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
3638
f.yAxis [
37-
{ title: { text: '開催回数' }, tickInterval: 500, max: 2000 },
38-
{ title: { text: '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
39+
{ title: { text: lang == 'en' ? 'Events' : '開催回数' }, tickInterval: 500, max: 2000 },
40+
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
3941
]
4042
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
4143
f.colors(["#F4C34F", "#BD2561"])
4244
end
4345
end
4446

45-
def build_annual_participants(source)
47+
def build_annual_participants(source, lang = 'ja')
4648
data = annual_chart_data_from(source)
49+
title_text = lang == 'en' ? 'Number of Participants' : '参加者数の推移'
4750

4851
LazyHighCharts::HighChart.new('graph') do |f|
49-
f.title(text: '参加者数の推移')
52+
f.title(text: title_text)
5053
f.xAxis(categories: data[:years])
51-
f.series(type: 'column', name: '参加者数', yAxis: 0, data: data[:increase_nums])
52-
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
54+
f.series(type: 'column', name: lang == 'en' ? 'Participants' : '参加者数', yAxis: 0, data: data[:increase_nums])
55+
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
5356
f.yAxis [
54-
{ title: { text: '参加者数' }, tickInterval: 2500, max: 12500 },
55-
{ title: { text: '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
57+
{ title: { text: lang == 'en' ? 'Participants' : '参加者数' }, tickInterval: 2500, max: 12500 },
58+
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
5659
]
5760
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
5861
f.colors(["#EF685E", "#35637D"])

app/models/stat.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ def annual_sum_of_participants
3131
@annual_sum_of_participants = year_hash_template.merge!(hash)
3232
end
3333

34-
def annual_dojos_chart
34+
def annual_dojos_chart(lang = 'ja')
3535
# MEMO: トップページの道場数と一致するように Active Dojo を集計対象としている
36-
HighChartsBuilder.build_annual_dojos(Dojo.active.annual_count(@period))
36+
HighChartsBuilder.build_annual_dojos(Dojo.active.annual_count(@period), lang)
3737
end
3838

39-
def annual_event_histories_chart
40-
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories)
39+
def annual_event_histories_chart(lang = 'ja')
40+
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories, lang)
4141
end
4242

43-
def annual_participants_chart
44-
HighChartsBuilder.build_annual_participants(annual_sum_of_participants)
43+
def annual_participants_chart(lang = 'ja')
44+
HighChartsBuilder.build_annual_participants(annual_sum_of_participants, lang)
4545
end
4646

4747
private

0 commit comments

Comments
 (0)