jekyll-localization 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -0
- data/README +13 -5
- data/lib/jekyll/localization.rb +31 -31
- data/lib/jekyll/localization/version.rb +1 -1
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
= Revision history for jekyll-localization
|
2
2
|
|
3
|
+
== 0.0.2 [2010-07-01]
|
4
|
+
|
5
|
+
* Refactoring and documentation.
|
6
|
+
* Jekyll::LANGUAGES now lives in Jekyll::Localization::LANGUAGES
|
7
|
+
* New constant Jekyll::Localization::LANG_EXT_RE
|
8
|
+
* Directory name should *NOT* contain language extension
|
9
|
+
* Turned #t method into a filter (should work for Liquid, too?)
|
10
|
+
* Credits.
|
11
|
+
|
3
12
|
== 0.0.1 [2010-06-30]
|
4
13
|
|
5
14
|
* Birthday :-)
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to jekyll-localization version 0.0.
|
5
|
+
This documentation refers to jekyll-localization version 0.0.2
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -13,15 +13,17 @@ Add the following to your <tt>_plugins/ext.rb</tt> file:
|
|
13
13
|
|
14
14
|
require 'jekyll-localization'
|
15
15
|
|
16
|
-
Then start using
|
17
|
-
language from the file
|
18
|
-
|
16
|
+
Then start using Jekyll::Filters#t in your templates, which will extract
|
17
|
+
the target language from the file name (<tt><NAME>.<LANG>.<EXT></tt>,
|
18
|
+
where +LANG+ is supposed to be a two-letter language code). The order
|
19
|
+
of the arguments corresponds to the order of the languages defined in
|
20
|
+
Localization::LANGUAGES (e.g., +en+, +de+, +fr+):
|
19
21
|
|
20
22
|
Some <%= t 'translated', 'übersetzter' %> text.
|
21
23
|
|
22
24
|
You can modify Jekyll::LANGUAGES to add languages or change their order.
|
23
25
|
The first one is the default language and will be used when a translation
|
24
|
-
is missing.
|
26
|
+
is missing (+fr+ in this example).
|
25
27
|
|
26
28
|
|
27
29
|
== LINKS
|
@@ -37,6 +39,12 @@ RubyGem:: <http://rubygems.org/gems/jekyll-localization>
|
|
37
39
|
* Jens Wille <mailto:jens.wille@uni-koeln.de>
|
38
40
|
|
39
41
|
|
42
|
+
== CREDITS
|
43
|
+
|
44
|
+
* Arne Eilermann <mailto:arne.eilermann@uni-koeln.de> for the original idea
|
45
|
+
and implementation.
|
46
|
+
|
47
|
+
|
40
48
|
== LICENSE AND COPYRIGHT
|
41
49
|
|
42
50
|
Copyright (C) 2010 University of Cologne,
|
data/lib/jekyll/localization.rb
CHANGED
@@ -32,29 +32,39 @@ require 'jekyll/rendering'
|
|
32
32
|
|
33
33
|
module Jekyll
|
34
34
|
|
35
|
-
LANGUAGES = %w[en de fr]
|
36
|
-
|
37
35
|
module Localization
|
36
|
+
|
37
|
+
# The language codes that will be considered for translation
|
38
|
+
LANGUAGES = %w[en de fr]
|
39
|
+
|
40
|
+
# What is considered a language extension
|
41
|
+
LANG_EXT_RE = %r{\.([a-z]{2})}
|
42
|
+
|
38
43
|
end
|
39
44
|
|
40
45
|
class Page
|
41
46
|
|
42
47
|
alias_method :_localization_original_initialize, :initialize
|
43
48
|
|
49
|
+
# Overwrites the original method to extract the language extension.
|
44
50
|
def initialize(site, base, dir, name)
|
45
51
|
_localization_original_initialize(site, base, dir, name)
|
46
52
|
|
47
|
-
@lang = data['lang'] = @name[
|
53
|
+
@lang = data['lang'] = @name[/#{Localization::LANG_EXT_RE}\.\w+\z/, 1]
|
54
|
+
@lang_ext = ".#{@lang}" if @lang
|
48
55
|
end
|
49
56
|
|
50
57
|
alias_method :_localization_original_url, :url
|
51
58
|
|
59
|
+
# Overwrites the original method to include the language extension.
|
52
60
|
def url
|
53
|
-
|
61
|
+
"#{_localization_original_url}#{@lang_ext}"
|
54
62
|
end
|
55
63
|
|
56
64
|
alias_method :_localization_original_write, :write
|
57
65
|
|
66
|
+
# Overwrites the original method to cater for language extension in output
|
67
|
+
# file name.
|
58
68
|
def write(dest_prefix, dest_suffix = nil)
|
59
69
|
dest = File.join(dest_prefix, @dir)
|
60
70
|
dest = File.join(dest, dest_suffix) if dest_suffix
|
@@ -62,45 +72,35 @@ module Jekyll
|
|
62
72
|
|
63
73
|
# The url needs to be unescaped in order to preserve the correct filename
|
64
74
|
path = File.join(dest, CGI.unescape(url))
|
65
|
-
if ext == '.html' && url !~ /\.html(?:\.[a-z]{2})?\z/
|
66
|
-
FileUtils.mkdir_p(path)
|
67
|
-
path = File.join(path, "index#{@lang ? "#{ext}.#{@lang}" : ext}")
|
68
|
-
end
|
69
75
|
|
70
|
-
|
71
|
-
|
76
|
+
if ext == '.html' && _localization_original_url !~ /\.html\z/
|
77
|
+
path.sub!(/#{Localization::LANG_EXT_RE}\z/, '')
|
72
78
|
|
73
|
-
|
74
|
-
|
75
|
-
module Engine
|
76
|
-
|
77
|
-
class Erb
|
78
|
-
|
79
|
-
def t(*translations)
|
80
|
-
index = LANGUAGES.index(page.lang)
|
81
|
-
index && translations[index] || translations.first
|
79
|
+
FileUtils.mkdir_p(path)
|
80
|
+
path = File.join(path, "index#{ext}#{@lang_ext}")
|
82
81
|
end
|
83
82
|
|
83
|
+
File.open(path, 'w') { |f| f.write(output) }
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
# FIXME: dunno if it works...
|
88
|
+
module Filters
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
# call-seq:
|
91
|
+
# t 'default', 'translation', ... => aString (Ruby-style)
|
92
|
+
# ['default', 'translation', ...] | t => aString (Liquid-style)
|
93
|
+
#
|
94
|
+
# Returns the argument whose position corresponds to the current
|
95
|
+
# language's position in the Localization::LANGUAGES array. If that
|
96
|
+
# particular argument is missing, +default+ is returned.
|
97
|
+
def t(*translations)
|
98
|
+
translations.flatten!
|
96
99
|
|
97
|
-
|
98
|
-
index
|
99
|
-
index && @translations[index] || @translations.first
|
100
|
+
index = Localization::LANGUAGES.index(page.lang)
|
101
|
+
index && translations[index] || translations.first
|
100
102
|
end
|
101
103
|
|
102
|
-
Liquid::Template.register_tag('t', self)
|
103
|
-
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-localization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jens Wille
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-01 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|