Dynamic translation for search form placeholder text (Lombiq Technologies: OCORE-255)#18981
Dynamic translation for search form placeholder text (Lombiq Technologies: OCORE-255)#18981Piedone wants to merge 7 commits intoOrchardCMS:mainfrom
Conversation
| {% endif %} | ||
|
|
||
| {% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' %} | ||
| {% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' | t %} |
There was a problem hiding this comment.
Placeholder is dynamic data, right?
There was a problem hiding this comment.
I'm not sure I understand what you mean. Model.Placeholder comes from the search settings and can be provided by the admin user.
There was a problem hiding this comment.
This should use IDataLocalizer if I'm not wrong
There was a problem hiding this comment.
Ah right, indeed. Fixed that.
| {% endif %} | ||
|
|
||
| {% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' | t %} | ||
| {% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' | d %} |
There was a problem hiding this comment.
Let me add a liquid filter for it
There was a problem hiding this comment.
Isn't there one? I assumed there will be, and this actually turned out working indeed.
There was a problem hiding this comment.
AFAIK, there's t only. Now I'm adding a data localization filter in a new PR
Now the question is, if this was entered by the admin, there should be some sort of context to make it translatable
There was a problem hiding this comment.
I assumed there will be, and this actually turned out working indeed.
How do you localize the dynamic placeholder in PO?
There was a problem hiding this comment.
@sebastienros, correct me if I'm wrong regarding my comment #18981 (comment)
| {% endif %} | ||
|
|
||
| {% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' %} | ||
| {% assign placeholder = Model.Placeholder | default: "Enter your search term(s)" | d: "Search" %} |
There was a problem hiding this comment.
"Search" in this context is easy to add, but it needs a provider to capture all the localization strings :)
There was a problem hiding this comment.
Wait, what? It's a static string, use t, not d, it's a fundamental misunderstanding otherwise (maybe from me).
There was a problem hiding this comment.
Ya t is suited for "Enter your search term(s)" but for Model.Placeholder IMHO d is suited because it's dynamic, right?
There was a problem hiding this comment.
If this is used as a trick and anything will return the same translation slot for this provider, then the context should be more specific. But instead I'd used the actual text, from the placeholder value. Or we are creating a provider for a single value
There was a problem hiding this comment.
This diff here shows old code. The current one uses t for the default and d for the admin-configured placeholder: https://github.com/OrchardCMS/OrchardCore/pull/18981/changes#diff-6de49ec02dc75dceeeb8efc8b73b1f4db6c2e42a66cef2b5a1b3cb49ba9057ff.
But note that this won't properly work yet, unless you merge from #18988 first. That needs to be merged before this PR. And yes, for that to work, this does have a provider for a single value.
|
@Piedone, I'm planning to introduce a new provider to help with the use case. The basic idea is to create a localization provider that allows the user to participate in adding localization strings |
|
FYI #18999 |
| if (string.IsNullOrEmpty(searchSettings.Placeholder)) | ||
| { | ||
| return Enumerable.Empty<DataLocalizedString>(); | ||
| } |
There was a problem hiding this comment.
| if (string.IsNullOrEmpty(searchSettings.Placeholder)) | |
| { | |
| return Enumerable.Empty<DataLocalizedString>(); | |
| } | |
| var placeholder = string.IsNullOrEmpty(searchSettings.Placeholder) | |
| ? "Enter your search term(s)" | |
| : searchSettings.Placeholder |
There was a problem hiding this comment.
Why would we do this? If you didn't specify the placeholder in search settings, then the default will be used, which has a static PO translation.
I assume your other comments are related to this too. However, for the templates to be changed SearchController needs to be changed as well.
|
|
||
| return new[] | ||
| { | ||
| new DataLocalizedString("Search", searchSettings.Placeholder, string.Empty), |
There was a problem hiding this comment.
| new DataLocalizedString("Search", searchSettings.Placeholder, string.Empty), | |
| new DataLocalizedString("Search", placeholder, string.Empty), |
| } | ||
| <form asp-action="Search" asp-controller="Search" asp-area="OrchardCore.Search" asp-route-index="@Model.Index" method="get"> | ||
| <div class="input-group mb-3 mt-5"> | ||
| <input name="Terms" type="text" value="@Model.Terms" class="form-control form-control-lg" placeholder="@placeholder" autofocus /> |
There was a problem hiding this comment.
| <input name="Terms" type="text" value="@Model.Terms" class="form-control form-control-lg" placeholder="@D[Model.Placeholder, "Search"].Value" autofocus /> |
| @{ | ||
| var placeholder = string.IsNullOrWhiteSpace(Model.Placeholder) | ||
| ? T["Enter your search term(s)"].Value | ||
| : D[Model.Placeholder, "Search"].Value; | ||
| } |
There was a problem hiding this comment.
| @{ | |
| var placeholder = string.IsNullOrWhiteSpace(Model.Placeholder) | |
| ? T["Enter your search term(s)"].Value | |
| : D[Model.Placeholder, "Search"].Value; | |
| } |
| {% assign placeholder = "Enter your search term(s)" | t %} | ||
| {% else %} | ||
| {% assign placeholder = Model.Placeholder | d: "Search" %} | ||
| {% endif %} |
There was a problem hiding this comment.
| {% assign placeholder = "Enter your search term(s)" | t %} | |
| {% else %} | |
| {% assign placeholder = Model.Placeholder | d: "Search" %} | |
| {% endif %} | |
| {% assign placeholder = Model.Placeholder | d: "Search" %} |
No description provided.