Crestron Components Lib - Showcase App

multi-language support

Emulator Scenario (click to expand) (click to collapse)
{
  "cues": [
    {
      "type": "boolean",
      "event": "trigger_11",
      "trigger": true,
      "actions": [
        {
          "state": "temperature_in_city",
          "type": "s",
          "logic": "set",
          "value": "-+temperature.temp37+-"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "trigger_21",
      "trigger": true,
      "actions": [
        {
          "state": "temperature_in_city",
          "type": "s",
          "logic": "set",
          "value": "-+temperature.temp20+-"
        }
      ]
    }
  ],
  "onStart":[
    {
      "state": "temperature_in_city",
      "type": "s",
      "value":  "-+temperature.temp20+-"
    }
  ]
}
Emulator actions

Press the Load button to load the scenario. This will also reload all of the existing examples on the page.

Press the Run button to run the scenario. You only need to do this if the scenario (the json) has an onStart key.

Events and states

The Emulator Scenario JSON contains an array of cues and an optional array onStart.

→ A cue is defined by: type:string, event:string, trigger:boolean|string|number, actions:array
→ An action is defined by: type:string, state:string, logic:string ... plus other fields ( depending on type)

The value of the state or event for a cue or for an action is a string which represents the name of that state or action.

Type field

The type for cue or for action can be the string:

  • b or boolean - for a boolean state or event
  • n or number or numeric - for a number state or event
  • s or string - for a string state or event
  • o or object - for an object state or event
Trigger field

The trigger can be either a fixed value of the same type as the state or event, or the string "&change". If it is a fixed value then, when the emulator detects that the state or event has changed to the value given in trigger, it also executes the actions for that state or event. If the value is the string is "&change", regardless of state or event type, the actions are executed on any change in the value of the state or event.

Logic Field

The logic can be:

  • link - passes the value received on the incoming join through to the outgoing join. Using this between incompatible join types will attempt to cast the value. In the event of a cast failure, the value will be set to false, 0 or "" (empty string).
  • set - assigns a specific value to the join. This requires a 5th key of 'value' and the specific value to assign. ie. {"state":"light_level", "type":"n", "logic": "set","value":5}. If the 5th key is omitted, the default value will be sent (false, 0, "" or {}).
  • toggle - (boolean Only) reads the current state and changes it to the opposite state.
  • pulse - (boolean Only) value goes high and then low.
  • increment - (Numeric Only) reads the current value of the analog and adds an offset. This logic accepts an optional 5th key of 'offset which determines how many times to increment by. ie. {"event":"volume_level","type":"n", "logic":"increment","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.
  • decrement - (Numeric Only) reads the current value of the analog and subtracts an offset. This logic accepts an optional 5th key of 'offset which determines how many times to decrement by. ie. {"event":"volume_level","type":"n", "logic":"decrement","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.
  • RCB logic can be accomplished by defining an action containing an object state or event of RCB type. A 5th key is expected as the amount of time in milliseconds to reach the level. {"signal":"light_level", "type":"n", "logic": "rcb","value":65535, "time":2000}
    { "rcb":{ "value": numeric_value, "time": duration_in_ms } }
Scenario example:

    {
      "cues": [
        {
          "type": "boolean",
          "event": "trigger",
          "trigger": true,
          "actions": [
            {
              "state": "action1",
              "type": "boolean",
              "logic": "toggle"
            },
            {
                "state": "rcb_signal",
                "type": "object",
                "logic": "set",
                "value": {
                    "rcb":{
                        "value": 101,
                        "time": 1500
                    }
                }
            }
          ]
        }
      ],
      "onStart": [
      ]
    }
    
Try multilanguage options to see how the language change works.
Components use the i18next interface to make the translations.
The JS code will help for understanding how it is implemented.


Subscribe



All components:

Button:



data-ch5-textcontent

Changes the value of the string signal temperature_in_city to "37 degrees Celsius"

Changes the value of the string signal temperature_in_city to "20 degrees Celsius"

DIV: Testing data-ch5-textcontent



data-ch5-i18n

Testing with inner html

Image alt:

Select

Toggle

Modal Dialog

Spinner:

<label for="language">Change language</label>
<select class="language-dropdown" onchange="changeLanguage(this.value)" id="language">
    <option value="en">en</option>
    <option value="de">de</option>
    <option value="cz">cz</option>
</select>
<br />
<br />
<h4>Subscribe</h4>
<ch5-textinput
  placeholder="-+firstname.placeholder+-"
  feedbackMode="submit"
  label="-+firstname.label+-"
  >
</ch5-textinput>
<br />
<ch5-toggle
  label="-+gender.label+-"
  labelOn="-+gender.m+-"
  labelOff="-+gender.f+-"
>
</ch5-toggle>
<br />
<ch5-button
  label="-+button.save+-"
  size="small"
  type="primary"
></ch5-button>
<ch5-button
  label="-+button.reset+-"
  size="small"
  type="danger"
>
</ch5-button>
<div class="components">
  <h4>All components: </h4>

  <div class="component">
    <p><strong>Button:</strong></p>
    <ch5-button
      label="-+button.save+-">
    </ch5-button>
  </div>
<br />
<br />
<h4>data-ch5-textcontent</h4>

    <p>
        Changes the value of the string signal temperature_in_city to "37 degrees Celsius"
        <ch5-button sendEventOnClick="trigger_11" label="T1"></ch5-button>
    </p>
    <p>
        Changes the value of the string signal temperature_in_city to "20 degrees Celsius"
        <ch5-button sendEventOnClick="trigger_21" label="T2"></ch5-button>
    </p>

    <div id="textcontent-el-1" class="b-red"
         data-ch5-textcontent="temperature_in_city">
        DIV: Testing data-ch5-textcontent
    </div>
<br />
<br />
<br />
<h4>data-ch5-i18n</h4>

	  <div data-ch5-i18n="-+i18ntext.body+-"></div>
	  <div data-ch5-i18n="-+[inner=span#test-span]i18ntext.body+-">
		  <span>Testing with inner html</span><br>
		  <span id='test-span'></span>
	  </div>
	  <img src="ch5image.png" data-ch5-i18n="-+[attr=alt]i18ntext.imagetext+-" />
<br />
  <div class="component">
    <p>Image alt:</p>
    <ch5-image alt="-+image.alt+-"></ch5-image>
  </div>

  <div class="component">
    <p>Select</p>
    <ch5-select size="5" indexId="idx" noneSelectedPrompt="-+select.noneSelectedPrompt+-">
        <template>
            <ch5-select-option>
                <div>
                    <span>item_{{idx}}</span>
                </div>
            </ch5-select-option>
        </template>
    </ch5-select>
  </div>

  <div class="component">
    <p>Toggle</p>
    <ch5-toggle
      label="-+gender.label+-"
      labelOn="-+gender.m+-"
      labeloff="-+gender.f+-"
    ></ch5-toggle>
  </div>

  <div class="component">
    <p>Modal Dialog</p>
    <ch5-modal-dialog
            receiveStateShowPulse="trigger_1"
            closable
            mask
            title="-+modalDialog.title+-"
            okButtonLabel="-+modalDialog.okButton+-"
            cancelButtonLabel="-+modalDialog.cancelButton+-"
            prompt="-+modalDialog.prompt+-">

        <ch5-image
                id="ex1-img"
                url="https://picsum.photos/200/300/?random">
        </ch5-image>
    </ch5-modal-dialog>
    <ch5-button
        sendEventOnClick="trigger_1"
        label="-+button.show+-"
        >
    </ch5-button>
  </div>
  <div class="component">
    <p>Spinner:</p>
    <ch5-spinner
        label="-+spinner.label+- {{idx}}"
        indexId="idx"
        size="40"
        itemHeight="40"
        visibleItemScroll="3">
    </ch5-spinner>
  </div>

</div>