jekyll_i18n_multi_page 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c5ddb36f4854a6045602943d170083ee5c51d1d48af49d295e6df760853e652
4
+ data.tar.gz: 3df4b08e1376a156a9598282c647be92ceccd6e9e16d915a8db44d21f96576ec
5
+ SHA512:
6
+ metadata.gz: 979de192576658b9386ecddf2dfe9a13e0f281681c05499bb39926f563f247def71ec374ba143542074a58956444b3be1aca6a8ecdb0ef94ad7ccaa4f02b4cb9
7
+ data.tar.gz: 59038f63b591d94c69432eb7924e81ee2340e0c8adf14eea962cedb664b3326dc8a6dd0ef27b5c644253a9232009f143497b633597bc94f7b05f52f3bc3c63b4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/dist/
9
+ /tmp/
10
+ /pkg/
11
+ .idea
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ script:
8
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in jekyll_i18n_multi_page.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll_i18n_multi_page (0.1.0)
5
+ activesupport (~> 6.0)
6
+ i18n (~> 1.6)
7
+ jekyll (~> 3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.0.0)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.1, >= 2.1.8)
18
+ addressable (2.6.0)
19
+ public_suffix (>= 2.0.2, < 4.0)
20
+ coderay (1.1.2)
21
+ colorator (1.1.0)
22
+ concurrent-ruby (1.1.5)
23
+ diff-lcs (1.3)
24
+ docile (1.3.2)
25
+ ffi (1.11.1)
26
+ forwardable-extended (2.6.0)
27
+ i18n (1.6.0)
28
+ concurrent-ruby (~> 1.0)
29
+ jekyll (3.6.3)
30
+ addressable (~> 2.4)
31
+ colorator (~> 1.0)
32
+ jekyll-sass-converter (~> 1.0)
33
+ jekyll-watch (~> 1.1)
34
+ kramdown (~> 1.14)
35
+ liquid (~> 4.0)
36
+ mercenary (~> 0.3.3)
37
+ pathutil (~> 0.9)
38
+ rouge (>= 1.7, < 3)
39
+ safe_yaml (~> 1.0)
40
+ jekyll-sass-converter (1.5.2)
41
+ sass (~> 3.4)
42
+ jekyll-watch (1.5.1)
43
+ listen (~> 3.0)
44
+ json (2.2.0)
45
+ kramdown (1.17.0)
46
+ liquid (4.0.3)
47
+ listen (3.1.5)
48
+ rb-fsevent (~> 0.9, >= 0.9.4)
49
+ rb-inotify (~> 0.9, >= 0.9.7)
50
+ ruby_dep (~> 1.2)
51
+ mercenary (0.3.6)
52
+ method_source (0.9.2)
53
+ minitest (5.11.3)
54
+ pathutil (0.16.2)
55
+ forwardable-extended (~> 2.6)
56
+ pry (0.12.2)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.9.0)
59
+ public_suffix (3.1.1)
60
+ rake (10.5.0)
61
+ rb-fsevent (0.10.3)
62
+ rb-inotify (0.10.0)
63
+ ffi (~> 1.0)
64
+ rouge (2.2.1)
65
+ rspec (3.8.0)
66
+ rspec-core (~> 3.8.0)
67
+ rspec-expectations (~> 3.8.0)
68
+ rspec-mocks (~> 3.8.0)
69
+ rspec-core (3.8.2)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-expectations (3.8.4)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.8.0)
74
+ rspec-mocks (3.8.1)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-support (3.8.2)
78
+ ruby_dep (1.5.0)
79
+ safe_yaml (1.0.5)
80
+ sass (3.7.4)
81
+ sass-listen (~> 4.0.0)
82
+ sass-listen (4.0.0)
83
+ rb-fsevent (~> 0.9, >= 0.9.4)
84
+ rb-inotify (~> 0.9, >= 0.9.7)
85
+ simplecov (0.17.0)
86
+ docile (~> 1.1)
87
+ json (>= 1.8, < 3)
88
+ simplecov-html (~> 0.10.0)
89
+ simplecov-html (0.10.2)
90
+ thread_safe (0.3.6)
91
+ tzinfo (1.2.5)
92
+ thread_safe (~> 0.1)
93
+ zeitwerk (2.1.9)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bundler (~> 1.17)
100
+ jekyll_i18n_multi_page!
101
+ pry (~> 0.12)
102
+ rake (~> 10.0)
103
+ rspec (~> 3.0)
104
+ simplecov (~> 0.17)
105
+
106
+ BUNDLED WITH
107
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yi Feng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Jekyll I18n MultiPage
2
+
3
+ Generate multiple pages for different locales based on single template.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'jekyll_i18n_multi_page'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Add the plugin to `_config.yml` file:
18
+
19
+ ```yml
20
+ plugins:
21
+ - jekyll_i18n_multi_page
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Declare available locales in your website in `_config.yml`:
27
+
28
+ ```yml
29
+ i18n:
30
+ - path: /
31
+ locale: en
32
+ - path: /tw
33
+ locale: zh-TW
34
+ ```
35
+
36
+ For each entry must contain `path`(the output of localized page) and `locale`.
37
+
38
+ Define files with localized contents in `_i18n` folder, filenames aren't mattered. For examples:
39
+
40
+ ```yml
41
+ # _i18n/my-en-site.yml
42
+ en:
43
+ index:
44
+ title: English title
45
+ hello: Hello
46
+ ```
47
+
48
+ ```yml
49
+ # _i18n/my-tw-site.yml
50
+ zh-TW:
51
+ index:
52
+ title: 中文標題
53
+ hello: 哈囉
54
+ ```
55
+
56
+ `page.i18n` is the way to access the current localized contents, said you have a HTML named `index.html` with content as the following:
57
+ ```html
58
+ ---
59
+ ---
60
+ {{ page.i18n.hello }}
61
+ ```
62
+
63
+ After building of Jekyll, the dist folder should have two files `index.html` and `tw/index.html`
64
+
65
+ Assume you have a file named `some/where/my.html` you should have its path in the localization file:
66
+ ```yml
67
+ # _i18n/my-en-site.yml
68
+ en:
69
+ some:
70
+ where:
71
+ my:
72
+ hello: Hello # access this text via page.i18n.hello
73
+ ```
74
+
75
+ ## Use cases
76
+
77
+ **For some reason, I have a page which is only available for certain locales**
78
+
79
+ ```html
80
+ ---
81
+ i18n_locales: ['zh-TW']
82
+ ---
83
+ {{ page.i18n.hello }}
84
+ ```
85
+ Using `i18n_locales` to declare the support locales. Then Jekyll will build `tw/index.html` file only.
86
+
87
+ **How to disable the features on certain pages**
88
+
89
+ ```html
90
+ ---
91
+ i18n_disabled: true
92
+ ---
93
+ ```
94
+ Using `i18n_disabled` to tell the plugin do not do anything for me.
95
+
96
+ **Translate helper**
97
+
98
+ ```
99
+ {% t index.hello %}
100
+ ```
101
+ `t` tag provides a way to translate content. When you take this way, you must write a full path.
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yfxie/jekyll_i18n_multi_page.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll_i18n_multi_page"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jekyll_i18n_multi_page/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll_i18n_multi_page"
8
+ spec.version = JekyllI18nMultiPage::VERSION
9
+ spec.authors = ["Yi Feng"]
10
+ spec.email = ["yfxie@me.com"]
11
+
12
+ spec.summary = %q{Jekyll plugin for handling I18n multiple pages.}
13
+ spec.description = %q{Generate multiple pages for different locales based on single template.}
14
+ spec.homepage = "https://github.com/yfxie/jekyll_i18n_multi_page"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry", "~> 0.12"
29
+ spec.add_development_dependency "simplecov", "~> 0.17"
30
+ spec.add_dependency "jekyll", "~> 3.0"
31
+ spec.add_dependency "i18n", "~> 1.6"
32
+ spec.add_dependency "activesupport", "~> 6.0"
33
+ end
@@ -0,0 +1,22 @@
1
+ module JekyllI18nMultiPage
2
+ module PageExtension
3
+ def translate_key
4
+ path.gsub('/','.')
5
+ .gsub(/\.(html|md)$/,'')
6
+ end
7
+
8
+ def i18n_disabled
9
+ data['i18n_disabled']
10
+ end
11
+
12
+ def template
13
+ return super if i18n_disabled
14
+ "/:i18n_path#{super}"
15
+ end
16
+
17
+ def url_placeholders
18
+ return super if i18n_disabled
19
+ super.merge({ i18n_path: data['i18n_path'] })
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module JekyllI18nMultiPage
2
+ class TranslateTag < Liquid::Tag
3
+ attr_accessor :markup
4
+
5
+ def initialize(tag_name, translate_path, tokens)
6
+ super
7
+ @translate_path = translate_path.strip
8
+ end
9
+
10
+ def render(context)
11
+ I18n.t(@translate_path, locale: context['page']['i18n_locale'])
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllI18nMultiPage
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'jekyll'
2
+ require 'i18n'
3
+ require 'active_support/core_ext/hash'
4
+ require 'jekyll_i18n_multi_page/version'
5
+ require 'jekyll_i18n_multi_page/page_extension'
6
+ require 'jekyll_i18n_multi_page/translate_tag'
7
+
8
+ module JekyllI18nMultiPage; end
9
+
10
+
11
+ Jekyll::Page.class_eval do
12
+ prepend JekyllI18nMultiPage::PageExtension
13
+ end
14
+
15
+ Jekyll::Hooks.register :site, :after_init do |site|
16
+ I18n.load_path << Dir[File.join(site.config['source'], '_i18n', '**/*.{yml,yaml}')]
17
+ end
18
+
19
+ Jekyll::Hooks.register :site, :post_read do |site|
20
+ config = site.config['i18n']
21
+
22
+ locale_config_mappings = config.reduce({}) do |map, config|
23
+ map[config['locale']] = config
24
+ map
25
+ end
26
+
27
+ site.pages = site.pages.flat_map do |page|
28
+ next page if page.i18n_disabled
29
+
30
+ locales = page.data['i18n_locales'] || locale_config_mappings.keys
31
+ locales.map do |locale|
32
+ config = locale_config_mappings[locale]
33
+ i18n_hash = I18n.t(page.translate_key, locale: locale)
34
+ data = page.data.clone.tap do |data|
35
+ data['i18n_locale'] = locale
36
+ data['i18n'] = i18n_hash.is_a?(Hash) ? i18n_hash.with_indifferent_access : {}
37
+ data['i18n_path'] = config['path']
38
+ end
39
+ page.clone.tap do |p|
40
+ p.data = data
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Liquid::Template.register_tag('t', JekyllI18nMultiPage::TranslateTag)
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_i18n_multi_page
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yi Feng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jekyll
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: i18n
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.6'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '6.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '6.0'
125
+ description: Generate multiple pages for different locales based on single template.
126
+ email:
127
+ - yfxie@me.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".ruby-version"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - jekyll_i18n_multi_page.gemspec
144
+ - lib/jekyll_i18n_multi_page.rb
145
+ - lib/jekyll_i18n_multi_page/page_extension.rb
146
+ - lib/jekyll_i18n_multi_page/translate_tag.rb
147
+ - lib/jekyll_i18n_multi_page/version.rb
148
+ homepage: https://github.com/yfxie/jekyll_i18n_multi_page
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Jekyll plugin for handling I18n multiple pages.
171
+ test_files: []