added title to view configuation#4037
Conversation
|
Hi @drakeloud, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
| return title; | ||
| } | ||
|
|
||
| return `${this._config.title} ${title}`; |
There was a problem hiding this comment.
We should provide the title as a variable to the translation. So the translator can move the order of the words when needed.
There was a problem hiding this comment.
@bramkragten If we make the title as a translation variable though, then we wouldn't be able to data bind to the title field, and include the 'view configuration'
There was a problem hiding this comment.
Not sure I understand what you are saying, I suggest:
this._config.title ?
this.hass!.localize("ui.panel.lovelace.editor.edit_view.header_name", name, ${this._config.title}) :
this.hass!.localize("ui.panel.lovelace.editor.edit_view.header")There was a problem hiding this comment.
I'm not sure I am following either. Because config.title is a dynamic value, it doesn't seem like we can move that to the translation variables like you mentioned, so how do you suggest that we allow the translator to change the order of the translation for that value?
Oh wait a second. So you are suggesting passing all of that in to the localize function, and having the translator take care of it?
Where is the code for the localize function to change the parameters for the function? Perhaps I am confused about how the hass.localize function works.
There was a problem hiding this comment.
There was a problem hiding this comment.
We can pass arguments to the localize function, and add placeholders ({placeholder}) to the translations text. These placeholders are replaced by the values we pass in as arguments.
|
@bramkragten I updated my PR. Is this what you were meaning? |
| );; | ||
| } | ||
|
|
||
| return this.hass!.localize("ui.panel.lovelace.editor.edit_view.header_name", this._config.title) |
There was a problem hiding this comment.
Does the key header_name exist? You have to add it to src/translations/en.json: Edit view {name}
And you have to pass the name of the placeholder you want to replace:
| return this.hass!.localize("ui.panel.lovelace.editor.edit_view.header_name", this._config.title) | |
| return this.hass!.localize("ui.panel.lovelace.editor.edit_view.header_name", name, this._config.title) |
| } | ||
|
|
||
| private get _viewConfigTitle(): string { | ||
| if (!this._config || !this._config.title || this._config.title === "") { |
There was a problem hiding this comment.
If there is no config we might want to change the header to Add new view?
| } | ||
|
|
||
| private get _viewConfigTitle(): string { | ||
| if (!this._config || !this._config.title || this._config.title === "") { |
There was a problem hiding this comment.
An empty string is falsy in javascript so this._config.title === "" is not needed.
| if (!this._config || !this._config.title || this._config.title === "") { | |
| if (!this._config || !this._config.title) { |
|
@bramkragten Ah I see. I admittedly have never done any work before around localization, so this has been all new for me. Thanks for the tips along the way. I have updated the PR with your suggestions. |
Fixed issue #4025
Added the config title to the card!