jekyll-locale_sgh 0.5.2
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/lib/jekyll-locale.rb +47 -0
- data/lib/jekyll/locale/auto_page.rb +28 -0
- data/lib/jekyll/locale/date_time_handler.rb +61 -0
- data/lib/jekyll/locale/document.rb +36 -0
- data/lib/jekyll/locale/drop.rb +10 -0
- data/lib/jekyll/locale/filters.rb +39 -0
- data/lib/jekyll/locale/handler.rb +210 -0
- data/lib/jekyll/locale/identity.rb +17 -0
- data/lib/jekyll/locale/mixins/helper.rb +57 -0
- data/lib/jekyll/locale/mixins/support.rb +41 -0
- data/lib/jekyll/locale/page.rb +28 -0
- data/lib/jekyll/locale/version.rb +7 -0
- data/lib/jekyll/patches/site.rb +15 -0
- data/lib/jekyll/patches/utils.rb +22 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd84ec51b9857cf1c667cd8ae469f775b05faa65939e52d4dfd9ee91393208db
|
4
|
+
data.tar.gz: 19967b20e45e6b449f9c9042a4dbfcc3f1a8e17ddbf263432917c03c517e0c06
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3198bfd0fd8e3a6500be066531a81a8133f36c36511856f223277cdb87aa71e89821ab29ad5f4106b621174866e534dea13e38b37c08dd00d23dc0d2378f561
|
7
|
+
data.tar.gz: d0b23bb078040c3b59a164d027ddd8d80b114c133280748cf100c6ace50a59a748148dcb63009c0ad62729df2f090ce8e8f0bbfbbb76e73e6e20e4c20d4de659
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ashwin Maroli
|
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,23 @@
|
|
1
|
+
# Jekyll Locale
|
2
|
+
|
3
|
+
[][travis]
|
4
|
+
[][appveyor]
|
5
|
+
[][maintainability]
|
6
|
+
[][test_coverage]
|
7
|
+
|
8
|
+
[travis]: https://travis-ci.org/ashmaroli/jekyll-locale
|
9
|
+
[appveyor]: https://ci.appveyor.com/project/ashmaroli/jekyll-locale/branch/master
|
10
|
+
[maintainability]: https://codeclimate.com/github/ashmaroli/jekyll-locale/maintainability
|
11
|
+
[test_coverage]: https://codeclimate.com/github/ashmaroli/jekyll-locale/test_coverage
|
12
|
+
|
13
|
+
A localization plugin for Jekyll.
|
14
|
+
|
15
|
+
|
16
|
+
## Features
|
17
|
+
|
18
|
+
* Exposes a `{{ locale }}` object for your Liquid templates that can be used to "translate" strings in your site easily.
|
19
|
+
* Depending on configured `mode`, the plugin either generates a *copy* of every page that renders into a HTML file, and
|
20
|
+
every document set to be written, and renders them into dedicated urls prepended by a supported locale, or, the plugin
|
21
|
+
"processes" only those files placed inside the plugin's configured **`content_dir`** .
|
22
|
+
|
23
|
+
Read through the [documentation](https://jekyll-locale.netlify.com/) for details.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale
|
5
|
+
autoload :Drop, "jekyll/locale/drop"
|
6
|
+
autoload :Document, "jekyll/locale/document"
|
7
|
+
autoload :AutoPage, "jekyll/locale/auto_page"
|
8
|
+
autoload :Page, "jekyll/locale/page"
|
9
|
+
autoload :Handler, "jekyll/locale/handler"
|
10
|
+
autoload :Identity, "jekyll/locale/identity"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative "jekyll/patches/site"
|
15
|
+
require_relative "jekyll/patches/utils"
|
16
|
+
|
17
|
+
require_relative "jekyll/locale/date_time_handler"
|
18
|
+
require_relative "jekyll/locale/filters"
|
19
|
+
|
20
|
+
require_relative "jekyll/locale/mixins/support"
|
21
|
+
require_relative "jekyll/locale/mixins/helper"
|
22
|
+
|
23
|
+
# Enhance Jekyll::Page and Jekyll::Document classes
|
24
|
+
[Jekyll::Page, Jekyll::Document].each do |klass|
|
25
|
+
klass.include Jekyll::Locale::Support
|
26
|
+
end
|
27
|
+
|
28
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
29
|
+
handler = site.locale_handler
|
30
|
+
handler.reset
|
31
|
+
I18n.config.enforce_available_locales = false
|
32
|
+
end
|
33
|
+
|
34
|
+
Jekyll::Hooks.register :site, :post_read do |site|
|
35
|
+
handler = site.locale_handler
|
36
|
+
handler.setup
|
37
|
+
handler.read
|
38
|
+
end
|
39
|
+
|
40
|
+
Jekyll::Hooks.register [:pages, :documents], :pre_render do |document, payload|
|
41
|
+
handler = document.site.locale_handler
|
42
|
+
handler.current_locale = document.locale
|
43
|
+
document.setup_hreflangs if document.setup_hreflangs?
|
44
|
+
payload["page"]["locale"] = document.locale || handler.default_locale
|
45
|
+
payload["page"]["hreflangs"] = document.hreflangs
|
46
|
+
payload["page"]["locale_siblings"] = document.locale_siblings
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::AutoPage < Page
|
5
|
+
include Locale::Helper
|
6
|
+
|
7
|
+
attr_reader :path
|
8
|
+
attr_accessor :data, :content, :output
|
9
|
+
|
10
|
+
def initialize(canon, locale)
|
11
|
+
setup(canon, locale)
|
12
|
+
@path = canon.path
|
13
|
+
@content = canon.content
|
14
|
+
@data = canon.data
|
15
|
+
@name = File.basename(@path)
|
16
|
+
@relative_path = canon.relative_path
|
17
|
+
process(@name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
@url ||= File.join("", locale.id, canon.url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_liquid
|
25
|
+
@to_liquid ||= configure_payload(canon.to_liquid)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale::DateTimeHandler
|
5
|
+
DATETIME_DEFAULTS = {
|
6
|
+
:date => {
|
7
|
+
:day_names => Date::DAYNAMES,
|
8
|
+
:month_names => Date::MONTHNAMES,
|
9
|
+
:abbr_day_names => Date::ABBR_DAYNAMES,
|
10
|
+
:abbr_month_names => Date::ABBR_MONTHNAMES,
|
11
|
+
},
|
12
|
+
:time => {
|
13
|
+
:am => "am",
|
14
|
+
:pm => "pm",
|
15
|
+
:formats => {
|
16
|
+
:default => "%B %d, %Y %l:%M:%S %p %z",
|
17
|
+
},
|
18
|
+
},
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
class << self
|
22
|
+
extend Forwardable
|
23
|
+
[:config, :backend].each do |method|
|
24
|
+
private def_delegator I18n, method
|
25
|
+
end
|
26
|
+
|
27
|
+
def bootstrap(handler)
|
28
|
+
@handler = handler
|
29
|
+
config.available_locales = @handler.available_locales
|
30
|
+
end
|
31
|
+
|
32
|
+
def localize(input, format)
|
33
|
+
object = date_cache(input)
|
34
|
+
locale = @handler.current_locale.id.to_sym
|
35
|
+
data = @handler.locale_dates[locale.to_s] || {}
|
36
|
+
store_translations(locale, data) unless translations.key?(locale)
|
37
|
+
backend.localize(locale, object, format)
|
38
|
+
end
|
39
|
+
|
40
|
+
def store_translations(locale, data)
|
41
|
+
backend.store_translations(
|
42
|
+
locale,
|
43
|
+
Utils.deep_merge_hashes(
|
44
|
+
DATETIME_DEFAULTS, Utils.recursive_symbolize_hash_keys(data)
|
45
|
+
)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def translations
|
52
|
+
backend.send(:translations)
|
53
|
+
end
|
54
|
+
|
55
|
+
def date_cache(input)
|
56
|
+
@date_cache ||= {}
|
57
|
+
@date_cache[input] ||= Liquid::Utils.to_date(input)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::Document < Document
|
5
|
+
attr_reader :type
|
6
|
+
include Locale::Helper
|
7
|
+
|
8
|
+
def initialize(canon, locale)
|
9
|
+
setup(canon, locale)
|
10
|
+
@collection = canon.collection
|
11
|
+
@extname = File.extname(relative_path)
|
12
|
+
@has_yaml_header = nil
|
13
|
+
@type = @collection.label.to_sym
|
14
|
+
read
|
15
|
+
|
16
|
+
special_dir = draft? ? "_drafts" : @collection.relative_directory
|
17
|
+
categories_from_path(special_dir)
|
18
|
+
|
19
|
+
configure_data
|
20
|
+
end
|
21
|
+
|
22
|
+
def cleaned_relative_path
|
23
|
+
@cleaned_relative_path ||= begin
|
24
|
+
rel_path = relative_path[0..-extname.length - 1]
|
25
|
+
rel_path.sub!(@locale_page_dir, "")
|
26
|
+
rel_path.sub!(collection.relative_directory, "")
|
27
|
+
rel_path.gsub!(%r!\.*\z!, "")
|
28
|
+
rel_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def url_template
|
33
|
+
@url_template ||= File.join("", locale.id, super)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale
|
5
|
+
module Filters
|
6
|
+
def localize_date(input, format = :default)
|
7
|
+
format = symbol_or_strftime(format)
|
8
|
+
DateTimeHandler.localize(time(input), format)
|
9
|
+
end
|
10
|
+
|
11
|
+
def prefix_locale(input)
|
12
|
+
return input unless input.is_a?(String)
|
13
|
+
return input if Addressable::URI.parse(input).absolute?
|
14
|
+
|
15
|
+
handler = @context.registers[:site].locale_handler
|
16
|
+
page_locale = @context.registers[:page]["locale"]
|
17
|
+
page_locale = "" if page_locale.id == handler.default_locale.id
|
18
|
+
File.join("/", page_locale.to_s, input).squeeze("/")
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def symbol_or_strftime(format)
|
24
|
+
return format if format.is_a?(Symbol)
|
25
|
+
|
26
|
+
format = format.to_s
|
27
|
+
if format.start_with?(":")
|
28
|
+
format.sub(":", "").to_sym
|
29
|
+
elsif format.start_with?("%")
|
30
|
+
format
|
31
|
+
else
|
32
|
+
:default
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Liquid::Template.register_filter(Jekyll::Locale::Filters)
|
@@ -0,0 +1,210 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::Handler
|
5
|
+
attr_reader :default_locale, :available_locales, :locale_dates, :content_dirname,
|
6
|
+
:user_locales
|
7
|
+
attr_writer :current_locale
|
8
|
+
|
9
|
+
DEFAULT_CONFIG = {
|
10
|
+
"mode" => "manual",
|
11
|
+
"locale" => "en-US",
|
12
|
+
"data_dir" => "locales",
|
13
|
+
"content_dir" => "_locales",
|
14
|
+
"locales_set" => [],
|
15
|
+
"exclude_set" => [],
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def initialize(site)
|
19
|
+
@site = site
|
20
|
+
config = site.config["localization"]
|
21
|
+
@config = if config.is_a?(Hash)
|
22
|
+
Jekyll::Utils.deep_merge_hashes(DEFAULT_CONFIG, config)
|
23
|
+
else
|
24
|
+
DEFAULT_CONFIG
|
25
|
+
end
|
26
|
+
initialize_locales
|
27
|
+
@content_dirname = mode == "auto" ? "" : fetch("content_dir")
|
28
|
+
@snakeified_keys = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
@locale_data = {}
|
33
|
+
@locale_dates = {}
|
34
|
+
@portfolio = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
Locale::DateTimeHandler.bootstrap(self)
|
39
|
+
setup_data if @locale_data.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def data
|
43
|
+
locale_data[snakeified_keys(current_locale)] ||
|
44
|
+
locale_data[snakeified_keys(default_locale)] || {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def read
|
48
|
+
mode == "auto" ? auto_localization : manual_localization
|
49
|
+
end
|
50
|
+
|
51
|
+
def current_locale
|
52
|
+
@current_locale ||= default_locale
|
53
|
+
end
|
54
|
+
|
55
|
+
def inspect
|
56
|
+
"#<#{self.class} @site=#{site}>"
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_reader :site, :config, :locale_data
|
62
|
+
|
63
|
+
def setup_data
|
64
|
+
locales_dir = fetch("data_dir")
|
65
|
+
base_data = site.site_data[locales_dir]
|
66
|
+
return @locale_data unless base_data.is_a?(Hash)
|
67
|
+
|
68
|
+
base_data.each do |locale_id, data|
|
69
|
+
next unless data.is_a?(Hash)
|
70
|
+
process_locale_data(locale_id, data)
|
71
|
+
end
|
72
|
+
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize_locales
|
77
|
+
default_locale_id = fetch("locale")
|
78
|
+
default_metadata = {}
|
79
|
+
@available_locales = [default_locale_id]
|
80
|
+
@user_locales = []
|
81
|
+
|
82
|
+
locales_set_config = @config["locales_set"]
|
83
|
+
locales_set_config = case locales_set_config
|
84
|
+
when Array
|
85
|
+
Hash[locales_set_config.map { |locale| [locale, {}] }]
|
86
|
+
when Hash
|
87
|
+
locales_set_config
|
88
|
+
else
|
89
|
+
{}
|
90
|
+
end
|
91
|
+
|
92
|
+
locales_set_config.each do |locale_id, metadata|
|
93
|
+
if locale_id == default_locale_id
|
94
|
+
default_metadata = metadata
|
95
|
+
next
|
96
|
+
end
|
97
|
+
|
98
|
+
@available_locales << locale_id
|
99
|
+
@user_locales << Locale::Identity.new(locale_id, metadata)
|
100
|
+
end
|
101
|
+
|
102
|
+
@default_locale = Locale::Identity.new(default_locale_id, default_metadata)
|
103
|
+
end
|
104
|
+
|
105
|
+
def process_locale_data(loc, data_hash)
|
106
|
+
locale = snakeified_keys(loc)
|
107
|
+
@locale_data[locale] = {}
|
108
|
+
|
109
|
+
date_data = Locale::DateTimeHandler::DATETIME_DEFAULTS
|
110
|
+
data_hash.each do |key, value|
|
111
|
+
if key == "locale_date"
|
112
|
+
date_data = configure_locale_date(date_data, value)
|
113
|
+
else
|
114
|
+
@locale_data[locale][snakeified_keys(key)] = value
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@locale_dates[loc] = date_data
|
118
|
+
end
|
119
|
+
|
120
|
+
def configure_locale_date(date_defaults, data)
|
121
|
+
return date_defaults unless data.is_a?(Hash)
|
122
|
+
|
123
|
+
Jekyll::Utils.deep_merge_hashes(
|
124
|
+
date_defaults, Utils.recursive_symbolize_hash_keys(data)
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Instances of Jekyll class that include `Jekyll::Locale::Support` mixin
|
129
|
+
# (which are simply Jekyll::Page and Jekyll::Document)
|
130
|
+
def portfolio
|
131
|
+
@portfolio ||= begin
|
132
|
+
html_pages = site.site_payload["site"]["html_pages"] || []
|
133
|
+
html_pages.reject! { |page| page.name == "404.html" }
|
134
|
+
|
135
|
+
(site.docs_to_write + html_pages).select do |doc|
|
136
|
+
doc.is_a?(Jekyll::Locale::Support)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def auto_localization
|
142
|
+
user_locales.each do |locale|
|
143
|
+
portfolio.each do |canon_doc|
|
144
|
+
next if canon_doc.relative_path =~ exclusion_regex
|
145
|
+
append_page(Locale::AutoPage, canon_doc, locale)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def manual_localization
|
151
|
+
user_locales.each do |locale|
|
152
|
+
portfolio.each do |canon_doc|
|
153
|
+
loc_page_path = site.in_source_dir(content_dirname, locale.id, canon_doc.relative_path)
|
154
|
+
next unless File.exist?(loc_page_path)
|
155
|
+
next unless Jekyll::Utils.has_yaml_header?(loc_page_path)
|
156
|
+
|
157
|
+
case canon_doc
|
158
|
+
when Jekyll::Page
|
159
|
+
append_page(Locale::Page, canon_doc, locale)
|
160
|
+
when Jekyll::Document
|
161
|
+
append_document(Locale::Document, canon_doc, locale)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def append_page(klass, canon_page, locale)
|
168
|
+
locale_page = klass.new(canon_page, locale)
|
169
|
+
return unless locale_page.publish?
|
170
|
+
|
171
|
+
canon_page.locale_pages << locale_page
|
172
|
+
site.pages << locale_page
|
173
|
+
site.pages.uniq!
|
174
|
+
end
|
175
|
+
|
176
|
+
def append_document(klass, canon_doc, locale)
|
177
|
+
locale_doc = klass.new(canon_doc, locale)
|
178
|
+
return unless locale_doc.publish?
|
179
|
+
|
180
|
+
canon_doc.locale_pages << locale_doc
|
181
|
+
canon_doc.collection.docs << locale_doc
|
182
|
+
site.docs_to_write << locale_doc
|
183
|
+
site.docs_to_write.uniq!
|
184
|
+
end
|
185
|
+
|
186
|
+
def snakeified_keys(key)
|
187
|
+
@snakeified_keys[key] ||= Utils.snakeify(key)
|
188
|
+
end
|
189
|
+
|
190
|
+
def mode
|
191
|
+
@mode ||= begin
|
192
|
+
value = config["mode"]
|
193
|
+
value == "auto" ? value : DEFAULT_CONFIG["mode"]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def fetch(key)
|
198
|
+
value = config[key]
|
199
|
+
default = DEFAULT_CONFIG[key]
|
200
|
+
return default unless value.class == default.class
|
201
|
+
return default if value.to_s.empty?
|
202
|
+
|
203
|
+
value
|
204
|
+
end
|
205
|
+
|
206
|
+
def exclusion_regex
|
207
|
+
@exclusion_regex ||= Regexp.new("\\A(?:#{Regexp.union(Array(config["exclude_set"]))})")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::Identity
|
5
|
+
attr_reader :id, :data
|
6
|
+
alias_method :to_s, :id
|
7
|
+
|
8
|
+
def initialize(locale_id, metadata)
|
9
|
+
@id = locale_id.to_s
|
10
|
+
@data = metadata
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_liquid
|
14
|
+
@to_liquid ||= data.merge("id" => id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale::Helper
|
5
|
+
attr_reader :canon, :relative_path
|
6
|
+
|
7
|
+
def setup_hreflangs?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_hreflangs
|
12
|
+
page_set = [canon] + canon.locale_pages
|
13
|
+
@hreflangs = sibling_data(page_set)
|
14
|
+
@locale_siblings = sibling_data(page_set - [self])
|
15
|
+
end
|
16
|
+
|
17
|
+
def permalink
|
18
|
+
canon_link = super
|
19
|
+
File.join(locale.id, canon_link) if canon_link
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class} @canon=#{canon.inspect} @locale=#{locale.inspect}>"
|
24
|
+
end
|
25
|
+
alias_method :to_s, :inspect
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def setup(canon, locale)
|
30
|
+
@locale = locale
|
31
|
+
@canon = canon
|
32
|
+
@site = canon.site
|
33
|
+
@extname = canon.extname
|
34
|
+
@locale_page_dir = File.join(@site.locale_handler.content_dirname, locale.id, "")
|
35
|
+
@relative_path = File.join(@locale_page_dir, canon.relative_path)
|
36
|
+
@path = @site.in_source_dir(@relative_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure_data
|
40
|
+
Array(@data["categories"]).delete_if do |category|
|
41
|
+
category == @site.locale_handler.content_dirname || category == @locale.id
|
42
|
+
end
|
43
|
+
|
44
|
+
@data = Jekyll::Utils.deep_merge_hashes(canon.data, @data)
|
45
|
+
@data.default_proc = proc do |_, key|
|
46
|
+
site.frontmatter_defaults.find(relative_path, type, key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure_payload(payload)
|
51
|
+
payload.to_h.tap do |data|
|
52
|
+
data["path"] = self.relative_path
|
53
|
+
data["url"] = self.url
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale::Support
|
5
|
+
attr_reader :site, :locale
|
6
|
+
|
7
|
+
def setup_hreflangs?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def locale_siblings
|
12
|
+
@locale_siblings ||= sibling_data(locale_pages)
|
13
|
+
end
|
14
|
+
|
15
|
+
def hreflangs
|
16
|
+
@hreflangs ||= sibling_data([self] + locale_pages)
|
17
|
+
end
|
18
|
+
|
19
|
+
def locale_pages
|
20
|
+
@locale_pages ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def publish?
|
24
|
+
site.publisher.publish?(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def sibling_data(locale_page_set)
|
30
|
+
locale_page_set.map do |locale_page|
|
31
|
+
next unless locale_page.publish?
|
32
|
+
|
33
|
+
locale = locale_page.locale || site.locale_handler.default_locale
|
34
|
+
{
|
35
|
+
"locale" => locale.to_liquid,
|
36
|
+
"url" => locale_page.url,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::Page < Page
|
5
|
+
include Locale::Helper
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
def initialize(canon, locale)
|
9
|
+
setup(canon, locale)
|
10
|
+
@dir, @name = File.split(relative_path)
|
11
|
+
@base = site.source
|
12
|
+
process(@name)
|
13
|
+
read_yaml(@dir, @name)
|
14
|
+
configure_data
|
15
|
+
|
16
|
+
# Empty the value as it is not longer required.
|
17
|
+
@dir = ""
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_liquid
|
21
|
+
@to_liquid ||= configure_payload(super)
|
22
|
+
end
|
23
|
+
|
24
|
+
def template
|
25
|
+
@template ||= File.join("", locale.id, super)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Drops::UnifiedPayloadDrop
|
5
|
+
def locale
|
6
|
+
@locale ||= Locale::Drop.new(@obj.locale_handler)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Site
|
11
|
+
def locale_handler
|
12
|
+
@locale_handler ||= Locale::Handler.new(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Utils
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def snakeify(input)
|
8
|
+
slug = slugify(input.to_s, :mode => "latin", :cased => true)
|
9
|
+
slug.tr!("-", "_")
|
10
|
+
slug
|
11
|
+
end
|
12
|
+
|
13
|
+
def recursive_symbolize_hash_keys(hash)
|
14
|
+
result = {}
|
15
|
+
hash.each do |key, value|
|
16
|
+
new_key = key.to_s.to_sym
|
17
|
+
result[new_key] = value.is_a?(Hash) ? recursive_symbolize_hash_keys(value) : value
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-locale_sgh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Saeed G
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- dev_projects@ghanavats.co.uk
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- lib/jekyll-locale.rb
|
43
|
+
- lib/jekyll/locale/auto_page.rb
|
44
|
+
- lib/jekyll/locale/date_time_handler.rb
|
45
|
+
- lib/jekyll/locale/document.rb
|
46
|
+
- lib/jekyll/locale/drop.rb
|
47
|
+
- lib/jekyll/locale/filters.rb
|
48
|
+
- lib/jekyll/locale/handler.rb
|
49
|
+
- lib/jekyll/locale/identity.rb
|
50
|
+
- lib/jekyll/locale/mixins/helper.rb
|
51
|
+
- lib/jekyll/locale/mixins/support.rb
|
52
|
+
- lib/jekyll/locale/page.rb
|
53
|
+
- lib/jekyll/locale/version.rb
|
54
|
+
- lib/jekyll/patches/site.rb
|
55
|
+
- lib/jekyll/patches/utils.rb
|
56
|
+
homepage: https://github.com/ghanavat/jekyll-locale
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
allowed_push_host: https://rubygems.org
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.1.4
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: A localization plugin for Jekyll
|
80
|
+
test_files: []
|