Skip to content

Commit f5296a8

Browse files
author
John Pinto
committed
If we get the ROR data in the search we would prefer to display the Org
name in English. As the ROR display value is in the language of the country. This commit attempts to find the name of type label for lang 'en' and display it. The fallback is the ror_display type value which is in the language of the country of the org.
1 parent 927d88b commit f5296a8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

app/controllers/org_domain_controller.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,35 @@ def index
4646

4747
# Extract the values from API result
4848
result = full_org_json['orgs'].map do |org|
49-
title = org['names'].find { |n| n['types'].include?('ror_display') }
49+
puts "org: #{org}"
50+
# NOTE: lang value in a names array is not always present and can be null,
51+
# e.g., {
52+
# "lang": null,
53+
# "types": [
54+
# "acronym"
55+
# ],
56+
# "value": "XYZ"
57+
# },
58+
59+
# The ror_display value will be in the language of the country, and should always be present.
60+
ror_display_name_json = org['names'].find { |n| n['lang'] && n['types']&.include?('ror_display') }
61+
puts "ror_display_name_json: #{ror_display_name_json}"
62+
org_name = ror_display_name_json ? ror_display_name_json['value'] : nil
63+
puts "org_name: #{org_name}"
64+
# We really want the name in English, so we look for the name with lang 'en' and type 'label'
65+
# If not found, we use the org_name as a fallback
66+
en_label_name_json = org['names'].find { |n| n['lang']&.include?('en') && n['types']&.include?('label') }
67+
puts "en_label_name_json: #{en_label_name_json}"
68+
display_name = en_label_name_json ? en_label_name_json['value'] : org_name
69+
puts "display_name: #{display_name}"
70+
# If display_name is nil, skip this org
71+
break if display_name.nil?
72+
5073
# ror_id_formatted = org['id'].split('/').last
51-
org_id_new_format = {name: title['value']}.to_json
74+
org_id_new_format = { name: display_name }.to_json
5275
{
5376
id: org_id_new_format,
54-
org_name: title ? title['value'] : 'Name not found',
77+
org_name: display_name,
5578
domain: '',
5679
}
5780
rescue => e

0 commit comments

Comments
 (0)