Jump to content

Static translated strings and ajax forms


Recommended Posts

Hi,

here is a task thats new to me. And obviously i overlook some basics. So maybe someone is so kind to give me some advice on this...

I have a page whichs collects some contact boxes straight away on page load. It is a multilanguage Site (default is in German, the screenshots shows the english version). The results are wrapped in a form, because the user is able to narrow the resulting contacts by a page reference language switcher (values are part of every contact entry)*. This is done with a javascript ajax request to avoid page reloads.

TL;DR: While everything is fine on page load, as soon as i select a country to get the related contact boxes by a ajax call, the static translated strings within the target PHP file are not recognized, e.g. their translation fails.

I assume i simply miss some basics here what and when things get parsed when doing such asynchron call.

*) The language switcher values has nothing to do with the choosen user language.

And for the brave ones...

On Page load:

screenshot-1-edit.thumb.png.658472c887a05a8748f4ddf823e3b25a.png

The highlighted areas are static translated strings (s. below). All is fine on page load (whatever current user language).

If the user selects a country within the language switcher, the form in submitted per JS, do a ajax call and query the results by the giving value of the select option (more details s. below).

The result is valid and looks like this (here i narrowed the result to contacts related to germany):

screenshot-2-edit.thumb.png.0288722ba185d0ed2d6b146173309ce8.png

BUT: As you can see, the static translation strings (s. highlighted areas) are not translated (e.g. use the default site language).

To give a brief overview how its done, here some excerpt screens.

Form tag with action target:

1279956128_Bildschirmfoto2022-03-13um13_39_46.thumb.png.d5f297c20a3131beb2b88bbc2186d573.png

Javascript:

1841503299_Bildschirmfoto2022-03-13um13_43_43.thumb.png.2f44f549161aebdea90f4ba42d4be543.png

And here is the processing target PHP file (excerpt):

contacts-flatproducts.php

Many thanks in advance,
Olaf

 

 

 

 

 

 

Link to comment
Share on other sites

  • olafgleba changed the title to Static translated strings and ajax forms

Hi @Zeka, many thanks for your hint! Helped me to get going.

My first guess was right,- missed something obvious ?.

Too avoid the mistake i made, this might help other forum members eventually:

As long as an file (which is used by a javascript ajax call) is not accessible to the processwire core (e.g. is a dedicated page derived from a template at least), such things as core translation etc. are not available in those files.

My approach here was to create a template, create a page from this template (with the code of my former `contacts-flatproducts.php`, s. OP) and took this page as my reference within the form action attribute.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...