HeikoH
Forum Replies Created
-
Forum: Plugins
In reply to: WordPress doesn't load correct mo-file via AJAX requestProblem solved by previous post.
Forum: Plugins
In reply to: WordPress doesn't load correct mo-file via AJAX requestIn one project I use xili and I solved the problem:
Plugins are loaded before the normal theme. So I wrote a little plugin which contains just a view lines of code to set the language and load the correct MO-files.
The plugin simply does two things:
1. include filter
add_filter('locale', 'my_function', 99);
The priority must be high. Here: 99. The higher priority overwrittes locals that are loaded earlier.
2. In the my_function($locale){….} function I wrote the code to determine which language file should be loaded.
For example:my_function($locale){ if($_GET['lang'] == 'en') return 'en_US'; return $locale; }
So my_function makes wordpress to load en_US.mo file if lang=en. Otherwise the default mo-file is loaded.
But that little “bug-fix-plugin” is not useable for wide range of people. It just fits for my special needs.
In addition:
I also wrote a little plugin to rewrite the xili-URL. example.com?lang=en is not very SEO friendly. With this second plugin I had to make some changes to the first mentioned plugin.Forum: Plugins
In reply to: WordPress doesn't load correct mo-file via AJAX requestI am writing different plugins and applications. And sometimes it is necessary that the user makes an ajax request and showing the result in an overlay(thickbox, lightbox). And (for example) if something goes wrong the error message should be displayed in the user’s language. Not in the default language defined by wp-config.php because the error message is written in the mo-file.
I am now trying to write a plugin which sets the language. I read that plugins are loaded before the $locale is set so this may be a solution (adding a filter using a plugin).
Or is there a solution to unload the default mo-file and load a specific one on the fly? That would also be useful.
Forum: Plugins
In reply to: WordPress doesn't load correct mo-file via AJAX requestThanks for your answer but that’s not what i am looking for. I don’t want to find posts in a language as admin.
I want wordpress to load the correct language files (theme and plugins) when I make an AJAX request from frontend. XILI doesn’t make wordpress to load the correct mo-file when a user makes an AJAX call (load en_US.mo instead of de_DE.mo when $_GET[‘lang’] = ‘en’ is set)