lookit / lookit-api

Codebase for Lookit v2 and Experimenter v2. Includes an API. Docs: http://lookit.readthedocs.io/
https://lookit.mit.edu/
MIT License
10 stars 18 forks source link

Add URL locale to info passed to protocol generator #1013

Open becky-gilbert opened 2 years ago

becky-gilbert commented 2 years ago

TL;DR

If a user is forcing translation of the Lookit site by including a locale (language code) in the URL, then the ember study should have access to that info via the protocol generator function.

Addresses part of #973.

Narrative

As a researcher, I would like to use the locale from the Lookit site URL to dynamically set the language of the study. For instance, if participant visits the Japanese verison of the site (https://lookit.mit.edu/ja), I'd like to be able to set up my study so that it automatically uses a Japanese version of the protocol and yaml translation file. In order to set this up, I need access to the locale value in the protocol generator function.

As a user (researcher or participant), when I go to a study page and click the "Preview Now" or "Participate Now" button, I expect the study to be presented in the same language as the one that I'm using on the main site.

Currently, researchers can use the user's country of residence and/or spoken languages list to dynamically set the study language. However, these solutions aren't ideal in all cases, e.g. user's language doesn't match the dominant language of their country, user lists multiple languages so it's not clear which should be used, researcher wants to easily test or share different language versions of their study).

Acceptance Criteria

Implementation Notes

Since the presence/absence and value of the locale can change across sessions, the locale should be added to the pastSessions rather than child object. The locale value for the current session could be stored in the table that stores all study session/response info, and it could be accessible in the protocol generator function with something like pastSessions[0].get('locale').

rhodricusack commented 2 years ago

I was wondering if you could help me out a bit here! I can see the locale being identified and stripped out of the URL in ProxyView

What is the best way to pass the locale through to ember? Am I right that "pastSessions[0]" is populated in ember in _createStudyResponse?

Should the locale be an additional element in the URL string passed from lookit to ember? Or what do you envisage?

becky-gilbert commented 2 years ago

Hi @rhodricusack, I was thinking that the URL locale could be added to the current session information, which is the pastSessions[0] argument passed to the generateProtocol function. To do it this way, I think we'll need to add locale to the Response model on the Lookit API side.

And yes I think the other option is to pass the locale string to the study as a URL query parameter, which we could do in the ExperimentProxyView dispatch method. However this wouldn't add the locale into the participant's response data. I'm not sure whether the language parameter value is automatically saved somewhere in the study data, but I can look into this (or maybe you already know?). If not, and if you need the locale/language value to be saved with the response data, then we'll have to modify the Response model anyway, in which case we might as well skip the query parameter and go for the pastSessions[0] option.

@mekline and @okaycj please let me know if you have thoughts/suggestions.

Right now we're replacing the Pipe video recording service with RecordRTC, but I can come back to this as soon as we're done, if that's ok with you @mekline?

rhodricusack commented 2 years ago

@becky-gilbert Thanks for the considered analysis and clear explanation.

Am I right that you would: (1) add a locale string to the Response model (2) create a response object within lookit-api and populate this with the locale string from the URL (say in the dispatch method), (3) pass the uuid of the response to ember as an extra parameter in the URL (4) add a route to extract this response_id (4) when response_id is provided, retrieve this response object instead of creating a new one in ember, here https://github.com/lookit/ember-lookit-frameplayer/blob/03085e316f03996b443c1626f9428fce6222935c/app/mixins/frame-player-route.js#L61

rhodricusack commented 2 years ago

Do you want me to have a go at this? The only thing holding me back is that I've never set Ember up on our testing server.

mekline commented 1 year ago

Hi @rhodricusack yes you're welcome to do this, and thank you!! Just like last time, a series of smaller PRs for more modular pieces of the solution may be easier for us to handle than a larger one. Please don't hesitate to comment here again if you have questions about how to go about this!