-
Notifications
You must be signed in to change notification settings - Fork 20
Language of Event feature. #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Oops, looks like I have |
|
Thanks for this! Not had a chance to have a detailed review yet, but I was wondering did you consider using a gem to provide the list of language codes/names? e.g. https://github.com/xwmx/iso-639 |
|
I had not considered getting it from a gem. Some thoughts on that specific gem:
|
fbacall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great PR - super clean implementation.
Sorry for not mentioning before (because I'd forgotten about it), but we do actually have some existing code for handling languages that was used in the "Trainer" profile feature:
TeSS/app/helpers/application_helper.rb
Lines 570 to 596 in a2d3a59
| def language_options_for_select(priority = priority_languages) | |
| priors = [] | |
| others = [] | |
| I18nData.languages.each do |lang| | |
| next unless lang and !lang.empty? | |
| value = lang[1] | |
| key = lang[0] | |
| # Rails.logger.debug "language: key[#{key}] value[#{value}]" | |
| if priority and !priority.empty? and priority.include?(key) | |
| priors << [value, key] | |
| else | |
| others << [value, key] | |
| end | |
| end | |
| priors + others | |
| end | |
| def language_label_by_key(key) | |
| return unless key and !key.nil? | |
| I18nData.languages.each do |lang| | |
| return lang[1] if lang[0] == key | |
| end | |
| end |
This was added by the guys working on the DReSA instance, but we haven't yet enabled it on our ELIXIR deployment.
Perhaps you could re-use some of that for handling the language keys and names?
(The language selection form on the trainer profile does currently display a huge list of languages like you were worried about, but could be filtered down)
app/helpers/search_helper.rb
Outdated
|
|
||
| # TODO: is there a better way? | ||
| if name == 'language' | ||
| title = render_language_name(value) | ||
| end | ||
| title ||= (html_options.delete(:title) || truncate(value.to_s, length: 50)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not currently, but I would move this logic into a method that takes the facet name and value and handles the special case for language, otherwise falls back to truncate(value.to_s, length: 50) as below.
app/models/concerns/has_language.rb
Outdated
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| validates :language, controlled_vocabulary_or_nil: { dictionary: 'LanguageDictionary' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass a allow_nil option to the existing vocab validator to get this behaviour:
controlled_vocabulary: { dictionary: 'LanguageDictionary', allow_nil: true }
|
Thanks for the review!
|
I think I like the idea of them being listed in an array in
I agree it's not very nice, although the spec says they are case-insensitive. I think we should go with lower case. We can just down-case the keys from the trainers table when they are read to be consistent (or write a migration to convert the stored data).
How about we list the EU language names under a |
* remove languages.yml
* override language names from I18nData with `I18n.t("languages.#{code}")`
|
This all sounds reasonable. I've integrated all of those suggestions in the latest push. |
fbacall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small simplification, otherwise looks good
* Test LanguageDictionary#render_language_name

Summary of changes
This adds a "Language of Instruction" feature to events, as per #994
The languages supported are the 24 official languages of the EU:
https://european-union.europa.eu/principles-countries-history/languages_en
Motivation and context
We (Canada) need this feature for the bilingual instance of TeSS we are working on, so thought it might be better to push this upstream too.
We'll see how this goes, and then add a similar feature for learning materials in the future.
Checklist
to license it to the TeSS codebase under the
BSD license.