jekyll-open-sdg-plugins 1.0.0.rc12 → 1.0.0.rc13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-open-sdg-plugins.rb +1 -0
- data/lib/jekyll-open-sdg-plugins/create_goals.rb +1 -1
- data/lib/jekyll-open-sdg-plugins/create_indicators.rb +1 -1
- data/lib/jekyll-open-sdg-plugins/create_pages.rb +1 -1
- data/lib/jekyll-open-sdg-plugins/sdg_variables.rb +2 -1
- data/lib/jekyll-open-sdg-plugins/search_index.rb +1 -0
- data/lib/jekyll-open-sdg-plugins/translate_metadata_field.rb +111 -0
- data/lib/jekyll-open-sdg-plugins/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6a82fc746845dce8607f5828fc220a00cf4ba028d46abba039e73b76b28bb0
|
4
|
+
data.tar.gz: 4568e2076c2204fd8e0198e705a73a900b22e390faa18a215315ddceeee9a566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42b5609bdc5adfdb846ec7be9e263ad1d7225ca17ccdb52699e13809a633c6025afb7cf1c0fd99d5c455107f9c65ff14fe3835639942b5a954e3490951c774d
|
7
|
+
data.tar.gz: 5906c9596f21a0e3c2613f80b730b00c3637cd54af49ad862a43aeb67b04ace9efee0f901a7b8cddba9616820ef7ea3145622a23ebbb07f42d788a871cc74546
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "jekyll-open-sdg-plugins/version"
|
2
2
|
require_relative "jekyll-open-sdg-plugins/fetch_remote_data"
|
3
3
|
require_relative "jekyll-open-sdg-plugins/translate_key"
|
4
|
+
require_relative "jekyll-open-sdg-plugins/translate_metadata_field"
|
4
5
|
require_relative "jekyll-open-sdg-plugins/create_indicators"
|
5
6
|
require_relative "jekyll-open-sdg-plugins/create_goals"
|
6
7
|
require_relative "jekyll-open-sdg-plugins/create_pages"
|
@@ -4,7 +4,7 @@ require_relative "helpers"
|
|
4
4
|
module JekyllOpenSdgPlugins
|
5
5
|
class SDGVariables < Jekyll::Generator
|
6
6
|
safe true
|
7
|
-
priority :
|
7
|
+
priority :low
|
8
8
|
|
9
9
|
# Get a goal number from an indicator number.
|
10
10
|
def get_goal_number(indicator_number)
|
@@ -388,6 +388,7 @@ module JekyllOpenSdgPlugins
|
|
388
388
|
end
|
389
389
|
end
|
390
390
|
site.data['sdg_lookup'] = lookup
|
391
|
+
|
391
392
|
end
|
392
393
|
end
|
393
394
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module TranslateMetadataField
|
6
|
+
# Takes a metadata field (machine name) and returns a translated string
|
7
|
+
# according to the language of the current page, suitable for displaying to
|
8
|
+
# the public. It gets this string by looking in the site's "schema" for a
|
9
|
+
# "translation_key" property, and running that through the
|
10
|
+
# opensdg_translate_key() helper function.
|
11
|
+
#
|
12
|
+
# Temporary backwards compatibility: If the check fails, it falls back to
|
13
|
+
# checking for a translation in the 'metadata_fields' translation group.
|
14
|
+
#
|
15
|
+
# More backwards compatibility: If all of the above fails, it falls back to
|
16
|
+
# using whatever is in a "label" property in the schema.
|
17
|
+
#
|
18
|
+
# Parameters
|
19
|
+
# ----------
|
20
|
+
# field_name : string
|
21
|
+
# The machine name of a metadata field.
|
22
|
+
def translate_metadata_field(field_name)
|
23
|
+
|
24
|
+
# Determine the language of the current page.
|
25
|
+
t = @context.registers[:site].data['translations']
|
26
|
+
lang = @context.environments.first['page']['language']
|
27
|
+
# Get the schema.
|
28
|
+
schema = @context.registers[:site].data['schema']
|
29
|
+
|
30
|
+
# Find the field.
|
31
|
+
field = schema.select {|x| x['name'] == field_name }
|
32
|
+
if field
|
33
|
+
field = field.first()
|
34
|
+
end
|
35
|
+
|
36
|
+
to_translate = ''
|
37
|
+
# First choice - use the 'translation_key' property from the schema.
|
38
|
+
if field && field['field'].has_key?('translation_key')
|
39
|
+
to_translate = field['field']['translation_key']
|
40
|
+
# Next choice - try the 'metadata_fields' translation group.
|
41
|
+
elsif t[lang].has_key?('metadata_fields') && t[lang]['metadata_fields'].has_key?(field_name)
|
42
|
+
to_translate = 'metadata_fields.' + field_name
|
43
|
+
# Next choice - use the 'label' from the schema.
|
44
|
+
elsif field && field['field'].has_key?('label')
|
45
|
+
to_translate = field['field']['label']
|
46
|
+
# Last choice - just use the field name.
|
47
|
+
else
|
48
|
+
to_translate = field_name
|
49
|
+
end
|
50
|
+
|
51
|
+
return opensdg_translate_key(to_translate, t, lang)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TranslateMetadataFieldOption
|
56
|
+
# Takes a metadata field (machine name) and option (value) and returns a
|
57
|
+
# translated string according to the language of the current page, suitable
|
58
|
+
# for displaying to the public.
|
59
|
+
#
|
60
|
+
# By contrast to TranslateMetadataField above, this is for translating the
|
61
|
+
# options of multiple-choice schema fields. But similar to
|
62
|
+
# TranslateMetadataField, this looks for a "translation_key" property on
|
63
|
+
# the option in the schema.
|
64
|
+
#
|
65
|
+
# Temporary backwards compatibility: If the check fails, it falls back to
|
66
|
+
# whatever is in a "name" property in the schema.
|
67
|
+
#
|
68
|
+
# Parameters
|
69
|
+
# ----------
|
70
|
+
# field_name : string
|
71
|
+
# The machine name of a metadata field.
|
72
|
+
# value : string
|
73
|
+
# The 'value' of the option to use.
|
74
|
+
def translate_metadata_field_option(field_name, value)
|
75
|
+
|
76
|
+
# Determine the language of the current page.
|
77
|
+
t = @context.registers[:site].data['translations']
|
78
|
+
lang = @context.environments.first['page']['language']
|
79
|
+
# Get the schema.
|
80
|
+
schema = @context.registers[:site].data['schema']
|
81
|
+
|
82
|
+
# Find the field.
|
83
|
+
field = schema.select {|x| x['name'] == field_name}
|
84
|
+
if field
|
85
|
+
field = field.first()
|
86
|
+
end
|
87
|
+
|
88
|
+
# Fall back to the value itself.
|
89
|
+
to_translate = value
|
90
|
+
|
91
|
+
# Look for the 'translation_key' property from the schema.
|
92
|
+
if field && field['field'].has_key?('options')
|
93
|
+
option = field['field']['options'].select {|x| x['value'] == value}
|
94
|
+
if option
|
95
|
+
option = option.first()
|
96
|
+
if option.has_key?('translation_key')
|
97
|
+
to_translate = option['translation_key']
|
98
|
+
else
|
99
|
+
to_translate = option['name']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
return opensdg_translate_key(to_translate, t, lang)
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Liquid::Template.register_filter(Jekyll::TranslateMetadataField)
|
111
|
+
Liquid::Template.register_filter(Jekyll::TranslateMetadataFieldOption)
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.rc13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brock Fanning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/jekyll-open-sdg-plugins/sdg_variables.rb
|
60
60
|
- lib/jekyll-open-sdg-plugins/search_index.rb
|
61
61
|
- lib/jekyll-open-sdg-plugins/translate_key.rb
|
62
|
+
- lib/jekyll-open-sdg-plugins/translate_metadata_field.rb
|
62
63
|
- lib/jekyll-open-sdg-plugins/version.rb
|
63
64
|
homepage: https://github.com/open-sdg/jekyll-open-sdg-plugins
|
64
65
|
licenses:
|