jekyll-open-sdg-plugins 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85363f52e817024bfeb2495c65aad436d3d19c6cfd213569b0ed170e4bc98914
4
- data.tar.gz: 1cbd736c8273adb165ba4bd2a482bc553f4fc59d62a1beda2b4791566d36b057
3
+ metadata.gz: df572d1ef49b272b66e85dd61d431086fc51f87b352fda68b68a5f1c9ced841e
4
+ data.tar.gz: 8e044042d7f52c9fc64418be34192443d198b260e8554a2c7553936d74fd3ad6
5
5
  SHA512:
6
- metadata.gz: 5c8f6cc3f8d6c09a54218017c2a82a9ace6efd3145e82512bf0ae073d356dc25641eee42bd762ebd1c8503efdc9d05f03c9e350731dad03b939eb11435026aaf
7
- data.tar.gz: dbd1f37bb30f3cc6b3863061f020cbb4eeae60081a534004222eb7748e3f92760250c55f48522cb677ce5d0091078b2661abbc2e2a21a482075325f5c0fd7017
6
+ metadata.gz: ba64c48c74554f547a6800acb5af303b168e97a38bd25a95b7b4e4adfb47dc52a3b4f1ae537155ac02d1c8e2c995423a1e828bf7133cce7218320633d05db351
7
+ data.tar.gz: 3db8a54dc10b34945816962f4f54034c2135b13359fdab84fe5ae6ca72aa9f42fd5826e259fb07bf95fa540c0b53a017e6de2723981abd31c98503cf2bcd17dd
@@ -1,5 +1,6 @@
1
1
  require_relative "jekyll-open-sdg-plugins/version"
2
2
  require_relative "jekyll-open-sdg-plugins/multilingual_metadata"
3
+ require_relative "jekyll-open-sdg-plugins/translate_key"
3
4
 
4
5
  module JekyllOpenSdgPlugins
5
6
  end
@@ -0,0 +1,45 @@
1
+ require "jekyll"
2
+
3
+ module Jekyll
4
+ module TranslateKey
5
+ # Takes a translation key and returns a translated string according to the
6
+ # language of the current page. Or if none is found, returns the original
7
+ # key.
8
+ def t(key)
9
+ translations = @context.registers[:site].data['translations']
10
+ language = @context.environments.first["page"]['language']
11
+
12
+ # Keep track of the last thing we drilled to.
13
+ drilled = translations[language]
14
+
15
+ # Keep track of how many levels we have drilled.
16
+ levels_drilled = 0
17
+ levels = key.split('.')
18
+
19
+ # Loop through each level.
20
+ levels.each do |level|
21
+
22
+ # If we have drilled down to a scalar value too soon, abort.
23
+ break if drilled.class != Hash
24
+
25
+ if drilled.has_key? level
26
+ # If we find something, continue drilling.
27
+ drilled = drilled[level]
28
+ levels_drilled += 1
29
+ end
30
+
31
+ end
32
+
33
+ # If we didn't drill the right number of levels, return the
34
+ # original string.
35
+ if levels.length != levels_drilled
36
+ return key
37
+ end
38
+
39
+ # Otherwise we must have drilled all they way.
40
+ return drilled
41
+ end
42
+ end
43
+ end
44
+
45
+ Liquid::Template.register_filter(Jekyll::TranslateKey)
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-open-sdg-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brock Fanning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,7 @@ files:
38
38
  - jekyll-open-sdg-plugins.gemspec
39
39
  - lib/jekyll-open-sdg-plugins.rb
40
40
  - lib/jekyll-open-sdg-plugins/multilingual_metadata.rb
41
+ - lib/jekyll-open-sdg-plugins/translate_key.rb
41
42
  - lib/jekyll-open-sdg-plugins/version.rb
42
43
  homepage: https://github.com/open-sdg/jekyll-open-sdg-plugins
43
44
  licenses: