jekyll-open-sdg-plugins 1.0.0.rc6 → 1.0.0.rc7

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: 8007d07bf097d9475a171e78389891a753f69338de2a859de6754013fc84ec17
4
- data.tar.gz: 6bad1a307d617c391b03970471310aa8be6f04571f17340391caaee50a21033e
3
+ metadata.gz: 2f9696653a01838967c46fbc75ba9f42ae3407e23fbea42f5577fff00c812400
4
+ data.tar.gz: 222958568c169871c68f6812bdb2e47f074186514c28de2d7090dbccdae416cb
5
5
  SHA512:
6
- metadata.gz: 9ebe2ef38212facd07500e1d02976bc14f34fbab8624dfe324e6f696c0abb37571e6aec6dcef7f84422c5eb5b27ac646111b4949f694b5db14ec794d9abbcd1e
7
- data.tar.gz: 1a4070ac2858484f3819be479b0041095eb3a7f4ee3b002cd36ef7656dc8639022a453c4fbf244a9bc076e67954651d3696a7665343b010ab7d866d234392798
6
+ metadata.gz: 9002444b28bfaf97393a3920ea25191d462fffecd3f53cc054948bd627ee45a3090fbd592203ac570b897eef110bb2aaa5059f92c005b270adb4000e4c123c50
7
+ data.tar.gz: 615e228587be863c9729300966e784515834d072adf5fe34acdb39d76fdaf7a3004c1607964a9cc8bb37d01dabc38811a310d586767bddae38c59dfeb915a75d
data/README.md CHANGED
@@ -2,152 +2,6 @@
2
2
 
3
3
  > 💎 Jekyll plugins for use with the Open SDG platform
4
4
 
5
- This plugin provides some Jekyll functionality for the [Open SDG](https://github.com/open-sdg/open-sdg) platform.
5
+ This plugin provides required Jekyll functionality for the [Open SDG](https://github.com/open-sdg/open-sdg) platform.
6
6
 
7
- The functionality provided consists of:
8
-
9
- ## 1. A "t" Liquid filter for translating strings.
10
-
11
- Usage example:
12
-
13
- ```
14
- {{ my_variable | t }}
15
- ```
16
-
17
- ## 2. Fill in missing fields to allow partially translated metadata.
18
-
19
- This allows metadata to be translated, field-by-field as needed, in subfolders in the data repository.
20
-
21
- ## 3. Automatically create goal pages based on data.
22
-
23
- This creates goal pages automatically based on the data, so that the site repository does not need to maintain a `_goals` folder. It depends on a `_config.yml` setting.
24
-
25
- Usage example (in `_config.yml`):
26
- ```
27
- create_goals:
28
- # This determines which layout is used to render the pages.
29
- layout: goal
30
- ```
31
-
32
- ## 4. Automatically create indicator pages based on data.
33
-
34
- This creates indicator pages automatically based on the data, so that the site repository does not need to maintain a `_indicators` folder. It depends on a `_config.yml` setting.
35
-
36
- Usage example (in `_config.yml`):
37
- ```
38
- create_indicators:
39
- # This determines which layout is used to render the pages.
40
- layout: indicator
41
- ```
42
-
43
- ## 5. Automatically create 4 required pages.
44
-
45
- This automates the creation of 4 required pages that all implementations of Open SDG will need. These consist of:
46
-
47
- * the home page: /
48
- * the indicators json page: /indicators.json
49
- * the search results page: /search
50
- * the reporting status page: /reporting-status
51
-
52
- There are advanced options for overriding the location of these pages (see creae_pages.rb). But see the example below to use the defaults.
53
-
54
- Usage example (in `_config.yml`):
55
- ```
56
- create_pages: true
57
- ```
58
-
59
- ## 6. Automatically fetch remote data and translations.
60
-
61
- This automates the fetching of the remote data (from the "data repository") and any remote translations.
62
-
63
- Note: This feature is disabled if "jekyll_get_json" is in the site config. This was the older (more verbose) way to do this.
64
-
65
- Usage example (in `_config.yml`):
66
- ```
67
- remote_data_prefix: https://mygithuborg.github.io/my-data-repository
68
- remote_translations:
69
- - https://open-sdg.github.io/sdg-translations/translations-0.6.0.json
70
-
71
- ```
72
-
73
- For those interested in switching to this convenience feature, note that this makes the "jekyll_get_json" and "remotedatabaseurl" settings obsolete; so they can be removed.
74
-
75
- ## 7. Provide standard variables on all pages, for use in templates
76
-
77
- This feature provides access to Hashes for goals, targets, and indicators. Each
78
- contains the following keys:
79
- * number (eg, "1" for a goal, "1.1" for a target, "1.1.1" for an indicator)
80
- * slug (eg, "1" for a goal, "1-1", for a target, "1-1-1" for an indicator)
81
- * name (the fully-translated name of the goal/target/indicator
82
- * sort (a string suitable for use in sorting the goals/targets/indicators)
83
- * global (an equivalent Hash containing specifically "global" versions)
84
-
85
- Additionally, indicators contain:
86
- * url (the URL of that indicator's page)
87
- * goal_number (the number of that indicator's goal)
88
- * target_number (the number of that indicator's target)
89
- * [all the indicator's metadata fields]
90
-
91
- Additionally, targets contain:
92
- * goal_number (the number of that target's goal)
93
-
94
- Additionally, goals contain:
95
- * url (the URL of that goal's page)
96
- * icon (the URL of that goal's icon)
97
- * short (the short version of the goal name, translated)
98
-
99
- The following variables can be used on ALL pages:
100
-
101
- * goals : Array of goals
102
- * targets : Array of targets
103
- * indicators : Array of indicators
104
- * baseurl: A page-specific version of site.baseurl, taking language into account
105
- * language: The language code for the current page
106
- * language_public: The "public" language code, which may be different from the
107
- language code.
108
- * t: A hash of all the compiled translations in the current language
109
-
110
- The following variables can be used on all indicator pages:
111
-
112
- * goal : the current goal
113
- * target : the current target
114
- * indicator : the current indicator
115
-
116
- The following variables can be used on all goal pages:
117
-
118
- * goal : the current goal
119
-
120
- Examples of usage:
121
-
122
- Printing titles for all available indicators in Goal 2:
123
- ```
124
- {% assign indicators = page.indicators | where: "goal_number", "2" %}
125
- {% for indicator in indicators %}
126
- {{ indicator.name }}
127
- {% endfor %}
128
- ```
129
-
130
- Printing the short name for the current goal, on a goal page:
131
- ```
132
- {{ page.goal.short }}
133
- ```
134
-
135
- Printing the name of all targets in a particular, on that goal page:
136
- ```
137
- {% assign targets = page.targets | where: "goal_number", page.goal.number %}
138
- {% for target in targets %}
139
- {{ target.name }}
140
- {% endfor %}
141
-
142
- ## 8. Lookup goals/targets/indicators by ID
143
-
144
- The hashes detailed above in #7 can also be looked up by id, with the `sdg_lookup` filter.
145
-
146
- Examples of usage:
147
-
148
- Looking up target 7.1 and printing its name
149
-
150
- ```
151
- {% assign target = '7.1' | sdg_lookup %}
152
- {{ target.name }}
153
- ```
7
+ The details on this functionality can be found throughout the [Open SDG documentation](https://open-sdg.readthedocs.io/en/latest/).
@@ -1,4 +1,5 @@
1
1
  require "jekyll"
2
+ require_relative "helpers"
2
3
 
3
4
  module JekyllOpenSdgPlugins
4
5
  class CreateGoals < Jekyll::Generator
@@ -10,7 +11,18 @@ module JekyllOpenSdgPlugins
10
11
  if site.config['languages'] and site.config['create_goals']
11
12
  # Compile the list of goals.
12
13
  goals = {}
13
- site.data['meta'].each do |inid, meta|
14
+ # Are we using translated builds?
15
+ metadata = {}
16
+ if opensdg_translated_builds(site)
17
+ # If we are using translated builds, the 'meta' data is underneath
18
+ # language codes. We just use the first language.
19
+ default_language = site.config['languages'][0]
20
+ metadata = site.data[default_language]['meta']
21
+ else
22
+ # Otherwise the 'meta' data is not underneath any language code.
23
+ metadata = site.data['meta']
24
+ end
25
+ metadata.each do |inid, indicator|
14
26
  goal = inid.split('-')[0].to_i
15
27
  goals[goal] = true
16
28
  end
@@ -1,4 +1,5 @@
1
1
  require "jekyll"
2
+ require_relative "helpers"
2
3
 
3
4
  module JekyllOpenSdgPlugins
4
5
  class CreateIndicators < Jekyll::Generator
@@ -25,8 +26,17 @@ module JekyllOpenSdgPlugins
25
26
  if languages_public[language]
26
27
  language_public = languages_public[language]
27
28
  end
29
+ metadata = {}
30
+ if opensdg_translated_builds(site)
31
+ # If we are using translated builds, the metadata is underneath a
32
+ # language code.
33
+ metadata = site.data[language]['meta']
34
+ else
35
+ # Otherwise the 'meta' data is not underneath any language code.
36
+ metadata = site.data['meta']
37
+ end
28
38
  # Loop through the indicators (using metadata as a list).
29
- site.data['meta'].each do |inid, meta|
39
+ metadata.each do |inid, meta|
30
40
  # Add the language subfolder for all except the default (first) language.
31
41
  dir = index == 0 ? inid : File.join(language_public, inid)
32
42
  # Create the indicator page.
@@ -30,6 +30,7 @@ module JekyllOpenSdgPlugins
30
30
  #
31
31
  # create_pages: true
32
32
  if site.config['languages'] and site.config['create_pages']
33
+
33
34
  default_pages = [
34
35
  {
35
36
  'folder' => '/',
@@ -2,61 +2,109 @@ require "jekyll"
2
2
  require 'json'
3
3
  require 'deep_merge'
4
4
  require 'open-uri'
5
+ require_relative "helpers"
5
6
 
6
7
  module JekyllOpenSdgPlugins
7
8
  class FetchRemoteData < Jekyll::Generator
8
9
  safe true
9
10
  priority :highest
10
11
 
12
+ def download_build(prefix)
13
+
14
+ endpoints = {
15
+ 'meta' => 'meta/all.json',
16
+ 'headlines' => 'headline/all.json',
17
+ 'schema' => 'meta/schema.json',
18
+ 'reporting' => 'stats/reporting.json',
19
+ 'translations' => 'translations/translations.json'
20
+ }
21
+ build = {}
22
+ endpoints.each do |key, value|
23
+ endpoint = prefix + '/' + value
24
+ begin
25
+ source = JSON.load(open(endpoint))
26
+ build[key] = source
27
+ rescue StandardError => e
28
+ puts e.message
29
+ # For backwards compatibility, we allow 'translations' to be missing.
30
+ if key != 'translations'
31
+ abort 'Unable to fetch remote data from: ' + endpoint
32
+ end
33
+ end
34
+ end
35
+ build
36
+ end
37
+
11
38
  def generate(site)
12
- # Backwards compatibility - only do this if 'jekyll_get_json' is absent.
13
- # (This is the older style of remote data fetching.)
14
- if !site.config['jekyll_get_json']
15
- # First try to grab the remote data.
16
- if site.config['remote_data_prefix']
17
- prefix = site.config['remote_data_prefix']
18
- # Set the required remotedatabaseurl config setting.
19
- site.config['remotedatabaseurl'] = prefix
20
- # Fetch remote data for each of our endpoints.
21
- endpoints = {
22
- 'meta' => 'meta/all.json',
23
- 'headlines' => 'headline/all.json',
24
- 'schema' => 'meta/schema.json',
25
- 'reporting' => 'stats/reporting.json'
26
- }
27
- endpoints.each do |key, value|
28
- target = site.data[key]
29
- endpoint = prefix + '/' + value
30
- begin
31
- source = JSON.load(open(endpoint))
32
- if target
33
- target.deep_merge(source)
34
- else
35
- site.data[key] = source
36
- end
37
- rescue StandardError => e
38
- puts e.message
39
- abort 'Unable to fetch remote data from: ' + endpoint
39
+
40
+ if site.config['remote_data_prefix']
41
+ prefix = site.config['remote_data_prefix']
42
+
43
+ # For below, make sure there is at least an empty hash at
44
+ # site.data.translations.
45
+ if !site.data.has_key?('translations')
46
+ site.data['translations'] = {}
47
+ end
48
+
49
+ # How do we tell, before data has been fetched, whether the site is
50
+ # using translated builds? Quick and dirty way - attempt a download
51
+ # of the non-tranlsated build. If it fails, assume translated builds.
52
+ translated_builds = false
53
+ begin
54
+ JSON.load(open(prefix + '/meta/all.json'))
55
+ rescue StandardError => e
56
+ translated_builds = true
57
+ end
58
+
59
+ if translated_builds
60
+ # For translated builds, we download a build for each language, and
61
+ # place them in "subfolders" (so to speak) of site.data.
62
+ site.config['languages'].each do |language|
63
+ data_target = site.data[language]
64
+ data_source = download_build(prefix + '/' + language)
65
+ if data_target
66
+ data_target.deep_merge(data_source)
67
+ else
68
+ site.data[language] = data_source
69
+ end
70
+ # Additionally, we move the language-specific translations to the
71
+ # site.data.translations location, where all translations are kept.
72
+ translation_target = site.data['translations'][language]
73
+ translation_source = site.data[language]['translations']
74
+ if translation_target
75
+ translation_target.deep_merge(translation_source)
76
+ else
77
+ site.data['translations'][language] = translation_source
40
78
  end
41
79
  end
80
+ else
81
+ # For untranslated builds, we download one build only, and place it
82
+ # in the "root" (so to speak) of site.data. Nothing else is needed.
83
+ target = site.data
84
+ source = download_build(prefix)
85
+ target.deep_merge(source)
42
86
  end
87
+ else
88
+ abort 'The "remote_data_prefix" configuration setting is missing.'
89
+ end
43
90
 
44
- # Next try to grab any remote translations.
45
- if site.config['remote_translations']
46
- key = 'translations'
47
- target = site.data[key]
48
- site.config['remote_translations'].each do |endpoint|
49
- begin
50
- source = JSON.load(open(endpoint))
51
- if target
52
- target.deep_merge(source)
53
- else
54
- site.data[key] = source
55
- end
56
- rescue StandardError => e
57
- puts e.message
58
- abort 'Unable to fetch remote translation from: ' + endpoint
91
+ # Finally support the deprecated 'remote_translations' option.
92
+ # This is deprecated because translations should now be in the
93
+ # data repository, where they will be fetched in download_build().
94
+ if site.config['remote_translations']
95
+ key = 'translations'
96
+ target = site.data[key]
97
+ site.config['remote_translations'].each do |endpoint|
98
+ begin
99
+ source = JSON.load(open(endpoint))
100
+ if target
101
+ target.deep_merge(source)
102
+ else
103
+ site.data[key] = source
59
104
  end
105
+ rescue StandardError => e
106
+ puts e.message
107
+ abort 'Unable to fetch remote translation from: ' + endpoint
60
108
  end
61
109
  end
62
110
  end
@@ -50,3 +50,17 @@ def opensdg_translate_key(key, translations, language)
50
50
  # Otherwise we must have drilled all they way.
51
51
  return drilled
52
52
  end
53
+
54
+ # Takes a site object and decides whether it is using translated builds.
55
+ def opensdg_translated_builds(site)
56
+ # Assume the site is using translated builds.
57
+ translated_builds = true
58
+ site.config['languages'].each do |language|
59
+ # If any languages don't have a key in site.data, the site is not using
60
+ # translated builds.
61
+ if !site.data.has_key? language
62
+ translated_builds = false
63
+ end
64
+ end
65
+ return translated_builds
66
+ end
@@ -34,33 +34,44 @@ module JekyllOpenSdgPlugins
34
34
  sort_order
35
35
  end
36
36
 
37
+ # The Jekyll baseurl is user-configured, and can be inconsistent. This
38
+ # ensure it is consistent in whether it starts/ends with a slash.
39
+ def normalize_baseurl(baseurl)
40
+ if baseurl == ''
41
+ baseurl = '/'
42
+ end
43
+ if !baseurl.start_with? '/'
44
+ baseurl = '/' + baseurl
45
+ end
46
+ if !baseurl.end_with? '/'
47
+ baseurl = baseurl + '/'
48
+ end
49
+ baseurl
50
+ end
51
+
37
52
  # Compute a URL for an item, given it's number.
38
53
  def get_url(baseurl, language, number, languages, languages_public)
39
54
 
55
+ baseurl = normalize_baseurl(baseurl)
56
+
40
57
  default_language = languages[0]
41
58
  language_public = language
42
59
  if languages_public && languages_public[language]
43
60
  language_public = languages_public[language]
44
61
  end
45
- if baseurl == ''
46
- baseurl = '/'
47
- end
48
62
  if default_language != language
49
63
  baseurl += language_public + '/'
50
64
  end
51
- if !baseurl.start_with? '/'
52
- baseurl = '/' + baseurl
53
- end
54
- if !baseurl.end_with? '/'
55
- baseurl = baseurl + '/'
56
- end
57
65
 
58
66
  number = number.gsub('.', '-')
59
67
  baseurl + number
60
68
  end
61
69
 
62
70
  # Get a Hash of all the URLs based on one particular one.
63
- def get_all_urls(url, language, languages, languages_public)
71
+ def get_all_urls(url, language, languages, languages_public, baseurl)
72
+
73
+ baseurl = normalize_baseurl(baseurl)
74
+
64
75
  language_public = language
65
76
  if languages_public && languages_public[language]
66
77
  language_public = languages_public[language]
@@ -78,7 +89,7 @@ module JekyllOpenSdgPlugins
78
89
  language => url
79
90
  }
80
91
  if language != default_language
81
- urls[default_language] = url_without_language
92
+ urls[default_language] = baseurl + url_without_language
82
93
  end
83
94
  languages.each do |other_language|
84
95
  if other_language == language
@@ -91,7 +102,7 @@ module JekyllOpenSdgPlugins
91
102
  if languages_public && languages_public[other_language]
92
103
  other_language_public = languages_public[other_language]
93
104
  end
94
- urls[other_language] = '/' + other_language_public + url_without_language
105
+ urls[other_language] = baseurl + other_language_public + url_without_language
95
106
  end
96
107
  urls
97
108
  end
@@ -210,7 +221,7 @@ module JekyllOpenSdgPlugins
210
221
  meta_key = indicator_number.gsub('.', '-')
211
222
  # The location of the metadata is different depending on whether we are
212
223
  # using "translated_builds" or not.
213
- if site.config['translated_builds']
224
+ if opensdg_translated_builds(site)
214
225
  meta = site.data[language]['meta'][meta_key]
215
226
  else
216
227
  meta = site.data['meta'][meta_key]
@@ -299,9 +310,15 @@ module JekyllOpenSdgPlugins
299
310
  doc.data['goals'] = available_goals[language]
300
311
  doc.data['targets'] = available_targets[language]
301
312
  doc.data['indicators'] = available_indicators[language]
302
- doc.data['t'] = site.data['translations'][language]
303
313
  doc.data['baseurl'] = get_url(baseurl, language, '', languages, languages_public)
304
- doc.data['url_by_language'] = get_all_urls(doc.url, language, languages, languages_public)
314
+ doc.data['url_by_language'] = get_all_urls(doc.url, language, languages, languages_public, baseurl)
315
+ doc.data['t'] = site.data['translations'][language]
316
+
317
+ # Set the remote_data_prefix for this indicator.
318
+ doc.data['remote_data_prefix'] = site.config['remote_data_prefix']
319
+ if opensdg_translated_builds(site)
320
+ doc.data['remote_data_prefix'] += '/' + language
321
+ end
305
322
 
306
323
  if collection == 'indicators'
307
324
  # For indicators we also set the current indicator/target/goal.
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "1.0.0.rc6".freeze
2
+ VERSION = "1.0.0.rc7".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.rc6
4
+ version: 1.0.0.rc7
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-11-16 00:00:00.000000000 Z
11
+ date: 2019-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -55,9 +55,7 @@ files:
55
55
  - lib/jekyll-open-sdg-plugins/create_indicators.rb
56
56
  - lib/jekyll-open-sdg-plugins/create_pages.rb
57
57
  - lib/jekyll-open-sdg-plugins/fetch_remote_data.rb
58
- - lib/jekyll-open-sdg-plugins/get_indicator_name.rb
59
58
  - lib/jekyll-open-sdg-plugins/helpers.rb
60
- - lib/jekyll-open-sdg-plugins/multilingual_metadata.rb
61
59
  - lib/jekyll-open-sdg-plugins/sdg_variables.rb
62
60
  - lib/jekyll-open-sdg-plugins/translate_key.rb
63
61
  - lib/jekyll-open-sdg-plugins/version.rb
@@ -1,146 +0,0 @@
1
- require "jekyll"
2
- require_relative "helpers"
3
-
4
- # This plugin will be removed before version 1.0.0.
5
- # Do not rely on this!
6
-
7
- module Jekyll
8
- module IndicatorName
9
-
10
- # Takes an indicator ID (dot-delimited or dash-delimited) and returns the
11
- # translated indicator name (according to the current language). This lookup
12
- # is as forgiving as possible, to make sure that something is always there.
13
- #
14
- # The order of preference in the lookup is:
15
- #
16
- # 1. "indicator_name_national" in translated metadata - subfolder approach
17
- # 2. "indicator_name_national" in translated metadata - translation key approach
18
- # 3. If the default language, "indicator_name_national" in non-translated metadata
19
- # 4. If a global indicator, translated global indicator name
20
- # 5. "indicator_name" in translated metadata - subfolder approach
21
- # 6. "indicator_name" in translated metadata - translation key approach
22
- # 7. "indicator_name" in non-translated metadata
23
- # 8. Finally, fall back to the indicator ID
24
-
25
- def get_indicator_name(inid)
26
-
27
- # Safety code - abort now if id is nil.
28
- if inid.nil?
29
- return ""
30
- end
31
-
32
- # Also make sure it is a string, and otherwise just return it.
33
- if not inid.is_a? String
34
- return inid
35
- end
36
-
37
- # More safety code - abort now if inid is empty.
38
- if inid.empty?
39
- return ""
40
- end
41
-
42
- # Normalize around dash-delimited inids.
43
- inid = inid.gsub('.', '-')
44
-
45
- # Some variables to help our lookups later.
46
- page = @context.environments.first['page']
47
- language = page['language']
48
- languages = @context.registers[:site].config['languages']
49
- data = @context.registers[:site].data
50
- translations = data['translations']
51
- meta = data['meta'][inid]
52
-
53
- # The metadata fields that we'll seek, first "override" then "default".
54
- override_field = 'indicator_name_national'
55
- default_field = 'indicator_name'
56
-
57
- name = false
58
-
59
- # 1. Is there a subfolder translation of the override field?
60
- if meta and meta.has_key? language
61
- if !name and meta[language].has_key? override_field
62
- name = meta[language][override_field]
63
- end
64
- end
65
-
66
- # 2. Is the override field actually a "translation key"?
67
- if !name
68
- if meta and meta.has_key? override_field
69
- untranslated = meta[override_field]
70
- translated = opensdg_translate_key(untranslated, translations, language)
71
- if untranslated != translated
72
- # If the opensdg_translate_key() function returned something else,
73
- # that means it was an actual "translation key".
74
- name = translated
75
- end
76
- end
77
- end
78
-
79
- # 3. If this is the default language, use the non-translated override
80
- # field, if available.
81
- if !name
82
- if language == languages[0]
83
- if meta and meta.has_key? override_field
84
- name = meta[override_field]
85
- end
86
- end
87
- end
88
-
89
- # 4. Is this a global indicator with a translation?
90
- if !name
91
- title_key = inid + '-title'
92
- # For backwards compatibility, look for both dot and dash-delimited keys.
93
- title_key_dots = inid.gsub('-', '.') + '-title'
94
- if translations.has_key? language
95
- if translations[language].has_key? 'global_indicators'
96
- if translations[language]['global_indicators'].has_key? title_key
97
- name = translations[language]['global_indicators'][title_key]
98
- elsif translations[language]['global_indicators'].has_key? title_key_dots
99
- name = translations[language]['global_indicators'][title_key_dots]
100
- end
101
- end
102
- end
103
- end
104
-
105
- # 5. Is there a subfolder translation of the default field?
106
- if !name
107
- if meta and meta.has_key? language
108
- if !name and meta[language].has_key? default_field
109
- name = meta[language][default_field]
110
- end
111
- end
112
- end
113
-
114
- # 6. Is the default field actually a "translation key"?
115
- if !name
116
- if meta and meta.has_key? default_field
117
- untranslated = meta[default_field]
118
- translated = opensdg_translate_key(untranslated, translations, language)
119
- if untranslated != translated
120
- # If the opensdg_translate_key() function returned something else,
121
- # that means it was an actual "translation key".
122
- name = translated
123
- end
124
- end
125
- end
126
-
127
- # 7. Use the non-translated default field, if available.
128
- if !name
129
- if meta and meta.has_key? default_field
130
- name = meta[default_field]
131
- end
132
- end
133
-
134
- # 8. Still here? Just return the inid.
135
- if !name
136
- name = inid
137
- end
138
-
139
- # Finally return the name with key translation for good measure.
140
- return opensdg_translate_key(name, translations, language)
141
-
142
- end
143
- end
144
- end
145
-
146
- Liquid::Template.register_filter(Jekyll::IndicatorName)
@@ -1,32 +0,0 @@
1
- require "jekyll"
2
-
3
- # This plugin will be removed before version 1.0.0.
4
- # Do not rely on this!
5
-
6
- module JekyllOpenSdgPlugins
7
- class MultilingualMetadataGenerator < Jekyll::Generator
8
- safe true
9
- priority :low
10
-
11
- def generate(site)
12
- # Make sure that the translated metadata contains a complete set of values
13
- # including non-translated metadata as a fallback. This allows us to treat
14
- # the translated metadata as complete when used in layouts and includes.
15
- if site.config['languages']
16
- site.config['languages'].each do |language|
17
- site.data['meta'].each do |indicator_id, meta|
18
- if meta[language]
19
- meta.each do |meta_key, meta_value|
20
- unless site.config['languages'].include? meta_key
21
- if !meta[language][meta_key]
22
- meta[language][meta_key] = meta_value
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end