-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make language slug available via session metadata #1630
Changes from 5 commits
21d0582
c52535c
848b727
fdac882
3bd8611
d6be27e
82681c3
abc2cfa
37eab50
6b0ad02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
import org.javarosa.core.model.instance.ExternalDataInstance; | ||
import org.javarosa.core.model.instance.InstanceRoot; | ||
import org.javarosa.core.model.instance.TreeElement; | ||
import org.javarosa.core.services.locale.Localization; | ||
|
||
import java.util.Arrays; | ||
import java.util.Hashtable; | ||
|
||
/** | ||
|
@@ -50,7 +52,7 @@ protected InstanceRoot setupCaseData(ExternalDataInstance instance) { | |
} | ||
|
||
@Override | ||
protected InstanceRoot setupSessionData(ExternalDataInstance instance) { | ||
protected InstanceRoot setupSessionData(ExternalDataInstance instance, String locale) { | ||
if (this.mPlatform == null) { | ||
throw new RuntimeException("Cannot generate session instance with undeclared platform!"); | ||
} | ||
|
@@ -61,10 +63,22 @@ protected InstanceRoot setupSessionData(ExternalDataInstance instance) { | |
|
||
Hashtable<String, String> userProperties = u.getProperties(); | ||
|
||
String appLang = locale; | ||
String[] locales = Localization.getGlobalLocalizerAdvanced().getAvailableLocales(); | ||
if (appLang == null || !Arrays.asList(locales).contains(appLang)) { | ||
// the ordering is always ['default', <true default slug>, <all other slugs in order they were added>] | ||
if (locales.length >= 2) { | ||
appLang = locales[1]; | ||
} else { | ||
// to pass tests | ||
appLang = locales[0]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My read of the code here is you are trying to get the current selected locale ? If so, think we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish I had known about this function sooner because this is doing exactly what I was looking to do from the start, without having to do all the unnecessary steps of passing the locale to the root generator function... I might end up reverting the commcare-core PR :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
TreeElement root = | ||
SessionInstanceBuilder.getSessionInstance(sessionWrapper.getFrame(), getDeviceId(), | ||
getVersionString(), getCurrentDrift(), u.getUsername(), u.getUniqueId(), | ||
userProperties, getWindowWidth()); | ||
userProperties, getWindowWidth(), appLang); | ||
root.setParent(instance.getBase()); | ||
return new ConcreteInstanceRoot(root); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does HQ get to know of current locale to send here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly not too sure! I just assumed all navigation request included the locale in the request body which gets set when initializing the sessionNavigationBean. Happy to be told otherwise but it's been accurately giving me the correct locale so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean HQ was already sending the current locale in the request body without us having to make a corresponding HQ change here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I believe so!