Mitul Koradiya
Mitul Koradiya

Reputation: 338

OctoberCMS translation language change error using ajax

First install OctoberCMS using composer and git and then install translate plugin with two language English and Spanish. But I have an error with the localePicker. When I choose a language, I get the following error;

AJAX handler 'onSwitchLocale' was not found.

enter image description here

According to this thread, is a October related issue. But I just want to be sure, how can I resolve it?

Please note that mysite.com/{langcode}/ works.

Thanks

Upvotes: 0

Views: 1488

Answers (2)

Fabien Haddadi
Fabien Haddadi

Reputation: 2080

This is a 2021 update: the Ajax handler will be added automatically if you add the Locale Picker component to your layout, not partials or page, if the latter are based on a layout. This point is important. See screenshot.

Inside of page that invokes the layout, my HTML implementation is:

 {% if activeLocale == 'en' %}<a href="#" data-request="onSwitchLocale" data-request-data="locale: 'fr'"><img src="flgfr.png" title="Version française" /></a>{% endif %}
 {% if activeLocale == 'fr' %}<a href="#" data-request="onSwitchLocale" data-request-data="locale: 'en'"><img src="flgen.png" title="English version" /></a>{% endif %}

To be noted that clicking the image will only force the URL to /fr or /en if you tick the "force URL schema" option. enter image description here

Upvotes: 1

Raja Khoury
Raja Khoury

Reputation: 3195

The AJAX handler onswitchlocale was not found simply means you did not attach the component of RainLab.Translate to your page or layout

Add to your layout :

[localePicker]
forceUrl = 1

Upvotes: 3

Related Questions