Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to translate provider-badges texts at search results display #104

Open
impactfactory opened this issue Feb 15, 2021 · 4 comments
Open

Comments

@impactfactory
Copy link

Thank you for this amazing plugin. Im very greatful!

How can I translate the provider-badges?

using a twig translation code thus expectedly not work. Any other magic?

@tobias-kuendig
Copy link
Member

You can pass them through the | trans filter and then provide your own translations:

{# Translation key is for example 'your.plugin::lang.badges.blog' #}
{{ 'your.plugin::lang.badges.' ~ (result.badge | lower) }}

(or extend the locale of the site search plugin itself:
https://octobertricks.com/tricks/override-translations-with-a-plugin)

Or you can make it even easier and provide the translated values in a page lifecycle method (untested code):

url = "/search"
==
function onStart()
{
    $currentLocale = \RainLab\Translate\Classes\Translator::instance()->getLocale();
    $locales = [
        'de' => ['page' => 'Seite'],
        'en' => ['page' => 'Page'],
    ];

    $this['locale'] = $locales[$currentLocale] ?? [];
}
==

Badge: {{ locale[(result.badge | lower)] }}

@impactfactory
Copy link
Author

impactfactory commented Feb 17, 2021

I would like the second solution as it seems less complicated. But my know how is not advanced enough to make it work or understand the octobertrick - i didnt succeed unfortunately with all kind of attempts :(

you use f.e. {{ result.provider }} not {{ result.badge}} . Also what I do in this view is displayed then in every badge of every results type.

Im willing to test more if you help me through and then provide a complete manual for the next ones that live in a mutlilanguages country like Switzerland :)

@impactfactory
Copy link
Author

impactfactory commented Feb 17, 2021

But, by the way: I found out how to make the input field multilanguage with your code :). My solution is using the Utopigs.Seo-plugin for translating the meta tags.

in the page settings

title = "Suchresultate"
url = "/suchresultate"
layout = "default"
meta_title = "Suchresultate"
meta_description = "Suchresultate"
is_hidden = 0
robot_index = "index"
robot_follow = "follow"

[viewBag]
localeUrl[de] = "/suchresultate"
localeUrl[en] = "/searchresults"
localeTitle[en] = "Search results"
localeMeta_title[en] = "Search Results"
localeMeta_description[en] = "Search results"
....

[searchResults]
...

[searchInput]
...

in the php-section:

function onStart()
{
    // translate the form action url for input field
    $currentLocale = \RainLab\Translate\Classes\Translator::instance()->getLocale();
    $locales = [
        'de' => ['url' => 'suchresultate'],
        'en' => ['url' => 'searchresults']
    ];

    $this['formaction'] = $locales[$currentLocale] ?? [];

}

and in the view:

.... 
<form action="{{ formaction.url }}?q=" method="get">
....

@impactfactory
Copy link
Author

I found the solution to have a multilanguage provider button, but only for my own models that I feed the search with. In plugin.php of my Plugin f.e.

'provider' => e(trans('pluginauthorname.pluginname::lang.search.provider')),

and then add lines in your lang/locale/lang.php like

'search' => [ 'provider' => 'ObjectofYourModel', ]

But how you can achieve that with the plugins that are already available through the settings is still unknow to me.

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

No branches or pull requests

2 participants