-
Notifications
You must be signed in to change notification settings - Fork 110
Developer Interface
When it is impossible to achieve all your needs with JSON-encoded configuration, a PHP coding is the next step. It can be done either under a child theme or as an additional integrating plugin. There is a number of already implemented integrating plugins, which can serve examples to start your developemnt with.
It is strongly discouraged to make direct calls to any internal qTranslate-X functions, since they are subject to change at any time, except those that are designed as an interface to the 3rd-party themes and plugins. In most cases, one may use filters instead of direct calls to any function, as the most safe way widely employed by WordPress within their framework.
Available PHP filters are documented in the source code.
Same is applicable to javascript methods, which are documented on the page “Custom Java Scripts“.
- Use test
if(defined( 'QTRANSLATE_FILE'))
and use constantQTRANSLATE_FILE
to compute paths, if necessary. In this way, if qTranslate-X gets installed in a different folder, your code will continue to work. - Use
$translator = apply_filters('wp_translator', null);
, if you plan to use$translator
object for any reason, which will benull
in case no multilingual plugin is activated.
Please, take one of already existing integrating plugins as a starting point. A typical integrating plugin consists of three main PHP files:
- The main head PHP file, which uses action ‘qtranslate_init_language’ to separate code for front- and back-end.
- PHP file with frontend code, which mostly sets filters needed and may alter front-config configuraion branch via filter ‘i18n_front_config’.
- PHP file with back-end code, which uses filter ‘i18n_admin_config’ to load configuration of admin pages. It may also have some additional filters, if necessary.
The most extensive page configuration example would be the code of plugin “Events Made Easy & qTranslate-X“, which can also be implemented as a configuration file instead of plugin. Integrating plugin “WooCommerce & qTranslate-X” uses some additional custom filters at both ends. Plugin “WPBakery Visual Composer & qTranslate-X” provides an example of use of an additional custom java script.
The list of designated interface functions is being shaped and finalized now. Any suggestion is welcome. Meanwhile, if you really need to customize something, which is not yet available on a designated interface, you will probably need one of the following functions:
- qtranxf_convertURL
- qtranxf_get_url_for_language
- qtranxf_getLanguage
- qtranxf_getLanguageName
- qtranxf_generateLanguageSelectCode
- qtranxf_getSortedLanguages
- qtranxf_join_*
- qtranxf_split
- qtranxf_use
- qtranxf_use_language
- qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
- qtranxf_useCurrentLanguageIfNotFoundShowAvailable
Look them up in the PHP source code to find out how to call them.