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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df572d1ef49b272b66e85dd61d431086fc51f87b352fda68b68a5f1c9ced841e
|
4
|
+
data.tar.gz: 8e044042d7f52c9fc64418be34192443d198b260e8554a2c7553936d74fd3ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba64c48c74554f547a6800acb5af303b168e97a38bd25a95b7b4e4adfb47dc52a3b4f1ae537155ac02d1c8e2c995423a1e828bf7133cce7218320633d05db351
|
7
|
+
data.tar.gz: 3db8a54dc10b34945816962f4f54034c2135b13359fdab84fe5ae6ca72aa9f42fd5826e259fb07bf95fa540c0b53a017e6de2723981abd31c98503cf2bcd17dd
|
@@ -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)
|
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.
|
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-
|
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:
|