Skip to content

Commit ed6eeeb

Browse files
committed
Introduce some localizations into the news plugin
Localize the titles of the news page and the yearly/monthly archives pages. Leave the date unchanged (format and month names).
1 parent 5c452c2 commit ed6eeeb

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

_plugins/news.rb

+21-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def initialize(site,base,lang,year,month,posts)
4242
@month = month
4343
@dir = File.join(@dir,@year.to_s,"%.2d" % @month)
4444

45-
data['title'] = "#{MONTHS[@month]} #{@year} Archives"
45+
if site.config['locales']['news'][lang]
46+
title = site.config['locales']['news'][lang]['archive_title']
47+
else
48+
title = site.config['locales']['news']['en']['archive_title']
49+
end
50+
51+
data['title'] = "#{title['prefix']} #{MONTHS[@month]} #{@year} #{title['postfix']}".strip
4652
data['year'] = year
4753
end
4854

@@ -58,7 +64,13 @@ def initialize(site,base,lang,year,posts)
5864
@year = year
5965
@dir = File.join(@dir,@year.to_s)
6066

61-
data['title'] = "#{@year} Archives"
67+
if site.config['locales']['news'][lang]
68+
title = site.config['locales']['news'][lang]['archive_title']
69+
else
70+
title = site.config['locales']['news']['en']['archive_title']
71+
end
72+
73+
data['title'] = "#{title['prefix']} #{@year} #{title['postfix']}".strip
6274

6375
months = posts.map { |post| post.date.month }.uniq
6476

@@ -81,7 +93,13 @@ class Index < ArchivePage
8193
def initialize(site,base,lang,posts)
8294
super(site,base,LAYOUT,lang,posts)
8395

84-
data['title'] = 'Recent News'
96+
if site.config['locales']['news'][lang]
97+
title = site.config['locales']['news'][lang]['recent_news']
98+
else
99+
title = site.config['locales']['news']['en']['recent_news']
100+
end
101+
102+
data['title'] = title
85103
data['years'] = posts.map { |post| post.date.year }.uniq.reverse
86104
data['posts'] = posts.last(MAX_POSTS).reverse
87105
end

0 commit comments

Comments
 (0)