jekyll-locales 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25799590a9e5b76543de8e6a92113146d3075f7c863d48dedfdf767aba10b766
4
- data.tar.gz: b83c6dcc24dc064a3ac0168c203d39c22f5363bffdc29755f23020ff0ef3516d
3
+ metadata.gz: 764336f02b1a0f2d7875de245b0ee0079f4e8bb98f312b5922acd843c06cd027
4
+ data.tar.gz: 8df9900565b574eb1d6782375713c5b9d29bf7369bd21d3b88cc70547311f1a3
5
5
  SHA512:
6
- metadata.gz: c2d95bfceff947e8519cb9e07e6c0c2ddbb846d0ca229ae1bd524bb3e9b4eda17e5e91dc7ee758c158e88508f7208f962634d9bff6a88ce495c4ae21c055c95a
7
- data.tar.gz: c0b88bad5a414cb6895335ed8b5742853779b4adbbdb021931cf589b2fea1fdae32488db0c8243f714870947ac8a0231631a3756717ea93bc34b56cfd4ea520d
6
+ metadata.gz: 3f96129ee3b801fe9a5552501bd3a7df7ee1328df62cb4e70e59b3579599de75e842466e3bbb7de62586afafc259883d812b95e312d97262b700501a8c4c135d
7
+ data.tar.gz: 277f7ed8ec305865cc5299e766a19d849e3dbb2f39c2ffec6737bcace7b04174f62876503c383cac994929c89949d04a02e6564561f5ee397b7e181231e52130
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-locales (0.1.0)
4
+ jekyll-locales (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -61,6 +61,25 @@ locales:
61
61
 
62
62
  Then you can access them by using `page.locales` in your layout.
63
63
 
64
+ ### Pages
65
+
66
+ You can translate the front matter by adding locale-specific variables
67
+ in it:
68
+
69
+ ```yaml
70
+ ---
71
+ layout: page
72
+ title: Default title
73
+ locales:
74
+ es:
75
+ title: Título en castellano
76
+ permalink: pagina/
77
+ en:
78
+ title: English title
79
+ permalink: page/
80
+ ---
81
+ ```
82
+
64
83
  ### Themes
65
84
 
66
85
  To translate your theme, put the string into `_data/LANGUAGE.yml` files,
@@ -2,3 +2,4 @@
2
2
 
3
3
  require 'jekyll/site'
4
4
  require 'jekyll/locales/site'
5
+ require 'jekyll/locales/hooks/page_post_init'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Jekyll::Hooks.register :pages, :post_init do |page|
4
+ next unless page.data.dig('locales', page.site.locale)
5
+
6
+ page.data.merge! page.data['locales'][page.site.locale]
7
+ end
@@ -9,20 +9,24 @@ module Jekyll
9
9
  # * The plugin generates a copy of the site for every language at
10
10
  # _site/LANGUAGE
11
11
  class Site
12
+ attr_reader :locale
13
+
12
14
  # We don't monkey patch because the Site is already instantiated
13
15
  alias process_single process
14
16
 
15
17
  # Process the site once per available locale
16
18
  def process
17
19
  locales.each do |locale|
20
+ @locale = locale
21
+
18
22
  Jekyll.logger.info 'Generating locale:', locale
19
23
 
20
- config_for locale
24
+ locale_config
21
25
 
22
26
  Jekyll.logger.info 'Destination:', config['destination']
23
27
  Jekyll.logger.info 'Base URL:', config['baseurl']
24
28
 
25
- symlink_for locale
29
+ symlink
26
30
  process_single
27
31
  copy_redirector
28
32
  end
@@ -33,9 +37,9 @@ module Jekyll
33
37
 
34
38
  private
35
39
 
36
- def config_for(locale)
37
- @dest = config['destination'] = destination_for(locale)
38
- config['baseurl'] = baseurl_for(locale)
40
+ def locale_config
41
+ @dest = config['destination'] = locale_destination
42
+ config['baseurl'] = locale_baseurl
39
43
 
40
44
  # XXX: Retrocompatibility
41
45
  config['locale'] = config['lang'] = locale
@@ -61,27 +65,26 @@ module Jekyll
61
65
  end
62
66
 
63
67
  # Add locale to the site destination
64
- def destination_for(locale)
68
+ def locale_destination
65
69
  File.join(root_destination, locale)
66
70
  end
67
71
 
68
72
  # If the site has a baseurl, we add the locale to it. But we add
69
73
  # it anyway so relative URLs include the locale
70
- def baseurl_for(locale)
74
+ def locale_baseurl
71
75
  [orig_baseurl, locale].join('/')
72
76
  end
73
77
 
74
78
  # Creates a symlink to the _posts/ directory so Jekyll believes
75
79
  # it's processing a single site.
76
- def symlink_for(locale)
80
+ def symlink
77
81
  FileUtils.rm_f('_posts')
78
82
  FileUtils.ln_s("_#{locale}", '_posts')
79
83
  end
80
84
 
81
85
  # TODO: Make configurable
82
86
  def redirector
83
- @redirector ||= File.join(destination_for(default_locale),
84
- 'redirector.html')
87
+ @redirector ||= File.join(locale_destination, 'redirector.html')
85
88
  end
86
89
 
87
90
  def redirector_to_index(redir)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Locales
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-locales
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-14 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - jekyll-locales.gemspec
91
91
  - lib/jekyll-locales.rb
92
92
  - lib/jekyll/locales.rb
93
+ - lib/jekyll/locales/hooks/page_post_init.rb
93
94
  - lib/jekyll/locales/site.rb
94
95
  - lib/jekyll/locales/version.rb
95
96
  homepage: https://0xacab.org/sutty/jekyll/jekyll-locales