Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added locale date support using R18n

  • Loading branch information...
commit 26cfa737d029c31b39eb00304db730e14382b157 1 parent 72b7b1f
@rvanlieshout authored
View
1  jekyll.gemspec
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('maruku', ">= 0.5.9")
s.add_runtime_dependency('kramdown', ">= 0.13.2")
s.add_runtime_dependency('albino', ">= 1.3.2")
+ s.add_runtime_dependency('r18n-core', ">= 0.4.10")
s.add_development_dependency('redgreen', ">= 1.2.2")
s.add_development_dependency('shoulda', ">= 2.11.3")
View
3  lib/jekyll.rb
@@ -66,6 +66,9 @@ module Jekyll
'markdown' => 'maruku',
'permalink' => 'date',
+ 'locale' => 'en',
+ 'translation_path' => File.join(Dir.pwd, '_locale'),
+
'markdown_ext' => 'markdown,mkd,mkdn,md',
'textile_ext' => 'textile',
View
11 lib/jekyll/filters.rb
@@ -1,8 +1,11 @@
require 'uri'
+require 'r18n-core'
module Jekyll
module Filters
+ include R18n::Helpers
+
# Convert a Textile string into HTML output.
#
# input - The Textile String to convert.
@@ -25,22 +28,22 @@ def markdownify(input)
converter.convert(input)
end
- # Format a date in short format e.g. "27 Jan 2011".
+ # Format a date in short format e.g. "10/01/2010".
#
# date - the Time to format.
#
# Returns the formatting String.
def date_to_string(date)
- date.strftime("%d %b %Y")
+ l Date.parse(date.to_s)
end
- # Format a date in long format e.g. "27 January 2011".
+ # Format a date in long format e.g. "10th of January, 2010".
#
# date - The Time to format.
#
# Returns the formatted String.
def date_to_long_string(date)
- date.strftime("%d %B %Y")
+ l Date.parse(date.to_s), :full
end
# Format a date for use in XML.
View
3  lib/jekyll/site.rb
@@ -88,6 +88,9 @@ def setup
end.map do |c|
c.new(self.config)
end
+
+ # Set locale
+ R18n.set(config['locale'], config['translation_path'])
end
# Read Site data from disk and load it into internal data structures.
View
10 test/test_post.rb
@@ -248,7 +248,7 @@ def do_render(post)
assert_equal Time, post.date.class
assert_equal Time, post.to_liquid["date"].class
assert_equal "/2010/01/10/date-override.html", post.url
- assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
+ assert_equal "<p>Post with a front matter date</p>\n<p>10/01/2010</p>", post.output
end
should "recognize time in yaml" do
@@ -257,7 +257,7 @@ def do_render(post)
assert_equal Time, post.date.class
assert_equal Time, post.to_liquid["date"].class
assert_equal "/2010/01/10/time-override.html", post.url
- assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
+ assert_equal "<p>Post with a front matter time</p>\n<p>10/01/2010</p>", post.output
end
should "recognize time with timezone in yaml" do
@@ -266,7 +266,7 @@ def do_render(post)
assert_equal Time, post.date.class
assert_equal Time, post.to_liquid["date"].class
assert_equal "/2010/01/10/timezone-override.html", post.url
- assert_equal "<p>Post with a front matter time with timezone</p>\n<p>10 Jan 2010</p>", post.output
+ assert_equal "<p>Post with a front matter time with timezone</p>\n<p>10/01/2010</p>", post.output
end
should "to_liquid prioritizes post attributes over data" do
@@ -380,14 +380,14 @@ def do_render(post)
post = setup_post("2010-01-09-date-override.textile")
do_render(post)
- assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
+ assert_equal "<p>Post with a front matter date</p>\n<p>10/01/2010</p>", post.output
end
should "render time specified in front matter properly" do
post = setup_post("2010-01-09-time-override.textile")
do_render(post)
- assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
+ assert_equal "<p>Post with a front matter time</p>\n<p>10/01/2010</p>", post.output
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.