Skip to content

Commit 16bb7f9

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 16bb7f9

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

app/controllers/org_domain_controller.rb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,36 @@ 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 vaule 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
60+
title = org['names'].find { |n| n['lang'] && n['types']&.include?('ror_display') }
61+
puts "title: #{title}"
5062
# ror_id_formatted = org['id'].split('/').last
51-
org_id_new_format = {name: title['value']}.to_json
63+
org_name = title ? title['value'] : nil
64+
puts "org_name: #{org_name}"
65+
# We really want the name in English, so we look for the name with lang 'en' and type 'label'
66+
# If not found, we use the org_name as a fallback
67+
display = org['names'].find { |n| n['lang']&.include?('en') && n['types']&.include?('label') }
68+
puts "display: #{display}"
69+
display_name = display ? display['value'] : org_name
70+
puts "display_name: #{display_name}"
71+
# If display_name is nil, skip this org
72+
break if display_name.nil?
73+
74+
# ror_id_formatted = org['id'].split('/').last
75+
org_id_new_format = {name: display_name}.to_json
5276
{
5377
id: org_id_new_format,
54-
org_name: title ? title['value'] : 'Name not found',
78+
org_name: display_name,
5579
domain: '',
5680
}
5781
rescue => e

0 commit comments

Comments
 (0)