Skip to content
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

Updating choices for single language. #376

Merged
merged 8 commits into from
Oct 10, 2019
Merged

Conversation

nribeka
Copy link
Contributor

@nribeka nribeka commented Sep 26, 2019

Fix #285.

This will inline the label when there's only 1 language for the survey instead of referencing the itext fields.

@lognaturel
Copy link
Contributor

The approach here is to look at the first choice in a list and see whether its label is represented as a dict or a simple value, right? This seems fine to me! I'm guessing you looked at doing it with the header row of the choices sheet and that there's no way to do it with that?

I think the conditionals at https://github.com/XLSForm/pyxform/pull/376/files#diff-642ca628a5111f8d9ff1314acb61ceadL550 would also go away.

@nribeka
Copy link
Contributor Author

nribeka commented Sep 26, 2019

Yes, this is looking at the label whether it is dictionary type or simple value.

@nribeka
Copy link
Contributor Author

nribeka commented Sep 26, 2019

I can do checking on the row header and that's the other approach that I mentioned in the ticket. What that entails:

  • I need to introduce a new field in the intermediate json_dict (probably gonna call it "multi_language" of boolean type).
  • Update the survey object and add new field (same probably).
  • Use that field to conditionally generate the xml document.

What do you think?

@lognaturel
Copy link
Contributor

I don't see a big benefit to having the property exposed in the json_dict. The checks are cheap and I think they're pretty easy to understand.

I see also that on the issue you asked about modifying the expected XML. I don't think there's going to be any way around that. Hopefully there aren't too many tests affected and the diff will be easy to review.

@nribeka
Copy link
Contributor Author

nribeka commented Sep 26, 2019

Kewl then @lognaturel. Going to fix the expected xml next then. There are 5 xml files I think. Not bad.

@codecov-io
Copy link

codecov-io commented Sep 27, 2019

Codecov Report

Merging #376 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #376      +/-   ##
==========================================
+ Coverage   82.33%   82.48%   +0.14%     
==========================================
  Files          23       23              
  Lines        3244     3260      +16     
  Branches      757      763       +6     
==========================================
+ Hits         2671     2689      +18     
+ Misses        436      431       -5     
- Partials      137      140       +3
Impacted Files Coverage Δ
pyxform/survey.py 90.66% <100%> (+0.66%) ⬆️
pyxform/question.py 92.47% <100%> (+0.29%) ⬆️
pyxform/xls2json.py 77.95% <0%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 077972c...6fed6f1. Read the comment docs.

@nribeka
Copy link
Contributor Author

nribeka commented Sep 27, 2019

Unit tests fixed and I added a few tests. Ready for some eyes to check it out.

Copy link
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of suggestions but overall it's looking close to me!


def test_inline_translations(self):
"""
Test using data as the name of the form which will generate <data />.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment. It was a copy-pasta error.


def test_multiple_translations(self):
"""
Test using data as the name of the form which will generate <data />.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should relate to the test. This one is actually a little odd because the reason that translations are generated is because the survey sheet only has a default language (label without a suffix) and the choices sheet only has English (en). I think that's ok but to be more explicit, consider adding a language suffix.

What happens if both have the ::English(en) suffix? No translations are generated, right? Or is it only the case if the settings sheet explicitly sets English(en) as the default? Since this case is a little unclear, I think it's worth having a test for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since I'm checking it whether it's a dictionary or a straight string, whenever there's ::English(en), it will think the survey is multi-language because it will actually generate a dictionary instead of the regular label.

Do you want me to inline this as well? This will require an update in the approach to test for multi-language or not. Instead of checking the first element to see if it's a dictionary or not, i need to count each element in the choices dictionary. Multi language will have more than 1 elements in the choices.

@lognaturel
Copy link
Contributor

It looks like the tests fail on some Python version and that black fails on others. Would be good to look into.

@nribeka
Copy link
Contributor Author

nribeka commented Sep 30, 2019

Fixed for 3.5. I ended up need to sort the label and the name to make sure they're consistent on both 2.7 and 3.5.

I tried to fix the black issue earlier, but failed miserably hahaha ...

@nribeka nribeka marked this pull request as ready for review September 30, 2019 16:08
ukanga
ukanga previously approved these changes Oct 2, 2019
@ukanga ukanga self-requested a review October 2, 2019 23:59
@ukanga ukanga dismissed their stale review October 3, 2019 00:00

@nribeka, can you fix the conflict first? Otherwise, this looks good.

Conflicts:
	pyxform/tests/test_output/cascades_old.xml
@lognaturel lognaturel dismissed their stale review October 3, 2019 17:56

Need to review new changes

@ukanga ukanga merged commit 7fc5e90 into XLSForm:master Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't generate itext block if only one language is defined
4 participants