Create language-dependent JavaScript files for CMS modules
The bluetronix CMS automatically generates optimized JavaScript files for each active language on your website. You will learn how standard files, individual adjustments, and language-dependent module texts are merged, and how the CMS automatically incorporates the appropriate files into your website.
Language-dependent JavaScript files
The bluetronix CMS can generate its own JavaScript files for each activated language on your website. This provides language-dependent texts and functions directly within the respective JavaScript file.
The required files are automatically created as soon as you save a module configuration. The CMS considers both the standard files and your individual adjustments.
This tutorial builds on the documentation "Integrating and customizing CMS modules." You should already be familiar with the developer folder bx_Mod and the use of your own _own files.
1. Automatic generation of JavaScript files
When you save a module configuration, the CMS automatically regenerates all necessary language-dependent JavaScript files.
Only the language versions that you have activated via the Lang module will be created.
The activated languages are determined through the global module configuration:
bx_Mod/config_own.php
For example, if you have activated German, English, and Spanish, the CMS will create the corresponding JavaScript files for these three languages.
Changing the color set or layout no longer modifies the JavaScript files. The automatic regeneration occurs when saving a module configuration.
2. Manually generate JavaScript files
In addition to automatic generation, you can have the language-dependent JavaScript files created manually.
To do this, as an administrator, access the following address. Replace the example domain with the address of your CMS:
https://xxxx.bxserver.net/bx_Mod/BxScript.php
Through this call, you can regenerate the JavaScript files independently of saving a module configuration.
3. Global module configuration
The global module configuration is located at:
bx_Mod/config_own.php
This file contains the individual settings for your project. It is set up according to the user's requirements after installation.
Here, it is determined what modules and areas should be used, for example, shop or blog. The activated languages are also taken into account.
The configuration thus forms an important basis for the generation of language-dependent JavaScript files.
4. Module configurations and language files
When generating, the CMS takes into account the configuration files of the respective modules. This includes the standard configuration, individual adjustments, and language-dependent texts.
For example, in the shop module, these are:
bx_Mod/Shop/config.php
bx_Mod/Shop/config_own.php
bx_Mod/Shop/config_text_de.php
bx_Mod/Shop/config_text_de_own.php
The files serve different purposes:
config.php: Contains the standard configuration of the shop module.
config_own.php: Contains your individual configuration settings.
config_text_de.php: Contains the default German texts of the shop module.
config_text_de_own.php: Contains your individual adjustments of the German texts.
For other activated languages, the corresponding language files are taken into account.
Try not to change the standard files directly. Use the designated _own files for individual adjustments so that your changes are retained during regular CMS updates.
5. Default JavaScript and custom adjustments
The general JavaScript files are located in the developer folder bx_script.
For the central JavaScript functions, the following files are considered:
/bx_script/BxScript_own_min.js
/bx_script/BxScript_own.js
/bx_script/BxScript_own_min.js
BxScript.js is the standard file of the bluetronix CMS. It can be overwritten during system updates.
The files BxScript_own.js and BxScript_own_min.js are intended for individual adjustments.
These files can be considered when generating the language-dependent JavaScript files.
6. Header JavaScript and custom adjustments
In addition to the general JavaScript files, there are separate files for the header of your website.
/bx_script/BxHeadScript_own_min.js
/bx_script/BxHeadScript_own.js
/bx_script/BxHeadScript_own_min.js
BxHeadScript.js contains the header JavaScript functions provided by the CMS. This standard file can be overwritten during a system update.
For your own adjustments, BxHeadScript_own.js and BxHeadScript_own_min.js are available.
The corresponding language-dependent versions are also generated from these files.
7. Generated JavaScript files
From the existing configuration, language, and JavaScript files, the CMS generates separate files for each activated language.
For example, the following general JavaScript files are created:
/bx_script/BxScript_de.js
/bx_script/BxScript_en.js
/bx_script/BxScript_ru.js
/bx_script/BxScript_es.js
Additionally, the corresponding header JavaScript files are created:
/bx_script/BxHeadScript_de.js
/bx_script/BxHeadScript_en.js
/bx_script/BxHeadScript_ru.js
/bx_script/BxHeadScript_es.js
The language codes indicate the respective language. For example, de stands for German, en for English, ru for Russian, and es for Spanish.
The CMS only generates files for the languages that are actually activated.
8. Optimization of generated JavaScript files
During generation, the JavaScript files are also optimized. This can remove unnecessary comments and redundant whitespace.
The simple optimization includes the following steps:
1. Lines that begin with // are removed.
2. Lines that contain only whitespace are removed.
3. Multiple spaces can be replaced by a single space.
Full minification is currently not strictly necessary.
The optimization reduces unnecessary content within the generated JavaScript files.
9. Automatically include language-specific JavaScript files
The bluetronix CMS checks whether a corresponding JavaScript file is available for the currently selected language when generating your website.
In the HTML layout, for example, the general JavaScript file may be included via the following CMS tag:
__FV_/bx_script/BxScript_own_min.js__
When the visitor accesses the German language version of your website and the corresponding language file is available, the CMS automatically replaces the tag with:
__FV_/bx_script/BxScript_de.js__
The same principle applies to the header JavaScript file.
From:
__FV_/bx_script/BxHeadScript_own_min.js__
this becomes:
__FV_/bx_script/BxHeadScript_de.js__
The existing HTML inclusion does not need to be adjusted for each language individually.
If no suitable language file is available, the general JavaScript file remains included.
10. Update browser cache with file modification date
To prevent browsers from loading an outdated JavaScript file from the cache after a change, the CMS can additionally use the modification date of the respective file.
The included JavaScript file therefore receives a version parameter.
Example:
BxScript_de.js?v=DATEI_AENDERUNGS_DATUM
If the file changes, the version parameter may also change. This allows the browser to recognize the changed file version and reload it.
This procedure can be used for both the general JavaScript files and the header JavaScript files.
11. Summary
The bluetronix CMS automatically creates separate JavaScript files for each enabled language of your website.
The generation occurs each time a module configuration is saved. In addition, you can manually start it via bx_Mod/BxScript.php.
During creation, the global module configuration, the configuration and language files of the modules, as well as the standard and custom JavaScript files are taken into account.
In the layout, the CMS automatically detects whether a suitable language file is available and includes it instead of the general JavaScript file.
For individual adjustments, always use the designated _own files to ensure your changes are retained during regular system updates.
FAQ
what customers often ask us
When are language-dependent JavaScript files generated?
The bluetronix CMS automatically generates the files as soon as you save a module configuration. The JavaScript files for all enabled languages are recreated.
How can I manually recreate the JavaScript files?
As an administrator, visit the address https://xxxx.bxserver.net/bx_Mod/BxScript.php. Replace the example domain with the address of your CMS.
Are JavaScript files generated for all available languages?
No. The CMS only creates language versions that you have activated via the Lang module. The corresponding settings are defined in bx_Mod/config_own.php.
Are the JavaScript files changed when switching color sets or layouts?
No. The color set or layout no longer changes the JavaScript files. Automatic regeneration occurs when saving a module configuration.
Which files can I customize?
For custom JavaScript adjustments, you have access to BxScript_own.js, BxScript_own_min.js, BxHeadScript_own.js, and BxHeadScript_own_min.js. The modules also have their own configuration and language files marked with _own.
What happens to the standard JavaScript files during a CMS update?
The standard files BxScript.js and BxHeadScript.js can be overwritten during system updates. Therefore, you should only save your changes in the designated _own files.
How does the CMS recognize which JavaScript file needs to be included?
The CMS checks when generating the webpage if a corresponding JavaScript file is available for the currently selected language. For example, if BxScript_de.js exists, it will be included for the German language version instead of the general file.
How do I prevent visitors from loading outdated JavaScript files from the browser cache?
The CMS can additionally use the file modification date as a version parameter when including JavaScript files. This allows the browser to load the new file version after a change.