jekyll-localization 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  = Revision history for jekyll-localization
2
2
 
3
+ == 0.1.0 [2011-03-09]
4
+
5
+ * Added Jekyll::Localization::HUMAN_LANGUAGES and corresponding helper.
6
+ * Added helpers to deal with other languages than the current one.
7
+
3
8
  == 0.0.9 [2010-12-21]
4
9
 
5
10
  * Set YAML data too when alternative language content will be used.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to jekyll-localization version 0.0.9
5
+ This documentation refers to jekyll-localization version 0.1.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -24,7 +24,9 @@ Jekyll::Localization::LANGUAGES (e.g., +en+, +de+, +fr+):
24
24
 
25
25
  You can modify Jekyll::Localization::LANGUAGES to add languages or change
26
26
  their order. The first one is the default language and will be used when a
27
- translation is missing (+fr+ in this example).
27
+ translation is missing (+fr+ in this example). Note that, when you do add
28
+ languages and in particular when you change their order, you should adjust
29
+ Jekyll::Localization::HUMAN_LANGUAGES accordingly!
28
30
 
29
31
 
30
32
  == LINKS
@@ -43,7 +45,7 @@ RubyGem:: <http://rubygems.org/gems/jekyll-localization>
43
45
 
44
46
  == LICENSE AND COPYRIGHT
45
47
 
46
- Copyright (C) 2010 University of Cologne,
48
+ Copyright (C) 2010-2011 University of Cologne,
47
49
  Albertus-Magnus-Platz, 50923 Cologne, Germany
48
50
 
49
51
  jekyll-localization is free software: you can redistribute it and/or modify it under
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require %q{lib/jekyll/localization/version}
1
+ require File.expand_path(%q{../lib/jekyll/localization/version}, __FILE__)
2
2
 
3
3
  begin
4
4
  require 'hen'
@@ -10,9 +10,7 @@ begin
10
10
  :summary => %q{Jekyll plugin that adds localization features to the rendering engine.},
11
11
  :authors => ['Jens Wille', 'Arne Eilermann'],
12
12
  :email => ['jens.wille@uni-koeln.de', 'eilermann@lavabit.com'],
13
- :homepage => 'http://github.com/blackwinter/jekyll-localization',
14
- :files => FileList['lib/**/*.rb'].to_a,
15
- :extra_files => FileList['[A-Z]*'].to_a,
13
+ :homepage => :blackwinter,
16
14
  :dependencies => %w[jekyll-rendering]
17
15
  }
18
16
  }}
@@ -20,8 +18,6 @@ rescue LoadError => err
20
18
  warn "Please install the `hen' gem. (#{err})"
21
19
  end
22
20
 
23
- ### Place your custom Rake tasks here.
24
-
25
21
  begin
26
22
  require 'jekyll/testtasks/rake'
27
23
  rescue LoadError => err
@@ -5,8 +5,8 @@ module Jekyll
5
5
  module Version
6
6
 
7
7
  MAJOR = 0
8
- MINOR = 0
9
- TINY = 9
8
+ MINOR = 1
9
+ TINY = 0
10
10
 
11
11
  class << self
12
12
 
@@ -4,9 +4,9 @@
4
4
  # jekyll-localization -- Jekyll plugin that adds localization features to the #
5
5
  # rendering engine #
6
6
  # #
7
- # Copyright (C) 2010 University of Cologne, #
8
- # Albertus-Magnus-Platz, #
9
- # 50923 Cologne, Germany #
7
+ # Copyright (C) 2010-2011 University of Cologne, #
8
+ # Albertus-Magnus-Platz, #
9
+ # 50923 Cologne, Germany #
10
10
  # #
11
11
  # Authors: #
12
12
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -37,9 +37,19 @@ module Jekyll
37
37
  # The language codes that will be considered for translation
38
38
  LANGUAGES = %w[en de fr]
39
39
 
40
+ # The language codes mapped to their human names
41
+ HUMAN_LANGUAGES = {
42
+ 'en' => %w[English Englisch Anglais],
43
+ 'de' => %w[German Deutsch Allemand],
44
+ 'fr' => %w[French Französisch Français]
45
+ }
46
+
40
47
  # What is considered a language extension
41
48
  LANG_EXT_RE = %r{\.([a-z]{2})}
42
49
 
50
+ # The language extension, anchored at the end of the string
51
+ LANG_END_RE = %r{#{Localization::LANG_EXT_RE}\z}
52
+
43
53
  # Extract relevant parts from a file name
44
54
  LANG_PARTS_RE = %r{\A(.*?)#{LANG_EXT_RE}\.(\w+)\z}
45
55
 
@@ -126,30 +136,24 @@ module Jekyll
126
136
  alias_method :_localization_original_url, :url
127
137
 
128
138
  # Overwrites the original method to include the language extension.
129
- def url
130
- "#{_localization_original_url}#{@lang_ext}"
139
+ def url(lang = nil)
140
+ "#{_localization_original_url}#{lang ? '.' + lang : @lang_ext}"
131
141
  end
132
142
 
133
- alias_method :_localization_original_write, :write
143
+ alias_method :_localization_original_destination, :destination
134
144
 
135
145
  # Overwrites the original method to cater for language extension in output
136
146
  # file name.
137
- def write(dest_prefix, dest_suffix = nil)
138
- dest = File.join(dest_prefix, @dir)
139
- dest = File.join(dest, dest_suffix) if dest_suffix
140
- FileUtils.mkdir_p(dest)
141
-
147
+ def destination(dest)
142
148
  # The url needs to be unescaped in order to preserve the correct filename
143
- path = File.join(dest, CGI.unescape(url))
149
+ path = File.join(dest, @dir, CGI.unescape(url))
144
150
 
145
151
  if ext == '.html' && _localization_original_url !~ /\.html\z/
146
- path.sub!(/#{Localization::LANG_EXT_RE}\z/, '')
147
-
148
- FileUtils.mkdir_p(path)
149
- path = File.join(path, "index#{ext}#{@lang_ext}")
152
+ path.sub!(Localization::LANG_END_RE, '')
153
+ File.join(path, "index#{ext}#{@lang_ext}")
154
+ else
155
+ path
150
156
  end
151
-
152
- File.open(path, 'w') { |f| f.write(output) }
153
157
  end
154
158
 
155
159
  alias_method :_localization_original_process, :process
@@ -159,7 +163,7 @@ module Jekyll
159
163
  def process(name)
160
164
  self.ext = File.extname(name)
161
165
  self.basename = name[0 .. -self.ext.length-1].
162
- sub(/#{Localization::LANG_EXT_RE}\z/, '')
166
+ sub(Localization::LANG_END_RE, '')
163
167
  end
164
168
 
165
169
  end
@@ -171,7 +175,6 @@ module Jekyll
171
175
  site.posts.delete_if { |post| post.lang != lang } if lang
172
176
 
173
177
  yield
174
-
175
178
  ensure
176
179
  site.posts.replace(original_posts) if original_posts && page.lang
177
180
  end
@@ -203,6 +206,18 @@ module Jekyll
203
206
  end
204
207
  end
205
208
 
209
+ def other_langs
210
+ Localization::LANGUAGES - [lang]
211
+ end
212
+
213
+ def human_lang(lang)
214
+ t(*Localization::HUMAN_LANGUAGES[lang]) || lang.capitalize
215
+ end
216
+
217
+ def url_lang(url, lang)
218
+ url.sub(Localization::LANG_END_RE, '.' + lang)
219
+ end
220
+
206
221
  def local_posts
207
222
  localize_posts(@site, @page) { site.posts.dup }
208
223
  end
@@ -214,13 +229,15 @@ module Jekyll
214
229
  # Returns the argument whose position corresponds to the current
215
230
  # language's position in the Localization::LANGUAGES array. If that
216
231
  # particular argument is missing, +default+ is returned.
217
- def t(*translations)
232
+ def translate(*translations)
218
233
  translations.flatten!
219
234
 
220
235
  index = Localization::LANGUAGES.index(lang)
221
236
  index && translations[index] || translations.first
222
237
  end
223
238
 
239
+ alias_method :t, :translate
240
+
224
241
  end
225
242
 
226
243
  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: 13
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-21 00:00:00 +01:00
19
+ date: 2011-03-09 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -42,31 +42,30 @@ executables: []
42
42
  extensions: []
43
43
 
44
44
  extra_rdoc_files:
45
+ - README
45
46
  - COPYING
46
47
  - ChangeLog
47
- - README
48
48
  files:
49
- - lib/jekyll/localization/version.rb
50
49
  - lib/jekyll/localization.rb
50
+ - lib/jekyll/localization/version.rb
51
+ - README
52
+ - ChangeLog
51
53
  - Rakefile
52
54
  - COPYING
53
- - ChangeLog
54
- - README
55
55
  has_rdoc: true
56
56
  homepage: http://github.com/blackwinter/jekyll-localization
57
57
  licenses: []
58
58
 
59
59
  post_install_message:
60
60
  rdoc_options:
61
+ - --charset
62
+ - UTF-8
61
63
  - --title
62
- - jekyll-localization Application documentation
64
+ - jekyll-localization Application documentation (v0.1.0)
63
65
  - --main
64
66
  - README
65
- - --line-numbers
66
- - --inline-source
67
67
  - --all
68
- - --charset
69
- - UTF-8
68
+ - --line-numbers
70
69
  require_paths:
71
70
  - lib
72
71
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -90,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
89
  requirements: []
91
90
 
92
91
  rubyforge_project:
93
- rubygems_version: 1.3.7
92
+ rubygems_version: 1.6.2
94
93
  signing_key:
95
94
  specification_version: 3
96
95
  summary: Jekyll plugin that adds localization features to the rendering engine.