jekyll-open-sdg-plugins 1.0.0.rc12 → 1.0.0.rc13

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: f3ddcd012812807b48b5b94dbbedfe47d4c3187f60383439fa0eb26c1f28e90f
4
- data.tar.gz: 64a473bdd4e7f3c64f2d9cf2e1c1e1b7659b2273f96b4089e0f4c74f0a8a09fb
3
+ metadata.gz: ec6a82fc746845dce8607f5828fc220a00cf4ba028d46abba039e73b76b28bb0
4
+ data.tar.gz: 4568e2076c2204fd8e0198e705a73a900b22e390faa18a215315ddceeee9a566
5
5
  SHA512:
6
- metadata.gz: 3bc05be3e1b50b49560c235df08893590ba67ace6b59056c77d049f7bb650ce955cc1ec1257145a7a02835f5245f4d8e84816eda4cf616e31a9549dac519b96f
7
- data.tar.gz: 994312f102ed250a8978d812aacc7d598767d062b5c9b065c420012311199345514cd0765b4af19bdd483bd684d9f83b405c3427c14ce54e9fcc93c7112650cb
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 CreateGoals < Jekyll::Generator
6
6
  safe true
7
- priority :low
7
+ priority :normal
8
8
 
9
9
  def generate(site)
10
10
  # If site.create_goals is set, create goals per the metadata.
@@ -4,7 +4,7 @@ require_relative "helpers"
4
4
  module JekyllOpenSdgPlugins
5
5
  class CreateIndicators < Jekyll::Generator
6
6
  safe true
7
- priority :low
7
+ priority :normal
8
8
 
9
9
  def generate(site)
10
10
  # If site.create_indicators is set, create indicators per the metadata.
@@ -3,7 +3,7 @@ require "jekyll"
3
3
  module JekyllOpenSdgPlugins
4
4
  class CreatePages < Jekyll::Generator
5
5
  safe true
6
- priority :low
6
+ priority :normal
7
7
 
8
8
  def generate(site)
9
9
  # If site.create_pages is set, create the 4 required pages. These include:
@@ -4,7 +4,7 @@ require_relative "helpers"
4
4
  module JekyllOpenSdgPlugins
5
5
  class SDGVariables < Jekyll::Generator
6
6
  safe true
7
- priority :lowest
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
@@ -70,6 +70,7 @@ module JekyllOpenSdgPlugins
70
70
 
71
71
  # Stow the data for later use in Jekyll templates.
72
72
  site.data['search_items'] = search_items
73
+
73
74
  end
74
75
  end
75
76
  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)
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "1.0.0.rc12".freeze
2
+ VERSION = "1.0.0.rc13".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: 1.0.0.rc12
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 00:00:00.000000000 Z
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: