Juergen Posted September 18, 2017 Share Posted September 18, 2017 Hello @ all, I have a some templates which will be loaded via AJAX. They are located in a separate folder under site/ajax/ so they are not in the PW template folder. I have bootstraped these templates via "include("../../index.php");" so I can query PW fields via API calls. It works quite well and I get all values from my PW fields. Unfortunately if I switch the language from German to English, all values will stay in the default language (German). So the language change will not be taken into account, because there are no different urls for each language (no PW pages). Has someone dealed with the same problem and could give me a hint how to take the language change into account? My idea was to add a query string with the id of the language at the end of the AJAX href (like "path/to/myajaxtemplatefile?id=1008) but maybe someone has a better idea. I dont want to create a real PW page for such small piece of information. Best regards 1 Link to comment Share on other sites More sharing options...
adrian Posted September 18, 2017 Share Posted September 18, 2017 24 minutes ago, Juergen said: My idea was to add a query string with the id of the language at the end of the AJAX href (like "path/to/myajaxtemplatefile?id=1008) but maybe someone has a better idea. That's basically how I have handles it in the past: path/to/myajaxtemplatefile.php?lang=portugues Then in the myajaxtemplatefile.php file add this to set the language: $user->language = $languages->get($sanitizer->selectorValue($input->get->lang)); 2 Link to comment Share on other sites More sharing options...
Zeka Posted September 18, 2017 Share Posted September 18, 2017 Hi @Juergen Maybe you can use wireRenderFile and pass language variable in arguments and then use getLanguageValue. 1 Link to comment Share on other sites More sharing options...
BitPoet Posted September 18, 2017 Share Posted September 18, 2017 1 hour ago, Juergen said: I dont want to create a real PW page for such small piece of information Why not? It's not that much work and provides you with all the niceties of language support. Drop a simple PHP template in the regular templates folder: <?php include("../site/ajax/{$input->urlSegment1}.php"); and create a template with url segments enabled with pattern: regex:^[a-zA-Z0-9]+\.php$ A single, hidden page can then route all your ajax calls in a language-aware way. Altogether that shouldn't take more than five minutes. 6 Link to comment Share on other sites More sharing options...
Juergen Posted September 18, 2017 Author Share Posted September 18, 2017 Thank you all for your tipps. These are all interesting options. I am not sure, which opiton I will choose at the end, but now I have some ways to go on further. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now