@@ -56,13 +56,6 @@ const ADDON_YAML_SCHEMA = DEFAULT_SCHEMA.extend([
5656
5757const MASKED_FIELDS = [ "password" , "secret" , "token" ] ;
5858
59- function getFieldKey (
60- entry : HaFormSchema ,
61- options ?: { path ?: string [ ] }
62- ) : string {
63- return options ?. path ? [ ...options . path , entry . name ] . join ( "." ) : entry . name ;
64- }
65-
6659@customElement ( "hassio-addon-config" )
6760class HassioAddonConfig extends LitElement {
6861 @property ( { attribute : false } ) public addon ! : HassioAddonDetails ;
@@ -89,27 +82,38 @@ class HassioAddonConfig extends LitElement {
8982
9083 @query ( "ha-yaml-editor" ) private _editor ?: HaYamlEditor ;
9184
85+ private _getTranslationEntry (
86+ language : string ,
87+ entry : HaFormSchema ,
88+ options ?: { path ?: string [ ] }
89+ ) {
90+ let parent = this . addon . translations [ language ] ?. configuration ;
91+ if ( ! parent ) return undefined ;
92+ if ( options ?. path ) {
93+ for ( const key of options . path ) {
94+ parent = parent [ key ] ?. fields ;
95+ if ( ! parent ) return undefined ;
96+ }
97+ }
98+ return parent [ entry . name ] ;
99+ }
100+
92101 public computeLabel = (
93102 entry : HaFormSchema ,
94103 _data : HaFormDataContainer ,
95104 options ?: { path ?: string [ ] }
96105 ) : string =>
97- this . addon . translations [ this . hass . language ] ?. configuration ?. [
98- getFieldKey ( entry , options )
99- ] ?. name ||
100- this . addon . translations . en ?. configuration ?. [ getFieldKey ( entry , options ) ]
101- ?. name ||
106+ this . _getTranslationEntry ( this . hass . language , entry , options ) ?. name ||
107+ this . _getTranslationEntry ( "en" , entry , options ) ?. name ||
102108 entry . name ;
103109
104110 public computeHelper = (
105111 entry : HaFormSchema ,
106112 options ?: { path ?: string [ ] }
107113 ) : string =>
108- this . addon . translations [ this . hass . language ] ?. configuration ?. [
109- getFieldKey ( entry , options )
110- ] ?. description ||
111- this . addon . translations . en ?. configuration ?. [ getFieldKey ( entry , options ) ]
114+ this . _getTranslationEntry ( this . hass . language , entry , options )
112115 ?. description ||
116+ this . _getTranslationEntry ( "en" , entry , options ) ?. description ||
113117 "" ;
114118
115119 private _convertSchema = memoizeOne (
0 commit comments