web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.0 KiB

  1. # Check Message Template
  2. Axe-core uses a custom template to handle dynamic check messages (messages that use the `data` property to output values or to determine which message to display). The structure for the messages is as follows:
  3. ## Simple Message
  4. A simple message is just a string that doesn't use the `data` property. Most checks uses this format.
  5. ```json
  6. {
  7. "messages": {
  8. "pass": "Simple message for a passing check"
  9. }
  10. }
  11. ```
  12. ## Message with Data
  13. A message can also use the `data` property to output information from the check. If `data` is a String, Boolean, or Number, you can use the syntax `${data}` to have the message output the value of the `data` property.
  14. ```js
  15. // check.js
  16. this.data(10);
  17. // check.json
  18. {
  19. "messages": {
  20. "pass": "Passed with a value of ${data}"
  21. // => "Passed with a value of 10"
  22. }
  23. }
  24. ```
  25. If `data` is an object, you can access properties of the object using the syntax `${data.propName}`.
  26. ```js
  27. // check.js
  28. this.data({
  29. contrast: '3:1',
  30. fontSize: '12px'
  31. });
  32. // check.json
  33. {
  34. "messages": {
  35. "fail": "Color-contrast failed with a contrast of ${data.contrast} and font size of ${data.fontSize}"
  36. // => "Color-contrast failed with a contrast of 3:1 and font size of 12px"
  37. }
  38. }
  39. ```
  40. ## Singular and Plural Messages
  41. If the message needs to to know how many items are in the `data` property to determine the type of language to use (singular or plural), you can structure the message to use `singular` and `plural` properties. Use the syntax `${data.values}` to have the message output a comma-separated list of the items (`data.values` is provided by the template code for you).
  42. ```js
  43. // check.js
  44. this.data(['item1', 'item2']);
  45. // check.json
  46. {
  47. "messages": {
  48. "fail": {
  49. "singular": "Attribute ${data.values} is not allowed",
  50. "plural": "Attributes: ${data.values} are not allowed"
  51. }
  52. // => Attributes: item1, item2 are not allowed
  53. }
  54. }
  55. ```
  56. ## Message Determined by Data
  57. Lastly, a message can use the `data` property to determine which message to display. Structure the message to use properties whose keys are the possible values of `data.messageKey`. You should also provide a `default` message that will be displayed if `messageKey` is not set.
  58. ```js
  59. // check.js
  60. this.data({
  61. messageKey: 'imgNode'
  62. });
  63. // check.json
  64. {
  65. "messages": {
  66. "incomplete": {
  67. "default": "Color-contrast could not be determined"
  68. "bgImage": "Element's background color could not be determined due to a background image",
  69. "imgNode": "Element's background color could not be determined because element contains an image node"
  70. }
  71. // => Element's background color could not be determined because element contains an image node
  72. }
  73. }
  74. ```
  75. The messages can still use the syntax `${data.propName}` to access other properties on the `data` property.
  76. ## Migrating From doT.js Template in Translations
  77. Axe-core use to use doT.js for it's temple library. To migrate from doT.js in a translation file, do the following:
  78. - If the message used `{{=it.data}}` or `{{=it.data.propName}}`, change the message to use the syntax `${data}` or `${data.propName}`.
  79. ```diff
  80. {
  81. "messages": {
  82. - "incomplete": "Check that the <label> does not need be part of the ARIA {{=it.data}} field's name"
  83. + "incomplete": "Check that the <label> does not need be part of the ARIA ${data} field's name"
  84. }
  85. }
  86. ```
  87. - If the message used `{{=it.data && it.data.length` to determine using singular or plural language, change the message structure of the message to instead use the `singular` and `plural` properties. Replace `{{=it.data.join(', ')}}` with `${data.values}`.
  88. ```diff
  89. {
  90. "messages": {
  91. - "fail": "Attribute{{=it.data && it.data.length > 1 ? 's' : ''}} {{=it.data.join(', ')}} {{=it.data && it.data.length > 1 ? 'are' : ' is'}} not allowed
  92. + "fail": {
  93. + "singular": "Attribute ${data.values} is not allowed",
  94. + "plural": "Attributes: ${data.values} are not allowed"
  95. + }
  96. }
  97. }
  98. ```