<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rmjohn2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rmjohn2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Rmjohn2"/>
	<updated>2026-05-12T06:12:22Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142534</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142534"/>
		<updated>2021-11-30T22:12:41Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: /* Automated Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
'''UPDATE: All of the below tests have been automated.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&amp;lt;br&amp;gt;&lt;br /&gt;
These feature tests cover all the functionality introduced as explained in the Manual Tests section above.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''internationalization_spec.rb''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
In addition to feature tests, we have also introduced unit tests for code that drives the I18n library:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''locale_spec.rb''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2159 UnitTests.png]]&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2159_UnitTests.png&amp;diff=142531</id>
		<title>File:E2159 UnitTests.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2159_UnitTests.png&amp;diff=142531"/>
		<updated>2021-11-30T22:11:33Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Rmjohn2 uploaded a new version of File:E2159 UnitTests.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2159_UnitTests.png&amp;diff=142530</id>
		<title>File:E2159 UnitTests.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2159_UnitTests.png&amp;diff=142530"/>
		<updated>2021-11-30T22:10:36Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142529</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142529"/>
		<updated>2021-11-30T22:10:04Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: /* Automated Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
'''UPDATE: All of the below tests have been automated.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&amp;lt;br&amp;gt;&lt;br /&gt;
These feature tests cover all the functionality introduced as explained in the Manual Tests section above.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''internationalization_spec.rb''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
In addition to feature tests, we have also introduced unit tests for code that drives the I18n library:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''locale_spec.rb''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2159_UnitTests.png]]&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142526</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142526"/>
		<updated>2021-11-30T22:09:10Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Unit tests&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
'''UPDATE: All of the below tests have been automated.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&lt;br /&gt;
These feature tests cover all the functionality introduced as explained in the Manual Tests section above.&lt;br /&gt;
&lt;br /&gt;
''internationalization_spec.rb''&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
In addition to feature tests, we have also introduced unit tests for code that drives the I18n library:&lt;br /&gt;
&lt;br /&gt;
''locale_spec.rb''&lt;br /&gt;
[[File:UnitTests.png]]&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142521</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142521"/>
		<updated>2021-11-30T22:02:27Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Manual tests are automated&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
'''UPDATE: All of the below tests have been automated.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&lt;br /&gt;
These feature tests cover all the functionality introduced.&lt;br /&gt;
&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142431</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142431"/>
		<updated>2021-11-30T18:08:04Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: /* Automated Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&lt;br /&gt;
These feature tests cover all the functionality introduced.&lt;br /&gt;
&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:FeatureTesting10.png&amp;diff=142429</id>
		<title>File:FeatureTesting10.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:FeatureTesting10.png&amp;diff=142429"/>
		<updated>2021-11-30T18:07:30Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142428</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142428"/>
		<updated>2021-11-30T18:06:43Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: /* Automated Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&lt;br /&gt;
These feature tests cover all the functionality introduced.&lt;br /&gt;
&lt;br /&gt;
[[File:FeatureTesting10.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:FeatureTesting.png&amp;diff=142426</id>
		<title>File:FeatureTesting.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:FeatureTesting.png&amp;diff=142426"/>
		<updated>2021-11-30T18:00:41Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142425</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=142425"/>
		<updated>2021-11-30T18:00:11Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added code snippet&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Important Links ==&lt;br /&gt;
*Git PR - https://github.com/expertiza/expertiza/pull/2151&lt;br /&gt;
*Git beta branch - https://github.com/arnavjulka/expertiza/tree/beta&lt;br /&gt;
*Overall Video - https://drive.google.com/file/d/1dc9St9J77q-Mb_vRuYBg4vs9Xv0SHm4d/view?usp=sharing&lt;br /&gt;
*Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Twophase2.jpg|none|700px]]&amp;lt;br&amp;gt;&lt;br /&gt;
'''1. Language selection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Every user has an option to set a language preference in the User Profile Information Edit page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ProfileEditPage.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
There is also an option where the instructor can choose a default language for a course. &lt;br /&gt;
&lt;br /&gt;
[[File:language2inter.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thus, the language not only varies from user to user but also across screens for the same user. Thus we need to recompute the language in which the page is to be rendered. If the student has given a language preference, then the choice is given weightage over the course default language chosen by the instructor. &lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
What if the translation for the target language is not available?&lt;br /&gt;
Even translation for a language like Hindi may be available in general, the translation for a given text may not be available Hindi. This may be due to a variety of reasons:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The specific text may have been accidentally missed out (remember the translation is not being done at runtime through an API, but rather curated by the developer)&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The given text is non-trivial to translate to the target language&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
Our design would thus need to accommodate this by seamlessly falling back on another language whose translation is available.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
The scope of this project is limited however only to static strings. I.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
'''Proposed Solution''' &amp;lt;br&amp;gt;&lt;br /&gt;
We explore and solve each of the three problems above in isolation:&lt;br /&gt;
&lt;br /&gt;
'''''1. Language selection'''''&amp;lt;br&amp;gt;&lt;br /&gt;
The language in which the page is rendered depends on a set of conditions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has set a language preference all pages are displayed in that language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is an instructor, all the pages are displayed in English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the user has not set a language preference and the user is a student who is on a page that is specific to a course for which the instructor has added a default language, the page is displayed in the course’s default language.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below functions are added and called before page rendering to bring in this logic.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    # Checks whether the user is logged in, else the default locale is used&lt;br /&gt;
    if logged_in?&lt;br /&gt;
      # If the current user has set his preferred language, the locale is set according to their preference&lt;br /&gt;
      if @current_user.locale != &amp;quot;no_pref&amp;quot;&lt;br /&gt;
        I18n.locale = @current_user.locale&lt;br /&gt;
        # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used&lt;br /&gt;
      elsif current_user_role? &amp;amp;&amp;amp; current_user_role.student? &amp;amp;&amp;amp; [&amp;quot;student_task&amp;quot;, &amp;quot;sign_up_sheet&amp;quot;, &amp;quot;student_teams&amp;quot;, &amp;quot;student_review&amp;quot;, &amp;quot;grades&amp;quot;, &amp;quot;submitted_content&amp;quot;, &amp;quot;participants&amp;quot;].include?(params[:controller])&lt;br /&gt;
        set_new_locale_for_student&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def set_new_locale_for_student&lt;br /&gt;
    # Gets participant using student from params&lt;br /&gt;
    if !params[:id].nil? || !params[:student_id].nil?&lt;br /&gt;
      participant_id = params[:id] || params[:student_id]&lt;br /&gt;
      participant = AssignmentParticipant.find_by(id: participant_id)&lt;br /&gt;
      # If id or student_id not correct, revert to locale based on courses.&lt;br /&gt;
      if participant.nil?&lt;br /&gt;
        find_locale_from_courses&lt;br /&gt;
        return&lt;br /&gt;
      end&lt;br /&gt;
      # Find assignment from participant and find locale from the assigment&lt;br /&gt;
      assignment = participant.assignment&lt;br /&gt;
      if !assignment.course.nil?&lt;br /&gt;
        new_locale = assignment.course.locale&lt;br /&gt;
        if !new_locale.nil?&lt;br /&gt;
          I18n.locale = new_locale&lt;br /&gt;
        else&lt;br /&gt;
          I18n.locale = I18n.default_locale&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      find_locale_from_courses&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def find_locale_from_courses&lt;br /&gt;
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if&lt;br /&gt;
    # the language for all these course are same, the page is displayed in that language&lt;br /&gt;
  courseParticipants = CourseParticipant.where(user_id: current_user.id)&lt;br /&gt;
    courseParticipantsLocales = courseParticipants.map { |cp| cp.course.locale }&lt;br /&gt;
    # If no tasks, then possible to have no courses assigned.&lt;br /&gt;
    if courseParticipantsLocales.uniq.length == 1 #&amp;amp;&amp;amp; !@tasks.empty?&lt;br /&gt;
      course = courseParticipants.first.course&lt;br /&gt;
      if course.locale?&lt;br /&gt;
        I18n.locale = course.locale&lt;br /&gt;
      else&lt;br /&gt;
        I18n.locale = I18n.default_locale&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      I18n.locale = I18n.default_locale&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;If the student user has not set a language preference and is not on a course-specific page, then the page is displayed in English.&lt;br /&gt;
If a language preference is obtained by following the above conditions but some keys in the page don't have a translation for the language, the English translation for that key is returned as a fallback.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Doing it ourselves felt like a great option. But i18n not just selects a language string at runtime for us it does a lot more under the hood which makes our lives easier. For example, it manages locale over the session for us, even if we change the urls and shift tabs and other stuff it manages our locale. &amp;lt;br&amp;gt;&lt;br /&gt;
Also there is a great principle that says - “ If it isn’t broken, Don’t fix it”. The library manages the registering of different language yml files, points to the right right text at runtime, manages session locale and a lot more. So we want to explore this library instead of reimplementing the same thing again.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3, Why did we store the default language choices in database instead of in session?'''&amp;lt;br&amp;gt;&lt;br /&gt;
We had to decide on whether to keep the student’s language preference in the database or in the session. We have thought about both approaches and below listed are the advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
In the work done by the previous team, they added a dropdown in the navbar where a student can choose the preferred language. One of the changes that we did was to move this field to the user profile page. The earlier team used session storage to store the preferred language. This session resets on every logout, but since the preferred language can easily be set from any page this wasn't much of an issue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing user language preference in database.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	If we are moving the language preference field to the user profile page, it will create some user experience issues if the preference is stored in session. The student will have to visit the user profile page every time they log in. To avoid this scenario, it’s better to keep the language preference in the database, so that the preference stays saved across sessions.&lt;br /&gt;
	The disadvantage of moving the language preference to the database is that it brings forth a schema change and this always requires a very careful going through to ensure that nothing else is affected. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Storing language preference in session storage.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main advantage of storing the language preference in session storage is that no schema change is involved. This decreases the chance of other features being affected. The main disadvantage is that the student will have to go to the user profile page every time they log in to set the preference, causing a user experience issue. Keep in mind that we’re moving the field away from the navbar to a user profile page.&lt;br /&gt;
&lt;br /&gt;
After considering these points, we finally decided to go store the user preference in the database itself as the project requires us to add a language preference field in user profile page.&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&amp;lt;li&amp;gt;An instructor can add a default language to any course. English is the default choice.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The user has an option to change their preferred language at any time. They have the option to do so in their profile page. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;All pages including the course-related and non-course-related pages are displayed in the user preferred language for any user other than student&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every non-course-related page is displayed in the student’s preferred language. Keys for which a translation is not found are displayed in the default language that is English&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Every course-related page is displayed in the student’s preferred language. If the student doesn’t have a preferred language, the course is displayed in the course’s preferred language. Keys for which a translation is not found are displayed in the default language that is English.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:usecasediagram.png|2000px|865px]]&lt;br /&gt;
&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
We add the locale field to the users and courses tables which has the default values 0 and 1, which is no preference and en_US respectively.&lt;br /&gt;
&lt;br /&gt;
The migrations will look as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLangLocaleToUsers &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :users, :locale, :integer, default: 0&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class AddLocaleToCourses &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
    add_column :courses, :locale, :integer, default: 1&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Database Modification ==&lt;br /&gt;
We add a new integer field to the users table to store the user preferred language. The integer will be hashed to the supported languages. The default value in the table will be 0, which will be no_pref.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      no_pref: 0,&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We also add a new integer field to the courses table to store the course preferred language. The integer will be hashed to the supported languages. The default value in the table will be 1, which will be en_US.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enum locale: {&lt;br /&gt;
      en_US: 1,&lt;br /&gt;
      hi_IN: 2&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hence the updated courses table will look like following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;courses&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string   &amp;quot;name&amp;quot;,            limit: 255&lt;br /&gt;
    t.integer  &amp;quot;instructor_id&amp;quot;,   limit: 4&lt;br /&gt;
    t.string   &amp;quot;directory_path&amp;quot;,  limit: 255&lt;br /&gt;
    t.text     &amp;quot;info&amp;quot;,            limit: 65535&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;&lt;br /&gt;
    t.boolean  &amp;quot;private&amp;quot;,                       default: false, null: false&lt;br /&gt;
    t.integer  &amp;quot;institutions_id&amp;quot;, limit: 4&lt;br /&gt;
    t.integer  &amp;quot;locale&amp;quot;,          limit: 4,     default: 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the updated users table will look like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create_table &amp;quot;users&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.string  &amp;quot;name&amp;quot;,                      limit: 255,      default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.string  &amp;quot;crypted_password&amp;quot;,          limit: 40,       default: &amp;quot;&amp;quot;,    null: false&lt;br /&gt;
    t.integer &amp;quot;role_id&amp;quot;,                   limit: 4,        default: 0,     null: false&lt;br /&gt;
    t.string  &amp;quot;password_salt&amp;quot;,             limit: 255&lt;br /&gt;
    t.string  &amp;quot;fullname&amp;quot;,                  limit: 255&lt;br /&gt;
    t.string  &amp;quot;email&amp;quot;,                     limit: 255&lt;br /&gt;
    t.integer &amp;quot;parent_id&amp;quot;,                 limit: 4&lt;br /&gt;
    t.boolean &amp;quot;private_by_default&amp;quot;,                         default: false&lt;br /&gt;
    t.string  &amp;quot;mru_directory_path&amp;quot;,        limit: 128&lt;br /&gt;
    t.boolean &amp;quot;email_on_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_submission&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;email_on_review_of_review&amp;quot;&lt;br /&gt;
    t.boolean &amp;quot;is_new_user&amp;quot;,                                default: true,  null: false&lt;br /&gt;
    t.integer &amp;quot;master_permission_granted&amp;quot;, limit: 1,        default: 0&lt;br /&gt;
    t.string  &amp;quot;handle&amp;quot;,                    limit: 255&lt;br /&gt;
    t.text    &amp;quot;digital_certificate&amp;quot;,       limit: 16777215&lt;br /&gt;
    t.string  &amp;quot;persistence_token&amp;quot;,         limit: 255&lt;br /&gt;
    t.string  &amp;quot;timezonepref&amp;quot;,              limit: 255&lt;br /&gt;
    t.text    &amp;quot;public_key&amp;quot;,                limit: 16777215&lt;br /&gt;
    t.boolean &amp;quot;copy_of_emails&amp;quot;,                             default: false&lt;br /&gt;
    t.integer &amp;quot;institution_id&amp;quot;,            limit: 4&lt;br /&gt;
    t.boolean &amp;quot;preference_home_flag&amp;quot;,                       default: true&lt;br /&gt;
    t.integer &amp;quot;locale&amp;quot;,                    limit: 4,        default: 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The locale field is the last column on both tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    courses:&amp;gt; t.integer  &amp;quot;locale&amp;quot;,  limit: 4,    default: 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      users:&amp;gt; t.integer &amp;quot;locale&amp;quot;,   limit: 4,    default: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
&lt;br /&gt;
Through manual testing, we aim to identify if all the features of the application are working as intended when the language conversion occurs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 1&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3. Check to see if the English strings on the profile page are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
4. Check if a page for which Hindi translation keys are added has its English static strings translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 2&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to No Preferences.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to an assignment page for which Hindi translation keys are added, which is under a course with the default language set to Hindi, and check whether the English strings are translated to Hindi.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 3&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Nil.&lt;br /&gt;
&lt;br /&gt;
3.  Check to see if the English strings on the page are unchanged, as the “User Profile Information” translates only if the student has a preference.&lt;br /&gt;
&lt;br /&gt;
4. Go to a non-course-specific page and verify that the page is displayed in English itself, as non of the default languages set for any of the courses should have any role.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Scenario 4&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza as a student.&lt;br /&gt;
&lt;br /&gt;
2. Go to the “User Profile Information” page and change “Preferred Language” to Hindi.&lt;br /&gt;
&lt;br /&gt;
3.  Go to a page where translation keys aren’t added completely and make sure that the unspecified keys display strings in English as a fallback.&lt;br /&gt;
&lt;br /&gt;
===Automated Testing===&lt;br /&gt;
The following screenshot describes the complete feature tests introduced as part of this project.&lt;br /&gt;
These feature tests cover all the functionality introduced.&lt;br /&gt;
&lt;br /&gt;
[[File:FeatureTesting.png]]&lt;br /&gt;
&lt;br /&gt;
Testing Video - https://drive.google.com/file/d/1TOatjhe0wzxTpmWDuC_ryVFmtQ-X7FJq/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently most course specific pages translated according to course language preference when the user has not provided any preference, but we need to identify if we have left out any other course specific page and add those to the list of pages which should take the course language setting into consideration.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140536</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140536"/>
		<updated>2021-11-03T01:48:42Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added introduction section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png|none|500px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Survey of home country of Expertiza users for a given course&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
'''Breaking down internationalization into 3 sequential subproblems:'''&lt;br /&gt;
&lt;br /&gt;
'''1. Language selection'''&lt;br /&gt;
@rsabu&lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language?&amp;lt;br&amp;gt;&lt;br /&gt;
To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.1 Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''2.2 Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Rendering the language&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:i18n.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3, Do we store the language preference, in the session or in the database?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@rsabu&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Chainofresp.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The I18n library gives us an option to have many fall back options. When the required text for a given language is not found, we then move on to find the text for the next language in the chain and so on until we find it. And in the end we will put english as default language. So if the key value pair for the text is not found in none of the yml files then the text will be fetched from the English language yml file.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently made the assignment screen display in the course’s language, however other screens such as the “Your work” screen and so on are also specific to the course could also be rendered in the course language when the user has not provided a preference.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Country_pie.png&amp;diff=140521</id>
		<title>File:Country pie.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Country_pie.png&amp;diff=140521"/>
		<updated>2021-11-03T01:34:05Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Distribution of students in a course by country&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Distribution of students in a course by country&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140520</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140520"/>
		<updated>2021-11-03T01:32:25Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: /* Introduction - Purpose &amp;amp; Problem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
&lt;br /&gt;
Currently, all Expertiza screens can only be viewed in English. Many Expertiza users are from other countries. This is a problem since this limits the accessibility of Expertiza. An important step in solving this problem is by making Expertiza available in more languages, which is a form of internationalization.&lt;br /&gt;
W3C defines [https://www.w3.org/International/questions/qa-i18n internationalization] as “''the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.''”&lt;br /&gt;
&lt;br /&gt;
[[File:country_pie.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Fig: Survey of home country of Expertiza users for a given course&lt;br /&gt;
&lt;br /&gt;
Breaking down internationalization into 3 sequential subproblems:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Scope:''' The scope of this project is limited however only to static strings. i.e. user-generated content will not be automatically translated to other languages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''1. Language selection'''&lt;br /&gt;
&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language? To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''*Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3. Translation gaps'''&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Rendering the language&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''I18n - Internationalisation, How are we using I18n in Ruby on Rail'''''&amp;lt;br&amp;gt;&lt;br /&gt;
I18n is a ruby library/gem which helps us render the static string on the view dynamically. Dynamicity means that based on a local decision of choosing the current language of the view, the library returns the strings of that particular language at runtime.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
These strings, instead of hardcoding in the view.rb, are provided in external .yml files. Now at the View level, we can pass an id to the 't' function and the I18n library returns the string for that id of the current set language(called as locale). &lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
For this purpose, we have to provide .yml files for each language and in those language-specific .yml, we have to provide a map of key-value pairs where the key is the id of the string and value is the string in that particular language. By default the language or locale is set to be English(:en). &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
THE GREATEST BENEFITS of using this library are - &amp;lt;br&amp;gt;&lt;br /&gt;
*The strings aren't hardcoded in the code/build. The strings are being fetched from external files which can be easily modified. For example, if one needs to change the text from 'Please Help' to 'Help', then one just needs to make a change in the .yml file and the change would reflect on the browser. For this change, we didn't need to redeploy the server. We just Decoupled the view when and where from what content is to be shown. &lt;br /&gt;
*Adding more languages is now super easy. Adding support for another language is just one line change in the config and adding a .yml file (having all the key-value pairs for the strings) for the new language. By doing this we can extend the language support as much as we want.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''3. Translation gaps'''''&lt;br /&gt;
&amp;lt;br&amp;gt;Also, if the language is set to be Hindi or any other language but the key-value pair is not set for that particular string then, automatically the library returns the default which is the English text.&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;config.i18n.fallbacks = [:en]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3, Do we store the language preference, in the session or in the database?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@rsabu&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently made the assignment screen display in the course’s language, however other screens such as the “Your work” screen and so on are also specific to the course could also be rendered in the course language when the user has not provided a preference.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140516</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140516"/>
		<updated>2021-11-03T01:23:51Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added the first alternate approache documentation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2 Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language? To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''*Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2. Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
Rendering the language&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Instead, the better approach is to have a single unified view that dynamically changes based on the selected language:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=language==’en’ ? ‘Summary Report for assignment’ : ‘Rapport de synthèse pour l'affectation’&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=language==’en’ ? ‘Team’ : ‘Équipe’&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;However this is clearly infeasible considering the number of call sites where we have to apply this logic. Thus, in order to maximize how concise the call site is, we can pull out this logic into a common helper function:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%=localized(“report_summary.page_header”)&amp;gt;: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;&amp;lt;%=localized(“report_summary.team_label”)&amp;gt;: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;Here the assumption is that the localized(“key”) is aware of the currently selected language and that “report_summary.page_header” is the key for the header which is available in English and Hindi. The helper intelligently selects and returns the right text based on the currently selected language. Through this approach, we are able to render the view in multiple possible languages without any significant increase in the verbosity of the view.&lt;br /&gt;
&lt;br /&gt;
What’s more, is that the above problem is a common problem for user-facing applications and a standard library for doing the above and much more already exists for rails applications called i18n&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
&lt;br /&gt;
'''1. Why not simply swap out the entire view for another language instead of each text?'''&amp;lt;br&amp;gt;&lt;br /&gt;
A view is an organized collection of multiple separate elements, views often involve dynamic generation and some level of sophistication. If we were to swap out one page in its entirety for another page this would often violate the '''DRY''' principle since we would have to have two separate implementations of the view in each language. Thus in the worst case, you have a complex view that has to be replicated dozens of times in various languages.&lt;br /&gt;
The majority of complexity of the page is not in the content itself but rather the code that executes to generate that content, thus it makes sense to instead maintain a single view and embed the language switching logic at each location where translation needs to occur to avoid replication of everything around it.&lt;br /&gt;
&lt;br /&gt;
'''2. Why did we pick i18n over implementing it ourselves?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3, Do we store the language preference, in the session or in the database?'''&amp;lt;br&amp;gt;&lt;br /&gt;
@rsabu&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently made the assignment screen display in the course’s language, however other screens such as the “Your work” screen and so on are also specific to the course could also be rendered in the course language when the user has not provided a preference.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140513</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140513"/>
		<updated>2021-11-03T01:20:35Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added major design patterns &amp;amp; principles&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2 Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language? To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''*Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''2. Rendering the language'''&amp;lt;br&amp;gt;&lt;br /&gt;
Rendering the language&amp;lt;br&amp;gt;&lt;br /&gt;
Once we have determined the language in which to render the page, we now need to update the rails view code to actually generate the appropriate HTML in the target language. This is the responsibility of the view. However, currently, the actual content of the HTML is hardcoded in (red) English. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Summary Report for assignment: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Team: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed earlier, “Views are composed of independent language elements” and so we cannot simply swap out the entire page content for a separate page in another language (Why? - See “swap out the entire view” in the alternative approaches section):&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;h2&amp;gt;Rapport de synthèse pour l'affectation: &amp;lt;%= @assignment.name %&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Équipe: &amp;lt;%= @team.name %&amp;gt;&amp;lt;/h4&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
&lt;br /&gt;
'''1. DRY: The i18n ‘t’ function'''&amp;lt;br&amp;gt;&lt;br /&gt;
We observe an extreme case of DRY with the t function of i18n.&lt;br /&gt;
For some background, the t function of the library takes in a key representing a text and returns the content referred to by that key in the preferred language of the user. It also performs many other functions such as falling back to a backup language if the translation for the preferred language has not been configured for that specific key. Thus since this logic has to be applied at every element of the view, it would behove us to extract this logic into a reusable function which is what the designers of the i18n library have employed&lt;br /&gt;
&lt;br /&gt;
'''2. Chain of responsibility'''&amp;lt;br&amp;gt;&lt;br /&gt;
@ajulka&lt;br /&gt;
&lt;br /&gt;
'''3. Open closed principle &amp;amp; Strategy Pattern'''&amp;lt;br&amp;gt;&lt;br /&gt;
As discussed in the “Language selection&amp;quot; design proposal above, if the user has not selected a preferred language, we do not simply default the view to render in the application language (English). Instead, the project requirements state that for course specific screens such as the assignment view, we would need to render the view in the course’s language.&lt;br /&gt;
While we could implement this code into the application controller that checks the controller being access and accordingly applies overrides on the default language, this violates the open closed principle since we would need to extend this logic any time we introduce a new course specific screen. Instead a better approach is to delegate the decision of selecting the language to the view itself since the view would be most aware of whether the view is course specific or not. We can also preserve the DRYness through mix-ins.&lt;br /&gt;
&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently made the assignment screen display in the course’s language, however other screens such as the “Your work” screen and so on are also specific to the course could also be rendered in the course language when the user has not provided a preference.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140510</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140510"/>
		<updated>2021-11-03T01:18:09Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added future scope&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2 Rendering the language'''''&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language? To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''*Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
2. Rendering the language&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
'''1. Expand to more languages'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project we have targetted Hindi as a second language, however our work makes it easy to extend to other languages as well.&lt;br /&gt;
&lt;br /&gt;
'''2. Identify and implement the course language override on more course specific screens'''&amp;lt;br&amp;gt;&lt;br /&gt;
As part of this project, we have introduced a generic framework by which any view can provide a preferred language in which it should be rendered, this is required by this project for the course language feature set by the instructor.&lt;br /&gt;
We have currently made the assignment screen display in the course’s language, however other screens such as the “Your work” screen and so on are also specific to the course could also be rendered in the course language when the user has not provided a preference.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140507</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140507"/>
		<updated>2021-11-03T01:16:28Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added team&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''''2 Rendering the language'''''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''How do we go about rendering the screen in that language?''' &amp;lt;br&amp;gt;&lt;br /&gt;
In the previous step, we’ve identified the language in which a view is to be rendered. It is important to note that this language may not only differ for a different user, but also for a different page for the same user. The question now becomes, how do we render the screen in this language? To tackle this question, we explore 2 fundamental concepts:&amp;lt;br&amp;gt;&lt;br /&gt;
'''Views are composed of independent language elements'''&amp;lt;br&amp;gt;&lt;br /&gt;
While this is something we typically take for granted, it becomes especially important in the context of translation. That is, a view is not a single contiguous block of text, nor is it an atomic visualization of information (unlike a screenshot), but rather a carefully organized collection of individual elements such as texts, buttons, etc that each contain language that needs to be translated separately. Crucially, this means that we cannot swap out a page in one language in its entirety for a page in another language in its entirety. Instead, each individual element needs to be swapped out individually so as to only impact the language and not the structural composition of the page itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''*Views require translation at a large number of call sites'''&amp;lt;br&amp;gt;&lt;br /&gt;
Given that a view is composed of individual elements, this also means that the computation of how to translate such an element such as a button’s text would need to be done separately for each element. This would result in not only a single centralized &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
2. Rendering the language&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
'''Team Members'''&lt;br /&gt;
&lt;br /&gt;
Reuben M. V. John [[mailto:rmjohn2@ncsu.edu rmjohn2@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Renji Joseph Sabu [[mailto:rsabu@ncsu.edu rsabu@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Ashwin Das [[mailto:adas9@ncsu.edu adas9@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
Arnav Julka [[mailto:ajulka@ncsu.edu ajulka@ncsu.edu]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
&lt;br /&gt;
Jialin Cui [[mailto:jcui9@ncsu.edu jcui9@ncsu.edu]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140504</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140504"/>
		<updated>2021-11-03T01:07:47Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Updated section headers&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
2. Rendering the language&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
== Design ==&lt;br /&gt;
Proposed Solution&lt;br /&gt;
1. Language selection&lt;br /&gt;
2. Rendering the language&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
== Alternate approaches ==&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
== Major design patterns and principles used ==&lt;br /&gt;
== Database Design ==&lt;br /&gt;
Database Modification ==&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
Test Details&lt;br /&gt;
Manual Testing&lt;br /&gt;
Scenario 1&lt;br /&gt;
Scenario 2&lt;br /&gt;
Scenario 3&lt;br /&gt;
Scenario 4&lt;br /&gt;
Scenario 5&lt;br /&gt;
== Future Scope==&lt;br /&gt;
== Team ==&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140499</id>
		<title>CSC/ECE 517 Fall 2021 - E2159. Expertiza internationalization</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2159._Expertiza_internationalization&amp;diff=140499"/>
		<updated>2021-11-03T01:03:03Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Added section headers&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction - Purpose &amp;amp; Problem ==&lt;br /&gt;
1. Language selection&lt;br /&gt;
2. Rendering the language&lt;br /&gt;
3. Translation gaps&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
Design	5&lt;br /&gt;
Proposed Solution	5&lt;br /&gt;
Language selection	5&lt;br /&gt;
Rendering the language	6&lt;br /&gt;
I18n - Internationalisation, How are we using I18n in Ruby on Rails	7&lt;br /&gt;
Translation gaps	8&lt;br /&gt;
Alternate approaches	8&lt;br /&gt;
Use Case Diagram	9&lt;br /&gt;
Major design patterns and principles used	9&lt;br /&gt;
Database Design	10&lt;br /&gt;
Database Modification	10&lt;br /&gt;
Test Plan	12&lt;br /&gt;
Test Details	12&lt;br /&gt;
Manual Testing	12&lt;br /&gt;
Scenario 1	12&lt;br /&gt;
Scenario 2	13&lt;br /&gt;
Scenario 3	13&lt;br /&gt;
Scenario 4	13&lt;br /&gt;
Scenario 5	13&lt;br /&gt;
UI Testing	14&lt;br /&gt;
Automated testing using Rspec	14&lt;br /&gt;
Future Scope	14&lt;br /&gt;
Team&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=140240</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=140240"/>
		<updated>2021-10-27T04:13:05Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Issue2 (345) - clarification of why the problem statement was changed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142. Improve e-mail notifications=&lt;br /&gt;
&lt;br /&gt;
==Brief Introduction==&lt;br /&gt;
The project consists of '''3 separate issues all related to the sending of emails from expertiza'''.&lt;br /&gt;
&lt;br /&gt;
The forked repository can be found at: https://github.com/griffinbrookshire/expertiza&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
*Issue1: Send new account welcome email to user, when imported from CSV through assignment page.&lt;br /&gt;
*Issue2: Don't send email to reviewers for a new submission after review deadline has passed.&lt;br /&gt;
*Issue3: Adding relevant links to reminder emails.&lt;br /&gt;
&lt;br /&gt;
==Issue1 (717) - Send new account welcome email to user, when imported from CSV through assignment page==&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There exists an assignment and an instructor&lt;br /&gt;
* The instructor navigates to the 'Manage Assignments' page&lt;br /&gt;
* The instructor clicks 'Add Participants' for the existing assignment&lt;br /&gt;
* The instructor clicks 'Import assignment participants'&lt;br /&gt;
* The instructor imports a CSV file containing a user who does not exist yet&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/717 - &lt;br /&gt;
&amp;quot;When students' accounts are created by importing a CSV on the Users page, they receive e-mails with their user-ID and password. But if an account is created by adding them as participants to an assignment when they don't already have an account, e-mail is not sent. Students should receive e-mails upon account creation, regardless of how their account is created.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So, when students accounts are created in any way, they should receive a welcome email. This includes adding them through importing a CSV.&lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
The implementation and testing for this issue already existed in the beta branch, which will be discussed below.&amp;lt;br&amp;gt;&lt;br /&gt;
This behavior was already implemented through one simple line in the app/models/user.rb file.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''user.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
after_create :email_welcome&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This line calls the 'email_welcome' function every time a user is created, which sends a welcome email to the newly created user.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''user.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Function which has a MailerHelper which sends the mail welcome email to the user after signing up&lt;br /&gt;
def email_welcome&lt;br /&gt;
  #this will send an account creation notification to user via email.&lt;br /&gt;
  MailerHelper.send_mail_to_user(self, &amp;quot;Your Expertiza account and password has been created&amp;quot;, &amp;quot;user_welcome&amp;quot;, password).deliver_now&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This functionality was also completely tested in the spec/models/assignment_participant_spec.rb file show below. This test shows that when the import function is called an email is delivered.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''assignment_participant_spec.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
context 'when new user needs to be created' do&lt;br /&gt;
  let(:row) do&lt;br /&gt;
    {name: 'no one', fullname: 'no one', email: 'name@email.com', role:'user_role_name', parent: 'user_parent_name'}&lt;br /&gt;
  end&lt;br /&gt;
  let(:attributes) do&lt;br /&gt;
    {role_id: 1, name: 'no one', fullname: 'no one', email: 'name@email.com', email_on_submission: 'name@email.com',&lt;br /&gt;
      email_on_review: 'name@email.com', email_on_review_of_review: 'name@email.com'}&lt;br /&gt;
  end&lt;br /&gt;
  let(:test_user) do&lt;br /&gt;
    {name: 'abc', email: 'abcbbc@gmail.com'}&lt;br /&gt;
  end&lt;br /&gt;
  it 'create the user and number of mails sent should be 1' do&lt;br /&gt;
    ActionMailer::Base.deliveries.clear&lt;br /&gt;
    allow(ImportFileHelper).to receive(:define_attributes).with(row).and_return(attributes)&lt;br /&gt;
    allow(ImportFileHelper).to receive(:create_new_user) do&lt;br /&gt;
      test_user = User.new(name: 'abc', fullname: 'abc bbc', email: 'abcbbc@gmail.com')&lt;br /&gt;
      test_user.id = 123&lt;br /&gt;
      test_user.save!&lt;br /&gt;
      test_user&lt;br /&gt;
    end&lt;br /&gt;
    #allow(ImportFileHelper).to receive(:create_new_user).with(attributes, {}).and_return()&lt;br /&gt;
    allow(Assignment).to receive(:find).with(1).and_return(assignment)&lt;br /&gt;
    allow(User).to receive(:exists?).with(name: 'no one').and_return(false)&lt;br /&gt;
    allow(participant).to receive(:set_handle).and_return('handle')&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:exists?).and_return(false)&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:create).and_return(participant)&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:set_handle)&lt;br /&gt;
    expect{(AssignmentParticipant.import(row, nil, {}, 1))}.to change { ActionMailer::Base.deliveries.count }.by(1)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Manual Testing Results'''&lt;br /&gt;
&lt;br /&gt;
After following the step-by-step instructions for Issue1 in the Test Plan below, the following email was received. This shows that when a new user was imported through the assignment participants page, they received a welcome email.&lt;br /&gt;
&lt;br /&gt;
[[File:Welcome email.png|750px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issue2 (345) - Don't send email to reviewers for a new submission after review deadline has passed==&lt;br /&gt;
&lt;br /&gt;
'''NOTE: This problem statement was modified upon discussion with the mentor to reflect the current state of the codebase:'''&lt;br /&gt;
* '''Original problem statement''': Emails were being sent when uploading an submission, but they should not be sent after the review deadline.&lt;br /&gt;
* '''Updated problem statement''': Emails are not being sent at all when uploading an assignment submission. Also, sending emails after the review deadline would no longer be an issue since students are not allowed to submit assignments after the review deadline (as explained in detail below).&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There is an assignment, a student as a participant, a participant as a reviewer who is reviewing the this particular assignment&lt;br /&gt;
* a review is made for a submission by the student&lt;br /&gt;
* review deadline has passed&lt;br /&gt;
* the student is allowed to submit after the review deadline has passed&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/345 - &lt;br /&gt;
&amp;quot;Evidently, if a submission is revised after review, the system e-mails the reviewer saying to revise the review. This is just fine ... except if the last round of review has been completed.&lt;br /&gt;
The message telling reviewers to revise their reviews should not be sent after the last review deadline has passed.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So basically, When the student makes a new submission after the LAST review deadline has passed. The reviewer should not receive an email, asking the reviewer to update the review according to the new submission.&lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
According to the current Code scenario on the beta branch '''''if the deadline has passed, a student(participant) cannot make new submissions'''''. So, automatically if the participant doe not make a new submission then the reviewer wont receive an email. So this issue does not really exist by the virtue of the state of the system.&lt;br /&gt;
the stack trace for the check if the submission is allowed or not is as follows - &lt;br /&gt;
assignment.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def submission_allowed(topic_id = nil)&lt;br /&gt;
    check_condition('submission_allowed_id', topic_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
assignment.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def check_condition(column, topic_id = nil)&lt;br /&gt;
    next_due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    return false if next_due_date.nil?&lt;br /&gt;
    right_id = next_due_date.send column&lt;br /&gt;
    right = DeadlineRight.find(right_id)&lt;br /&gt;
    right &amp;amp;&amp;amp; (right.name == 'OK' || right.name == 'Late')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
due_date.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
    if Assignment.find(assignment_id).staggered_deadline?&lt;br /&gt;
      next_due_date = TopicDueDate.find_by(['parent_id = ? and due_at &amp;gt;= ?', topic_id, Time.zone.now])&lt;br /&gt;
      # if certion TopicDueDate is not exist, we should query next corresponding AssignmentDueDate.&lt;br /&gt;
      # eg. Time.now is 08/28/2016&lt;br /&gt;
      # One topic uses following deadlines:&lt;br /&gt;
      # TopicDueDate      08/01/2016&lt;br /&gt;
      # TopicDueDate      08/02/2016&lt;br /&gt;
      # TopicDueDate      08/03/2016&lt;br /&gt;
      # AssignmentDueDate 09/04/2016&lt;br /&gt;
      # In this case, we cannot find due_at later than Time.now in TopicDueDate.&lt;br /&gt;
      # So we should find next corrsponding AssignmentDueDate, starting with the 4th one, not the 1st one!&lt;br /&gt;
      if next_due_date.nil?&lt;br /&gt;
        topic_due_date_size = TopicDueDate.where(parent_id: topic_id).size&lt;br /&gt;
        following_assignment_due_dates = AssignmentDueDate.where(parent_id: assignment_id)[topic_due_date_size..-1]&lt;br /&gt;
        unless following_assignment_due_dates.nil?&lt;br /&gt;
          following_assignment_due_dates.each do |assignment_due_date|&lt;br /&gt;
            if assignment_due_date.due_at &amp;gt;= Time.zone.now&lt;br /&gt;
              next_due_date = assignment_due_date&lt;br /&gt;
              break&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = AssignmentDueDate.find_by(['parent_id = ? &amp;amp;&amp;amp; due_at &amp;gt;= ?', assignment_id, Time.zone.now])&lt;br /&gt;
    end&lt;br /&gt;
    next_due_date&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So this is issue is resolved by the state of the system itself.&amp;lt;br&amp;gt;&lt;br /&gt;
'''''BUT Surprisingly on beta branch Reviewers aren't getting any emails at all'''''&lt;br /&gt;
on beta branch, in submitted_content_controller, in function &amp;quot;submit_file&amp;quot;, this lines is supposed to send email to the reviewers to notify them about the new submission&lt;br /&gt;
&amp;lt;pre&amp;gt; participant.assignment.email(participant.id) rescue nil &amp;lt;/pre&amp;gt;&lt;br /&gt;
''BUT'' here email function is undefined. we checked for email function in assignment class, there was none. The error &amp;quot;undefined function on assignment&amp;quot; is always rescued and hence no errors were raised previously and hence it wasn't highlighted before. &amp;lt;br&amp;gt;&lt;br /&gt;
So, in beta branch reviewers are not being notified anytime a new submission is made to an assignment that they have previously reviewed. So we fixed that&lt;br /&gt;
Taking inspiration from the Master branch the previous team's work we added following code to send an email notifying the reviewer of an new submission.&lt;br /&gt;
&lt;br /&gt;
in submitted_content_controller.rb, in the functions, submit_file, submit_hyperlink&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Team.mail_assigned_reviewers(@participant)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
participant.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def mail_assigned_reviewers()&lt;br /&gt;
    team = self.team&lt;br /&gt;
    maps = ResponseMap.where(reviewed_object_id: self.assignment.id, reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
    unless maps.nil?&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        reviewer = User.find(Participant.find(map.reviewer_id).user_id)&lt;br /&gt;
        Mailer.sync_message(&lt;br /&gt;
            {&lt;br /&gt;
                :to =&amp;gt; reviewer.email,&lt;br /&gt;
                subject:  &amp;quot;Assignment '#{self.assignment.name}': A submission has been updated since you last reviewed it&amp;quot;,&lt;br /&gt;
                cc: User.find_by(self.assignment.instructor_id).email,&lt;br /&gt;
                :body =&amp;gt; {&lt;br /&gt;
                    :obj_name =&amp;gt; self.assignment.name,&lt;br /&gt;
                    :link =&amp;gt; &amp;quot;https://expertiza.ncsu.edu/response/new?id=#{map.id}&amp;quot;,&lt;br /&gt;
                    :type =&amp;gt; 'submission',&lt;br /&gt;
                    :first_name =&amp;gt; ApplicationHelper::get_user_first_name(User.find(Participant.find(map.reviewer_id).user_id)),&lt;br /&gt;
                    :partial_name =&amp;gt; 'updated_submission_since_review'&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        ).deliver_now&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
app/views/mailer/partials/_updated_submission_since_review_plain.html.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi &amp;lt;%= @first_name %&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;%=@type%&amp;gt; you were reviewing for Assignment '&amp;lt;%= @obj_name %&amp;gt;' has been updated since you last review.&lt;br /&gt;
Hence, to update your review please click on the following link.&lt;br /&gt;
&amp;lt;% if @link != nil %&amp;gt;&amp;lt;%= @link %&amp;gt;&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
app/views/mailer/partials/_updated_submission_since_review_html.html.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi &amp;lt;%= @first_name %&amp;gt;,&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
  A &amp;lt;%=@type%&amp;gt; you were reviewing for Assignment '&amp;lt;%= @obj_name %&amp;gt;' has been updated since you last review.&amp;lt;br&amp;gt;&lt;br /&gt;
  Hence, to update your review please click on the following link.&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;% if @link != nil %&amp;gt;&amp;lt;a href=&amp;quot;&amp;lt;%= @link %&amp;gt;&amp;quot;&amp;gt;&amp;lt;%= @link %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
added a line in app/mailers/mailer.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @link = defn[:body][:link]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Issue3 (111) - Adding relevant links to reminder emails==&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There exists an assignment and a participant associated with that assignment &lt;br /&gt;
* The due date for the assignment is approaching&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/111 - &lt;br /&gt;
&amp;quot;E-mails about reviews should direct the user to the page where the review is found. Deadline reminders should include a link on where to go to perform the needed function.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So, when assignment reminder emails are sent to students, they should include a link to the relevant assignment. &lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
We implemented this behavior by enhancing the 'email_reminder' function within the app/mailers/mail_worker.rb file. First we get the user associated with the email, then we get the participant object associated with the particular user and the assignment. The ID of this object is the query parameter located at the end of the relevant link.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''mail_worker.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def email_reminder(emails, deadline_type)&lt;br /&gt;
  assignment = Assignment.find(self.assignment_id)&lt;br /&gt;
  subject = &amp;quot;Message regarding #{deadline_type} for assignment #{assignment.name}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Defining the body of mail&lt;br /&gt;
  body = &amp;quot;This is a reminder to complete #{deadline_type} for assignment #{assignment.name}.\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  emails.each do |mail|&lt;br /&gt;
    # Since the email is not unique fetching the first instance in results returned when searching via email&lt;br /&gt;
    user = User.where(email: mail).first&lt;br /&gt;
&lt;br /&gt;
    # Finding the mapping between participant and assignment so that it can be sent as a query param&lt;br /&gt;
    participant_assignment_id = Participant.find(user_id: user.id.to_s, parent_id: self.assignment_id.to_s).first.id&lt;br /&gt;
&lt;br /&gt;
    # This is the link which User can use to navigate&lt;br /&gt;
    link_to_destination = &amp;quot;Please follow the link: http://expertiza.ncsu.edu/student_task/view?id=#{participant_assignment_id}\n&amp;quot;&lt;br /&gt;
    body += link_to_destination + &amp;quot;Deadline is #{self.due_at}. If you have already done the #{deadline_type}, then please ignore this mail.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    # Send mail to the user&lt;br /&gt;
    @mail = Mailer.delayed_message(bcc: mail, subject: subject, body: body)&lt;br /&gt;
    @mail.deliver_now&lt;br /&gt;
    Rails.logger.info mail&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function is clearly tested through a new test we added to the spec/workers/sidekiq_mail_worker_spec.rb&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''sidekiq_mail_worker_spec.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should send reminder email to required email address with proper content&amp;quot; do&lt;br /&gt;
  Sidekiq::Testing.inline!&lt;br /&gt;
  ActionMailer::Base.deliveries.clear&lt;br /&gt;
  worker = MailWorker.new&lt;br /&gt;
  worker.perform(&amp;quot;1&amp;quot;, &amp;quot;metareview&amp;quot;, &amp;quot;2018-12-31 00:00:01&amp;quot;)&lt;br /&gt;
  expect(ActionMailer::Base.deliveries.size).to eq(1)&lt;br /&gt;
  email = ActionMailer::Base.deliveries.first&lt;br /&gt;
  expect(email.from[0]).to eq(&amp;quot;expertiza.development@gmail.com&amp;quot;)&lt;br /&gt;
  expect(email.bcc[0]).to eq(&amp;quot;psingh22@ncsu.edu&amp;quot;)&lt;br /&gt;
  expect(email.subject).to eq(&amp;quot;Message regarding teammate review for assignment no assignment&amp;quot;)&lt;br /&gt;
  expect(email.body).to eq(&amp;quot;This is a reminder to complete teammate review for assignment no assignment.\nPlease follow the link: http://expertiza.ncsu.edu/student_task/view?id=1\nDeadline is 2018-12-31 00:00:01. If you have already done the teammate review, then please ignore this mail.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
'''Issue 1'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Navigate to Manage --&amp;gt; Assignment page.&lt;br /&gt;
&lt;br /&gt;
Step 2: Click on add participants for any of the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Click &amp;quot;Import course participants&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Step 4: Choose a csv file to be imported (follow the format given on the website).&lt;br /&gt;
&lt;br /&gt;
Step 5: The users mentioned in the csv file and don't exist on Expertiza should get a new user email.&lt;br /&gt;
&lt;br /&gt;
'''Issue 2'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Create new assignment [Manage --&amp;gt; Assignment --&amp;gt; + Button (to create new assignment)]&lt;br /&gt;
&lt;br /&gt;
Step 2: Fill the details for the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Navigate to due dates.&lt;br /&gt;
&lt;br /&gt;
Step 4: Change the number of review rounds to 2.&lt;br /&gt;
&lt;br /&gt;
Step 5: Select &amp;quot;Yes&amp;quot; in the dropdown for review allowed during submission and select &amp;quot;Yes&amp;quot; for submission during the review.&lt;br /&gt;
&lt;br /&gt;
Step 6: Add two users to the assignment(author and reviewer).&lt;br /&gt;
&lt;br /&gt;
Step 7: Log in with some user credentials (author credential).&lt;br /&gt;
&lt;br /&gt;
Step 8: Make a new submission to this assignment.&lt;br /&gt;
&lt;br /&gt;
Step 9: Log in with another user (reviewer).&lt;br /&gt;
&lt;br /&gt;
Step 10: Submit a review of the assignment submission.&lt;br /&gt;
&lt;br /&gt;
Step 11: Login as an author again. &lt;br /&gt;
&lt;br /&gt;
Step 12: Edit the submission.&lt;br /&gt;
&lt;br /&gt;
Step 13: After this check the mailbox of the reviewer [development mail for development].&lt;br /&gt;
&lt;br /&gt;
Step 14: Reviewer should get the mail to re-review the work.&lt;br /&gt;
&lt;br /&gt;
Step 15: Change the due date to some date and time which has passed.&lt;br /&gt;
&lt;br /&gt;
Step 16: Now the author should not be able to make a new submission.&lt;br /&gt;
&lt;br /&gt;
'''Issue 3'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Create new assignment [Manage --&amp;gt; Assignment --&amp;gt; + Button (to create new assignment)]&lt;br /&gt;
&lt;br /&gt;
Step 2: Fill the details for the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Add an existing user to the new assignment&lt;br /&gt;
&lt;br /&gt;
Step 3: Navigate to due dates for the new assignment.&lt;br /&gt;
&lt;br /&gt;
Step 4: Set the due date to 1 hour and 5 seconds from now.&lt;br /&gt;
&lt;br /&gt;
Step 5: The user should recieve a reminder email with the relevant links to the assignment.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=140237</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=140237"/>
		<updated>2021-10-27T04:00:49Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Project intro&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142. Improve e-mail notifications=&lt;br /&gt;
&lt;br /&gt;
==Brief Introduction==&lt;br /&gt;
The project consists of '''3 separate issues all related to the sending of emails from expertiza'''.&lt;br /&gt;
&lt;br /&gt;
The forked repository can be found at: https://github.com/griffinbrookshire/expertiza&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
*Issue1: Send new account welcome email to user, when imported from CSV through assignment page.&lt;br /&gt;
*Issue2: Don't send email to reviewers for a new submission after review deadline has passed.&lt;br /&gt;
*Issue3: Adding relevant links to reminder emails.&lt;br /&gt;
&lt;br /&gt;
==Issue1 (717) - Send new account welcome email to user, when imported from CSV through assignment page==&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There exists an assignment and an instructor&lt;br /&gt;
* The instructor navigates to the 'Manage Assignments' page&lt;br /&gt;
* The instructor clicks 'Add Participants' for the existing assignment&lt;br /&gt;
* The instructor clicks 'Import assignment participants'&lt;br /&gt;
* The instructor imports a CSV file containing a user who does not exist yet&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/717 - &lt;br /&gt;
&amp;quot;When students' accounts are created by importing a CSV on the Users page, they receive e-mails with their user-ID and password. But if an account is created by adding them as participants to an assignment when they don't already have an account, e-mail is not sent. Students should receive e-mails upon account creation, regardless of how their account is created.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So, when students accounts are created in any way, they should receive a welcome email. This includes adding them through importing a CSV.&lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
The implementation and testing for this issue already existed in the beta branch, which will be discussed below.&amp;lt;br&amp;gt;&lt;br /&gt;
This behavior was already implemented through one simple line in the app/models/user.rb file.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''user.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
after_create :email_welcome&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This line calls the 'email_welcome' function every time a user is created, which sends a welcome email to the newly created user.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''user.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Function which has a MailerHelper which sends the mail welcome email to the user after signing up&lt;br /&gt;
def email_welcome&lt;br /&gt;
  #this will send an account creation notification to user via email.&lt;br /&gt;
  MailerHelper.send_mail_to_user(self, &amp;quot;Your Expertiza account and password has been created&amp;quot;, &amp;quot;user_welcome&amp;quot;, password).deliver_now&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This functionality was also completely tested in the spec/models/assignment_participant_spec.rb file show below. This test shows that when the import function is called an email is delivered.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''assignment_participant_spec.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
context 'when new user needs to be created' do&lt;br /&gt;
  let(:row) do&lt;br /&gt;
    {name: 'no one', fullname: 'no one', email: 'name@email.com', role:'user_role_name', parent: 'user_parent_name'}&lt;br /&gt;
  end&lt;br /&gt;
  let(:attributes) do&lt;br /&gt;
    {role_id: 1, name: 'no one', fullname: 'no one', email: 'name@email.com', email_on_submission: 'name@email.com',&lt;br /&gt;
      email_on_review: 'name@email.com', email_on_review_of_review: 'name@email.com'}&lt;br /&gt;
  end&lt;br /&gt;
  let(:test_user) do&lt;br /&gt;
    {name: 'abc', email: 'abcbbc@gmail.com'}&lt;br /&gt;
  end&lt;br /&gt;
  it 'create the user and number of mails sent should be 1' do&lt;br /&gt;
    ActionMailer::Base.deliveries.clear&lt;br /&gt;
    allow(ImportFileHelper).to receive(:define_attributes).with(row).and_return(attributes)&lt;br /&gt;
    allow(ImportFileHelper).to receive(:create_new_user) do&lt;br /&gt;
      test_user = User.new(name: 'abc', fullname: 'abc bbc', email: 'abcbbc@gmail.com')&lt;br /&gt;
      test_user.id = 123&lt;br /&gt;
      test_user.save!&lt;br /&gt;
      test_user&lt;br /&gt;
    end&lt;br /&gt;
    #allow(ImportFileHelper).to receive(:create_new_user).with(attributes, {}).and_return()&lt;br /&gt;
    allow(Assignment).to receive(:find).with(1).and_return(assignment)&lt;br /&gt;
    allow(User).to receive(:exists?).with(name: 'no one').and_return(false)&lt;br /&gt;
    allow(participant).to receive(:set_handle).and_return('handle')&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:exists?).and_return(false)&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:create).and_return(participant)&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:set_handle)&lt;br /&gt;
    expect{(AssignmentParticipant.import(row, nil, {}, 1))}.to change { ActionMailer::Base.deliveries.count }.by(1)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Manual Testing Results'''&lt;br /&gt;
&lt;br /&gt;
After following the step-by-step instructions for Issue1 in the Test Plan below, the following email was received. This shows that when a new user was imported through the assignment participants page, they received a welcome email.&lt;br /&gt;
&lt;br /&gt;
[[File:Welcome email.png|750px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issue2 (345) - Don't send email to reviewers for a new submission after review deadline has passed==&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There is an assignment, a student as a participant, a participant as a reviewer who is reviewing the this particular assignment&lt;br /&gt;
* a review is made for a submission by the student&lt;br /&gt;
* review deadline has passed&lt;br /&gt;
* the student is allowed to submit after the review deadline has passed&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/345 - &lt;br /&gt;
&amp;quot;Evidently, if a submission is revised after review, the system e-mails the reviewer saying to revise the review. This is just fine ... except if the last round of review has been completed.&lt;br /&gt;
The message telling reviewers to revise their reviews should not be sent after the last review deadline has passed.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So basically, When the student makes a new submission after the LAST review deadline has passed. The reviewer should not receive an email, asking the reviewer to update the review according to the new submission.&lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
According to the current Code scenario on the beta branch '''''if the deadline has passed, a student(participant) cannot make new submissions'''''. So, automatically if the participant doe not make a new submission then the reviewer wont receive an email. So this issue does not really exist by the virtue of the state of the system.&lt;br /&gt;
the stack trace for the check if the submission is allowed or not is as follows - &lt;br /&gt;
assignment.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def submission_allowed(topic_id = nil)&lt;br /&gt;
    check_condition('submission_allowed_id', topic_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
assignment.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def check_condition(column, topic_id = nil)&lt;br /&gt;
    next_due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    return false if next_due_date.nil?&lt;br /&gt;
    right_id = next_due_date.send column&lt;br /&gt;
    right = DeadlineRight.find(right_id)&lt;br /&gt;
    right &amp;amp;&amp;amp; (right.name == 'OK' || right.name == 'Late')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
due_date.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
    if Assignment.find(assignment_id).staggered_deadline?&lt;br /&gt;
      next_due_date = TopicDueDate.find_by(['parent_id = ? and due_at &amp;gt;= ?', topic_id, Time.zone.now])&lt;br /&gt;
      # if certion TopicDueDate is not exist, we should query next corresponding AssignmentDueDate.&lt;br /&gt;
      # eg. Time.now is 08/28/2016&lt;br /&gt;
      # One topic uses following deadlines:&lt;br /&gt;
      # TopicDueDate      08/01/2016&lt;br /&gt;
      # TopicDueDate      08/02/2016&lt;br /&gt;
      # TopicDueDate      08/03/2016&lt;br /&gt;
      # AssignmentDueDate 09/04/2016&lt;br /&gt;
      # In this case, we cannot find due_at later than Time.now in TopicDueDate.&lt;br /&gt;
      # So we should find next corrsponding AssignmentDueDate, starting with the 4th one, not the 1st one!&lt;br /&gt;
      if next_due_date.nil?&lt;br /&gt;
        topic_due_date_size = TopicDueDate.where(parent_id: topic_id).size&lt;br /&gt;
        following_assignment_due_dates = AssignmentDueDate.where(parent_id: assignment_id)[topic_due_date_size..-1]&lt;br /&gt;
        unless following_assignment_due_dates.nil?&lt;br /&gt;
          following_assignment_due_dates.each do |assignment_due_date|&lt;br /&gt;
            if assignment_due_date.due_at &amp;gt;= Time.zone.now&lt;br /&gt;
              next_due_date = assignment_due_date&lt;br /&gt;
              break&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = AssignmentDueDate.find_by(['parent_id = ? &amp;amp;&amp;amp; due_at &amp;gt;= ?', assignment_id, Time.zone.now])&lt;br /&gt;
    end&lt;br /&gt;
    next_due_date&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So this is issue is resolved by the state of the system itself.&amp;lt;br&amp;gt;&lt;br /&gt;
'''''BUT Surprisingly on beta branch Reviewers aren't getting any emails at all'''''&lt;br /&gt;
on beta branch, in submitted_content_controller, in function &amp;quot;submit_file&amp;quot;, this lines is supposed to send email to the reviewers to notify them about the new submission&lt;br /&gt;
&amp;lt;pre&amp;gt; participant.assignment.email(participant.id) rescue nil &amp;lt;/pre&amp;gt;&lt;br /&gt;
''BUT'' here email function is undefined. we checked for email function in assignment class, there was none. The error &amp;quot;undefined function on assignment&amp;quot; is always rescued and hence no errors were raised previously and hence it wasn't highlighted before. &amp;lt;br&amp;gt;&lt;br /&gt;
So, in beta branch reviewers are not being notified anytime a new submission is made to an assignment that they have previously reviewed. So we fixed that&lt;br /&gt;
Taking inspiration from the Master branch the previous team's work we added following code to send an email notifying the reviewer of an new submission.&lt;br /&gt;
&lt;br /&gt;
in submitted_content_controller.rb, in the functions, submit_file, submit_hyperlink&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Team.mail_assigned_reviewers(@participant)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
participant.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def mail_assigned_reviewers()&lt;br /&gt;
    team = self.team&lt;br /&gt;
    maps = ResponseMap.where(reviewed_object_id: self.assignment.id, reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
    unless maps.nil?&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        reviewer = User.find(Participant.find(map.reviewer_id).user_id)&lt;br /&gt;
        Mailer.sync_message(&lt;br /&gt;
            {&lt;br /&gt;
                :to =&amp;gt; reviewer.email,&lt;br /&gt;
                subject:  &amp;quot;Assignment '#{self.assignment.name}': A submission has been updated since you last reviewed it&amp;quot;,&lt;br /&gt;
                cc: User.find_by(self.assignment.instructor_id).email,&lt;br /&gt;
                :body =&amp;gt; {&lt;br /&gt;
                    :obj_name =&amp;gt; self.assignment.name,&lt;br /&gt;
                    :link =&amp;gt; &amp;quot;https://expertiza.ncsu.edu/response/new?id=#{map.id}&amp;quot;,&lt;br /&gt;
                    :type =&amp;gt; 'submission',&lt;br /&gt;
                    :first_name =&amp;gt; ApplicationHelper::get_user_first_name(User.find(Participant.find(map.reviewer_id).user_id)),&lt;br /&gt;
                    :partial_name =&amp;gt; 'updated_submission_since_review'&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        ).deliver_now&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
app/views/mailer/partials/_updated_submission_since_review_plain.html.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi &amp;lt;%= @first_name %&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;%=@type%&amp;gt; you were reviewing for Assignment '&amp;lt;%= @obj_name %&amp;gt;' has been updated since you last review.&lt;br /&gt;
Hence, to update your review please click on the following link.&lt;br /&gt;
&amp;lt;% if @link != nil %&amp;gt;&amp;lt;%= @link %&amp;gt;&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
app/views/mailer/partials/_updated_submission_since_review_html.html.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi &amp;lt;%= @first_name %&amp;gt;,&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
  A &amp;lt;%=@type%&amp;gt; you were reviewing for Assignment '&amp;lt;%= @obj_name %&amp;gt;' has been updated since you last review.&amp;lt;br&amp;gt;&lt;br /&gt;
  Hence, to update your review please click on the following link.&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;% if @link != nil %&amp;gt;&amp;lt;a href=&amp;quot;&amp;lt;%= @link %&amp;gt;&amp;quot;&amp;gt;&amp;lt;%= @link %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
added a line in app/mailers/mailer.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @link = defn[:body][:link]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Issue3 (111) - Adding relevant links to reminder emails==&lt;br /&gt;
&lt;br /&gt;
'''Pre conditions'''&lt;br /&gt;
* There exists an assignment and a participant associated with that assignment &lt;br /&gt;
* The due date for the assignment is approaching&lt;br /&gt;
&lt;br /&gt;
'''Expected Behavior'''&lt;br /&gt;
&lt;br /&gt;
Exact issue stating the expected behavior can be found at https://github.com/expertiza/expertiza/issues/111 - &lt;br /&gt;
&amp;quot;E-mails about reviews should direct the user to the page where the review is found. Deadline reminders should include a link on where to go to perform the needed function.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So, when assignment reminder emails are sent to students, they should include a link to the relevant assignment. &lt;br /&gt;
&lt;br /&gt;
'''Actual Behavior'''&lt;br /&gt;
&lt;br /&gt;
We implemented this behavior by enhancing the 'email_reminder' function within the app/mailers/mail_worker.rb file. First we get the user associated with the email, then we get the participant object associated with the particular user and the assignment. The ID of this object is the query parameter located at the end of the relevant link.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''mail_worker.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def email_reminder(emails, deadline_type)&lt;br /&gt;
  assignment = Assignment.find(self.assignment_id)&lt;br /&gt;
  subject = &amp;quot;Message regarding #{deadline_type} for assignment #{assignment.name}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Defining the body of mail&lt;br /&gt;
  body = &amp;quot;This is a reminder to complete #{deadline_type} for assignment #{assignment.name}.\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  emails.each do |mail|&lt;br /&gt;
    # Since the email is not unique fetching the first instance in results returned when searching via email&lt;br /&gt;
    user = User.where(email: mail).first&lt;br /&gt;
&lt;br /&gt;
    # Finding the mapping between participant and assignment so that it can be sent as a query param&lt;br /&gt;
    participant_assignment_id = Participant.find(user_id: user.id.to_s, parent_id: self.assignment_id.to_s).first.id&lt;br /&gt;
&lt;br /&gt;
    # This is the link which User can use to navigate&lt;br /&gt;
    link_to_destination = &amp;quot;Please follow the link: http://expertiza.ncsu.edu/student_task/view?id=#{participant_assignment_id}\n&amp;quot;&lt;br /&gt;
    body += link_to_destination + &amp;quot;Deadline is #{self.due_at}. If you have already done the #{deadline_type}, then please ignore this mail.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    # Send mail to the user&lt;br /&gt;
    @mail = Mailer.delayed_message(bcc: mail, subject: subject, body: body)&lt;br /&gt;
    @mail.deliver_now&lt;br /&gt;
    Rails.logger.info mail&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This function is clearly tested through a new test we added to the spec/workers/sidekiq_mail_worker_spec.rb&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;'''sidekiq_mail_worker_spec.rb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should send reminder email to required email address with proper content&amp;quot; do&lt;br /&gt;
  Sidekiq::Testing.inline!&lt;br /&gt;
  ActionMailer::Base.deliveries.clear&lt;br /&gt;
  worker = MailWorker.new&lt;br /&gt;
  worker.perform(&amp;quot;1&amp;quot;, &amp;quot;metareview&amp;quot;, &amp;quot;2018-12-31 00:00:01&amp;quot;)&lt;br /&gt;
  expect(ActionMailer::Base.deliveries.size).to eq(1)&lt;br /&gt;
  email = ActionMailer::Base.deliveries.first&lt;br /&gt;
  expect(email.from[0]).to eq(&amp;quot;expertiza.development@gmail.com&amp;quot;)&lt;br /&gt;
  expect(email.bcc[0]).to eq(&amp;quot;psingh22@ncsu.edu&amp;quot;)&lt;br /&gt;
  expect(email.subject).to eq(&amp;quot;Message regarding teammate review for assignment no assignment&amp;quot;)&lt;br /&gt;
  expect(email.body).to eq(&amp;quot;This is a reminder to complete teammate review for assignment no assignment.\nPlease follow the link: http://expertiza.ncsu.edu/student_task/view?id=1\nDeadline is 2018-12-31 00:00:01. If you have already done the teammate review, then please ignore this mail.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
'''Issue 1'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Navigate to Manage --&amp;gt; Assignment page.&lt;br /&gt;
&lt;br /&gt;
Step 2: Click on add participants for any of the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Click &amp;quot;Import course participants&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Step 4: Choose a csv file to be imported (follow the format given on the website).&lt;br /&gt;
&lt;br /&gt;
Step 5: The users mentioned in the csv file and don't exist on Expertiza should get a new user email.&lt;br /&gt;
&lt;br /&gt;
'''Issue 2'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Create new assignment [Manage --&amp;gt; Assignment --&amp;gt; + Button (to create new assignment)]&lt;br /&gt;
&lt;br /&gt;
Step 2: Fill the details for the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Navigate to due dates.&lt;br /&gt;
&lt;br /&gt;
Step 4: Change the number of review rounds to 2.&lt;br /&gt;
&lt;br /&gt;
Step 5: Select &amp;quot;Yes&amp;quot; in the dropdown for review allowed during submission and select &amp;quot;Yes&amp;quot; for submission during the review.&lt;br /&gt;
&lt;br /&gt;
Step 6: Add two users to the assignment(author and reviewer).&lt;br /&gt;
&lt;br /&gt;
Step 7: Log in with some user credentials (author credential).&lt;br /&gt;
&lt;br /&gt;
Step 8: Make a new submission to this assignment.&lt;br /&gt;
&lt;br /&gt;
Step 9: Log in with another user (reviewer).&lt;br /&gt;
&lt;br /&gt;
Step 10: Submit a review of the assignment submission.&lt;br /&gt;
&lt;br /&gt;
Step 11: Login as an author again. &lt;br /&gt;
&lt;br /&gt;
Step 12: Edit the submission.&lt;br /&gt;
&lt;br /&gt;
Step 13: After this check the mailbox of the reviewer [development mail for development].&lt;br /&gt;
&lt;br /&gt;
Step 14: Reviewer should get the mail to re-review the work.&lt;br /&gt;
&lt;br /&gt;
Step 15: Change the due date to some date and time which has passed.&lt;br /&gt;
&lt;br /&gt;
Step 16: Now the author should not be able to make a new submission.&lt;br /&gt;
&lt;br /&gt;
'''Issue 3'''&lt;br /&gt;
&lt;br /&gt;
Step 1: Create new assignment [Manage --&amp;gt; Assignment --&amp;gt; + Button (to create new assignment)]&lt;br /&gt;
&lt;br /&gt;
Step 2: Fill the details for the assignments.&lt;br /&gt;
&lt;br /&gt;
Step 3: Add an existing user to the new assignment&lt;br /&gt;
&lt;br /&gt;
Step 3: Navigate to due dates for the new assignment.&lt;br /&gt;
&lt;br /&gt;
Step 4: Set the due date to 1 hour and 5 seconds from now.&lt;br /&gt;
&lt;br /&gt;
Step 5: The user should recieve a reminder email with the relevant links to the assignment.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138980</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138980"/>
		<updated>2021-10-11T16:17:15Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142. Improve e-mail notifications=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Work in progress==&lt;br /&gt;
This project is ongoing, and this page will be updated live.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Brief Introduction==&lt;br /&gt;
&lt;br /&gt;
* E2142. Improve e-mail notifications&lt;br /&gt;
* The forked repository can be found at: https://github.com/griffinbrookshire/expertiza&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138979</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138979"/>
		<updated>2021-10-11T16:15:21Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142. Improve e-mail notifications=&lt;br /&gt;
&lt;br /&gt;
==Work in progress==&lt;br /&gt;
This project is ongoing, and this page will be updated live.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=138978</id>
		<title>CSC/ECE 517 Fall 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=138978"/>
		<updated>2021-10-11T16:14:55Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - {$num}. {$desc.title}]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2134. Write unit tests for admin_controller.rb and institution_controller.rb]]&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138977</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improve_e-mail_notifications&amp;diff=138977"/>
		<updated>2021-10-11T16:14:16Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Created page with &amp;quot;=E2142. Improve e-mail notifications=  ==Work in progress= This project is ongoing, and this page will be updated live.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142. Improve e-mail notifications=&lt;br /&gt;
&lt;br /&gt;
==Work in progress=&lt;br /&gt;
This project is ongoing, and this page will be updated live.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improving_email_notification&amp;diff=138975</id>
		<title>CSC/ECE 517 Fall 2021 - E2142. Improving email notification</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2142._Improving_email_notification&amp;diff=138975"/>
		<updated>2021-10-11T16:07:22Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: CSC/ECE 517 Fall 2021 - E2142. Improving email notification&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E2142 Improving e-mail notification=&lt;br /&gt;
&lt;br /&gt;
==Work in progress==&lt;br /&gt;
The project is still ongoing. This page will be updated live.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Rmjohn2&amp;diff=138972</id>
		<title>User:Rmjohn2</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Rmjohn2&amp;diff=138972"/>
		<updated>2021-10-11T16:02:40Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Rmjohn2&amp;diff=138971</id>
		<title>User:Rmjohn2</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Rmjohn2&amp;diff=138971"/>
		<updated>2021-10-11T16:02:20Z</updated>

		<summary type="html">&lt;p&gt;Rmjohn2: CSC/ECE 517 Fall 2021 - E1940. Improving email notification&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1940 Improving e-mail notification=&lt;br /&gt;
&lt;br /&gt;
==Work in progress==&lt;br /&gt;
The project is currently ongoing. This wiki page will by updated live.&lt;/div&gt;</summary>
		<author><name>Rmjohn2</name></author>
	</entry>
</feed>