Skip to content

Dynamic translation for search form placeholder text (Lombiq Technologies: OCORE-255)#18981

Open
Piedone wants to merge 7 commits intoOrchardCMS:mainfrom
Lombiq:issue/OCORE-255-translation
Open

Dynamic translation for search form placeholder text (Lombiq Technologies: OCORE-255)#18981
Piedone wants to merge 7 commits intoOrchardCMS:mainfrom
Lombiq:issue/OCORE-255-translation

Conversation

@Piedone
Copy link
Member

@Piedone Piedone commented Mar 11, 2026

No description provided.

{% endif %}

{% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' %}
{% assign placeholder = Model.Placeholder | default: 'Enter your search term(s)' | t %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder is dynamic data, right?

Copy link
Member Author

@Piedone Piedone Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you mean. Model.Placeholder comes from the search settings and can be provided by the admin user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use IDataLocalizer if I'm not wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add a liquid filter for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there one? I assumed there will be, and this actually turned out working indeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed there will be, and this actually turned out working indeed.

How do you localize the dynamic placeholder in PO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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" %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Search" in this context is easy to add, but it needs a provider to capture all the localization strings :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a provider too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, what? It's a static string, use t, not d, it's a fundamental misunderstanding otherwise (maybe from me).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya t is suited for "Enter your search term(s)" but for Model.Placeholder IMHO d is suited because it's dynamic, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Piedone changed the title Missing translation for search form placeholder text (Lombiq Technologies: OCORE-255) Dynamic translation for search form placeholder text (Lombiq Technologies: OCORE-255) Mar 13, 2026
@hishamco
Copy link
Member

@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

@hishamco
Copy link
Member

FYI #18999

Comment on lines +21 to +24
if (string.IsNullOrEmpty(searchSettings.Placeholder))
{
return Enumerable.Empty<DataLocalizedString>();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (string.IsNullOrEmpty(searchSettings.Placeholder))
{
return Enumerable.Empty<DataLocalizedString>();
}
var placeholder = string.IsNullOrEmpty(searchSettings.Placeholder)
? "Enter your search term(s)"
: searchSettings.Placeholder

Copy link
Member Author

@Piedone Piedone Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return new[]
{
new DataLocalizedString("Search", searchSettings.Placeholder, string.Empty),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<input name="Terms" type="text" value="@Model.Terms" class="form-control form-control-lg" placeholder="@D[Model.Placeholder, "Search"].Value" autofocus />

Comment on lines +7 to 11
@{
var placeholder = string.IsNullOrWhiteSpace(Model.Placeholder)
? T["Enter your search term(s)"].Value
: D[Model.Placeholder, "Search"].Value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@{
var placeholder = string.IsNullOrWhiteSpace(Model.Placeholder)
? T["Enter your search term(s)"].Value
: D[Model.Placeholder, "Search"].Value;
}

Comment on lines +9 to +12
{% assign placeholder = "Enter your search term(s)" | t %}
{% else %}
{% assign placeholder = Model.Placeholder | d: "Search" %}
{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% assign placeholder = "Enter your search term(s)" | t %}
{% else %}
{% assign placeholder = Model.Placeholder | d: "Search" %}
{% endif %}
{% assign placeholder = Model.Placeholder | d: "Search" %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants