Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Bug: create short label for all translations #268

Closed
florianm opened this issue Dec 21, 2021 · 7 comments · Fixed by #270
Closed

Bug: create short label for all translations #268

florianm opened this issue Dec 21, 2021 · 7 comments · Fixed by #270
Assignees
Labels
Projects

Comments

@florianm
Copy link
Contributor

https://forum.getodk.org/t/collect-crashes-when-switching-languages/36056/9

Repro:
Create form
Add short labels
Add language
Don't fill in short labels in new language
Deploy form to Central (no error)
Fill form in Android, switch lang, collect crashes.

@florianm florianm added the bug label Dec 21, 2021
@florianm florianm self-assigned this Dec 21, 2021
@florianm florianm added this to To do in Roadmap via automation Dec 21, 2021
@florianm florianm added this to the 0.4.1 milestone Dec 21, 2021
@florianm
Copy link
Contributor Author

florianm commented Dec 26, 2021

So far I haven't been able to populate the additional translations' short label, guidance hint et al. if added.
I've added a help text item in 1f51d50 (wrong issue link because clumsy) to prompt the user to populate short label and guidance hints for all translations if given in one translation.

Given that a user will want to provide translations for all user facing elements of a form, I'm not sure how much of a blocking issue this bug is.

@florianm florianm moved this from To do to In progress in Roadmap Dec 28, 2021
@lognaturel
Copy link
Member

This isn’t unique to short labels. How does Build deal with this with regular labels and hints? I think it would make sense to match that. Pyxform adds a - for any missing translations.

@issa-tseng
Copy link
Member

it just needs to generate the node on output always i assume. probably right now it's only dropping into whatever it sees. totally uneducated guessing here but it's not a complex export methodology. it's very 1980s if anything..

@florianm
Copy link
Contributor Author

florianm commented Jan 2, 2022

The current behaviour is indeed to create empty nodes for missing labels and hints (second nesting level).

The third nesting level, alternative forms like "short", "image", "bigimage", "video", "audio", which I've added way after the translation plumbing was designed, get dropped.

  <translation lang="English (en)">
          <text id="/data/text_1:label">
            <value>Text 1 label en</value>
            <value form="short">Text 1 short en</value>
            <value form="image">jr://images/text1.jpg</value>
          </text>
          <text id="/data/text_1:hint">
            <value>Text 1 hint</value>
            <value form="guidance">Text 1 guidance</value>
          </text>
          <text id="/data/text_1:constraintMsg">
            <value>Text 1 invalid</value>
          </text>
          <text id="/data/untitled1:label">
            <value>label 2 en</value>
            <value form="short">short 2 en</value>
          </text>
        </translation>
        <translation lang="Bavarian (bar)">
          <text id="/data/text_1:label">
            <value></value> // EMPTY TRANSLATION == EMPTY NODE (current behaviour)
                                       // NO SHORT LABEL == NO NODE
          </text>
          <text id="/data/text_1:hint">
            <value></value> // EMPTY TRANSLATION 
          </text>
          <text id="/data/text_1:constraintMsg">
            <value></value>
          </text>
          <text id="/data/untitled1:label">
            <value>label 2 bar</value>
          </text>
        </translation>
      </itext>

The difficulty I'm seeing is that due to the way the data is nested, in order to create a node in a second translation, I would need to introspect the other translations and create each node (or fill it with "-") if it exists in any of the other translations. My play time is limited, but if I can find a way to generate this I'll test it.

I fear creating empty nodes could create unwanted behaviour, e.g. while a given short label will replace the long form label in the hierarchy view, an empty short label could hide the long form label.

The only result I want to see in a translated form is the form designer provides complete and consistent translated strings.

@issa-tseng
Copy link
Member

i still haven't looked deeply at the code so i'm just another idiot with an opinion here, but i think if you preprocess what should always be there before things get going and then apply it on the fly your job will get easier.

i hear you on the empty nodes but clearly xlsform is creating them and it's no problem.

@florianm
Copy link
Contributor Author

florianm commented Jan 3, 2022

Hearing empty nodes are no problem is reassuring, thanks!
As a next step (when I find time) I will create a few minimal forms with empty/missing nodes to see what exactly crashes Collect, then form a plan which properties need nodes and which don't.

florianm pushed a commit to dbca-wa/build that referenced this issue Jan 5, 2022
* If an extra parameter or label or hint has at least one non-empty string, empty nodes are added for all missing translations
* If an extra parameter is not filled in for any language, no nodes will be added
* Noop: Add some comments in preparation for getodk#126
@florianm
Copy link
Contributor Author

florianm commented Jan 5, 2022

Thanks to Issa's push into the right direction, dbca-wa@c0aa062 adds empty nodes where needed and no nodes where no strings are given.

Let the XML do the talking:

<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:orx="http://openrosa.org/xforms" xmlns:odk="http://www.opendatakit.org/xforms">
  <h:head>
    <h:title>Translation268</h:title>
    <model>
      <instance>
        <data id="Translation268" orx:version="1641370369">
          <orx:meta>
            <orx:instanceID/>
          </orx:meta>
          <text_1>
            Text 1 default
          </text_1>
          <untitled1/>
        </data>
      </instance>
      <itext>
        <translation lang="English (en)">
          <text id="/data/text_1:label">
            <value>Text 1 label en</value>
            <value form="short">Text 1 short en</value> // Short label given in EN
            <value form="image">jr://images/text1.jpg</value> // Image label given in EN
          </text>
          <text id="/data/text_1:hint">
            <value>Text 1 hint</value>
            <value form="guidance">Text 1 guidance</value>
          </text>
          <text id="/data/text_1:constraintMsg">
            <value>Text 1 invalid</value>
          </text>
          <text id="/data/untitled1:label">
            <value>label 2 en</value>
            <value form="short">short 2 en</value>
          </text>
        </translation>
        <translation lang="Bavarian (bar)">
          <text id="/data/text_1:label">
            <value></value>
            <value form="short"></value> // Short label not given in BAR, empty node
            <value form="image"></value> // Image label not given in BAR, empty node
// no empty nodes for any other entirely missing labels: big-image, audio, video
          </text>
          <text id="/data/text_1:hint">
            <value></value>
            <value form="guidance"></value>
          </text>
          <text id="/data/text_1:constraintMsg">
            <value></value>
          </text>
          <text id="/data/untitled1:label">
            <value>label 2 bar</value>
            <value form="short"></value>
          </text>
        </translation>
      </itext>
      <bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid"/>
      <bind nodeset="/data/text_1" type="string" jr:constraintMsg="jr:itext('/data/text_1:constraintMsg')"/>
      <bind nodeset="/data/untitled1" type="string"/>
    </model>
  </h:head>
  <h:body>
    <input ref="/data/text_1">
      <label ref="jr:itext('/data/text_1:label')"/>
      <hint ref="jr:itext('/data/text_1:hint')"/>
    </input>
    <input ref="/data/untitled1">
      <label ref="jr:itext('/data/untitled1:label')"/>
    </input>
  </h:body>
</h:html>

XML export and .odkbuild save file:
Translation268.zip

Tested the form in Collect and changing languages does not crash the form any more.
In English I see the label, image label, both short labels, hint and guidance hint.
In Bavarian, I see the labels and nothing else. Short labels in hierarchy view are empty.

While this testing is not exhaustive, it indicates that the bug is fixed.

florianm pushed a commit to dbca-wa/build that referenced this issue Jan 10, 2022
Roadmap automation moved this from In progress to Done Jan 25, 2022
florianm pushed a commit that referenced this issue Jan 25, 2022
Fix #268: create empty nodes for missing translations
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
3 participants