jekyll-open-sdg-plugins 1.0.0.rc3 → 1.0.0.rc4

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: e906019810630c3739bf804892b5dfcee29161b4ff5a21cc030aedf1e0897118
4
- data.tar.gz: e1d7a573e7a3d621ea6407fde873be79b363efc38f21222fbd2e8ba9a34a5e05
3
+ metadata.gz: 8f50ca10fd9350b8b2e3010b8c17e971f38a4e49fc9866c6218f4f1486374a3f
4
+ data.tar.gz: 956ad212e0d4288410d4c121ad41d761a50e4e7ad4242db30f956db7310514de
5
5
  SHA512:
6
- metadata.gz: 71b97782ea83f10d1452635692bc70428c1e61e6f8d6573898a20c6a8c6da315436c829497c8993ac75c9de2c6cabc7ad1380115a51e70f7bdd3be9605db1de3
7
- data.tar.gz: 01a33c0033be841a0c181713c25da5fc16e59c453e57965b21114b13a536d1f3f54289a1878ffef832c9a875190f871fc7b4fb26326d0c20db4f5bb2bdc66110
6
+ metadata.gz: 559450040341021d19676dc1a57fed8cfadc42662ddeea40e7dd684e2dc57dd28735a62c27ea6aa594f3d030254cbd4fde9077cd8e632537e9feb7da51b0d754
7
+ data.tar.gz: 0af25756fd6504bb2d658fd62788386a57f5b7bea83435a276a0c4472c54f745070eea22f03e2ef8a1e5284e6052131f8173bc5e4b1faa2b54a2c26c168b85f9
@@ -5,6 +5,7 @@ require_relative "jekyll-open-sdg-plugins/translate_key"
5
5
  require_relative "jekyll-open-sdg-plugins/create_indicators"
6
6
  require_relative "jekyll-open-sdg-plugins/create_goals"
7
7
  require_relative "jekyll-open-sdg-plugins/create_pages"
8
+ require_relative "jekyll-open-sdg-plugins/get_indicator_name"
8
9
  require_relative "jekyll-open-sdg-plugins/sdg_variables"
9
10
 
10
11
  module JekyllOpenSdgPlugins
@@ -0,0 +1,143 @@
1
+ require "jekyll"
2
+ require_relative "helpers"
3
+
4
+ module Jekyll
5
+ module IndicatorName
6
+
7
+ # Takes an indicator ID (dot-delimited or dash-delimited) and returns the
8
+ # translated indicator name (according to the current language). This lookup
9
+ # is as forgiving as possible, to make sure that something is always there.
10
+ #
11
+ # The order of preference in the lookup is:
12
+ #
13
+ # 1. "indicator_name_national" in translated metadata - subfolder approach
14
+ # 2. "indicator_name_national" in translated metadata - translation key approach
15
+ # 3. If the default language, "indicator_name_national" in non-translated metadata
16
+ # 4. If a global indicator, translated global indicator name
17
+ # 5. "indicator_name" in translated metadata - subfolder approach
18
+ # 6. "indicator_name" in translated metadata - translation key approach
19
+ # 7. "indicator_name" in non-translated metadata
20
+ # 8. Finally, fall back to the indicator ID
21
+
22
+ def get_indicator_name(inid)
23
+
24
+ # Safety code - abort now if id is nil.
25
+ if inid.nil?
26
+ return ""
27
+ end
28
+
29
+ # Also make sure it is a string, and otherwise just return it.
30
+ if not inid.is_a? String
31
+ return inid
32
+ end
33
+
34
+ # More safety code - abort now if inid is empty.
35
+ if inid.empty?
36
+ return ""
37
+ end
38
+
39
+ # Normalize around dash-delimited inids.
40
+ inid = inid.gsub('.', '-')
41
+
42
+ # Some variables to help our lookups later.
43
+ page = @context.environments.first['page']
44
+ language = page['language']
45
+ languages = @context.registers[:site].config['languages']
46
+ data = @context.registers[:site].data
47
+ translations = data['translations']
48
+ meta = data['meta'][inid]
49
+
50
+ # The metadata fields that we'll seek, first "override" then "default".
51
+ override_field = 'indicator_name_national'
52
+ default_field = 'indicator_name'
53
+
54
+ name = false
55
+
56
+ # 1. Is there a subfolder translation of the override field?
57
+ if meta and meta.has_key? language
58
+ if !name and meta[language].has_key? override_field
59
+ name = meta[language][override_field]
60
+ end
61
+ end
62
+
63
+ # 2. Is the override field actually a "translation key"?
64
+ if !name
65
+ if meta and meta.has_key? override_field
66
+ untranslated = meta[override_field]
67
+ translated = opensdg_translate_key(untranslated, translations, language)
68
+ if untranslated != translated
69
+ # If the opensdg_translate_key() function returned something else,
70
+ # that means it was an actual "translation key".
71
+ name = translated
72
+ end
73
+ end
74
+ end
75
+
76
+ # 3. If this is the default language, use the non-translated override
77
+ # field, if available.
78
+ if !name
79
+ if language == languages[0]
80
+ if meta and meta.has_key? override_field
81
+ name = meta[override_field]
82
+ end
83
+ end
84
+ end
85
+
86
+ # 4. Is this a global indicator with a translation?
87
+ if !name
88
+ title_key = inid + '-title'
89
+ # For backwards compatibility, look for both dot and dash-delimited keys.
90
+ title_key_dots = inid.gsub('-', '.') + '-title'
91
+ if translations.has_key? language
92
+ if translations[language].has_key? 'global_indicators'
93
+ if translations[language]['global_indicators'].has_key? title_key
94
+ name = translations[language]['global_indicators'][title_key]
95
+ elsif translations[language]['global_indicators'].has_key? title_key_dots
96
+ name = translations[language]['global_indicators'][title_key_dots]
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ # 5. Is there a subfolder translation of the default field?
103
+ if !name
104
+ if meta and meta.has_key? language
105
+ if !name and meta[language].has_key? default_field
106
+ name = meta[language][default_field]
107
+ end
108
+ end
109
+ end
110
+
111
+ # 6. Is the default field actually a "translation key"?
112
+ if !name
113
+ if meta and meta.has_key? default_field
114
+ untranslated = meta[default_field]
115
+ translated = opensdg_translate_key(untranslated, translations, language)
116
+ if untranslated != translated
117
+ # If the opensdg_translate_key() function returned something else,
118
+ # that means it was an actual "translation key".
119
+ name = translated
120
+ end
121
+ end
122
+ end
123
+
124
+ # 7. Use the non-translated default field, if available.
125
+ if !name
126
+ if meta and meta.has_key? default_field
127
+ name = meta[default_field]
128
+ end
129
+ end
130
+
131
+ # 8. Still here? Just return the inid.
132
+ if !name
133
+ name = inid
134
+ end
135
+
136
+ # Finally return the name with key translation for good measure.
137
+ return opensdg_translate_key(name, translations, language)
138
+
139
+ end
140
+ end
141
+ end
142
+
143
+ Liquid::Template.register_filter(Jekyll::IndicatorName)
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "1.0.0.rc3".freeze
2
+ VERSION = "1.0.0.rc4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.rc3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brock Fanning
@@ -55,6 +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
58
59
  - lib/jekyll-open-sdg-plugins/helpers.rb
59
60
  - lib/jekyll-open-sdg-plugins/multilingual_metadata.rb
60
61
  - lib/jekyll-open-sdg-plugins/sdg_variables.rb