Advertisement

Language override for index php.file Topic is solved

General questions relating to Joomla! 5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
sgiobbio
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sun Jan 09, 2011 4:39 pm

Language override for index php.file

Post by sgiobbio » Mon Mar 24, 2025 1:25 pm

Is it possible to override the language of strings introduced in the index.php file of cassiopieia_child?
I have added the Silktide Consent Manager to one of our websites, which requires a portion of code to be inserted into index.php to function.
Since the website is multilingual, I would like to have the banner translations displayed in the correct language.
I attempted to replace a text portion with a string, but the override failed, and the online site displayed the string value instead of its translation.

Advertisement
User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 45108
Joined: Sat Apr 05, 2008 9:58 pm

Re: Language override for index php.file

Post by Webdongle » Mon Mar 24, 2025 4:11 pm

Create a module for each language and assign to their relative menu items.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

sgiobbio
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sun Jan 09, 2011 4:39 pm

Re: Language override for index php.file

Post by sgiobbio » Mon Mar 24, 2025 4:41 pm

Sorry Webdongle, I'm having trouble understanding your suggestions. I don't think it's possible to add any modules, and here's why:

The Silktide Consent Manager requires a code snippet to be inserted into index.php to function correctly.

This code snippet references a .js file and a .css file responsible for displaying the consent banner on the site and ensuring its proper operation.

The phrases displayed within that banner are embedded within the code snippet inserted into the site's index.php file.

These phrases are in English, and I need to override the language to display them in Italian and French when the multilingual site is viewed in either of those languages.

User avatar
ceford
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3158
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Language override for index php.file

Post by ceford » Mon Mar 24, 2025 5:24 pm

I had a brief look at the silktide/consent-manager repo on GitHub. The README shows an example HTML implementation. So taking that as a base, what I think you need to do:

The script that starts with: // Initialize the consent manager with your configuration

You should copy that to a JavaScript file with an '-en' in its name for example config-en.js. Make one of those files for each language and translate the English strings into each language (there is a way to save the strings in JavaScript you could try as an alternative). You can put the files in /media/templates/site/cassiopeia/css and js.

Now, in the cassiopeia/index.php file (or your custom copy) you need to add the Javascript and Styles using the Web Asset Manager. I am not sure where the best place is to do that. Try just before the ?><DOCTYPE html> statement. It would be something like:

// Register and attach a custom item in one run
$wa->registerAndUseStyle('bar', 'path/to/silktide-consent-manager.css, [], ['data-foo' => 'some attribute'], ['some.dependency']);
// Register and attach a custom item in one run
$wa->registerAndUseScript('bar','silktide-consent-manager.js', [], ['defer' => true], ['core']);

And then for the configuration you would have to get the language in use from $this and use a switch to load the required configuration file for the language.

$wa->addInlineScript('content of config-en.js');

You can read about the Web Asset Manager here: https://jdocmanual.org/en/jdocmanual?ar ... et-manager.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 45108
Joined: Sat Apr 05, 2008 9:58 pm

Re: Language override for index php.file

Post by Webdongle » Mon Mar 24, 2025 7:06 pm

sgiobbio wrote: Mon Mar 24, 2025 4:41 pm...

The Silktide Consent Manager requires a code snippet to be inserted into index.php to function correctly.
...
Where in the index.php?
If not in the <head></head> tags then when inserted into a custom module will display when the module is displayed.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

sgiobbio
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sun Jan 09, 2011 4:39 pm

Re: Language override for index php.file

Post by sgiobbio » Mon Mar 24, 2025 8:47 pm

Webdongkle it is located exactly between the <head></head> tags.
I would need a simple solution, if one exists; the one proposed by ceford seems too complex

User avatar
ceford
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3158
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Language override for index php.file

Post by ceford » Mon Mar 24, 2025 9:06 pm

sgiobbio wrote: Mon Mar 24, 2025 8:47 pm I would need a simple solution, if one exists; the one proposed by ceford seems too complex
Actually, very simple if you know how! So an interesting challenge - here is what I did:

1. Create a child template. I called mine silktide.
2. Copy index.php from templates/cassiopeia to templates/cassiopeia_silktide (use your file manager for this).
3. Go to System -> Site Templates and select Cassiopeia_silktide Details and Files
4. Upload the silktide-consent-manager.css file to the css folder.
5. Upload the silktide-consent-manager.js file to the js folder.
6. Create a new js file containing the configuration data copied from the README file (in the <script></script> part)
7. I named this file silktide-configuration-en.js
8. Translate that file into another language. I did that for German and French using ChatGPT.
9. Paste this code in the the Cassiopeia index.php file immediately after the instruction to load fontawesoeme:

Code: Select all

$wa->registerAndUseStyle('silktide', 'silktide-consent-manager.css');
$wa->registerAndUseScript('silktide', 'silktide-consent-manager.js');
if ($this->language == 'de-de') {
    $wa->registerAndUseScript('silktideconf', 'silktide-config-de.js');
} else if ($this->language == 'fr-fr') {
    $wa->registerAndUseScript('silktideconf', 'silktide-config-fr.js');
} else {
    $wa->registerAndUseScript('silktideconf', 'silktide-config-en.js');
}
10. Reload your page:
silktide-en.png
silktide-fr.png
silktide-preferences-fr.png
Afterthought: I made the silktide template the default to capture the results, first in English and then in French.
The pasted code above: only use the language files you have actually created.
You do not have the required permissions to view the files attached to this post.

sgiobbio
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sun Jan 09, 2011 4:39 pm

Re: Language override for index php.file

Post by sgiobbio » Mon Mar 24, 2025 9:40 pm

Thank you, Ceford, now everything is clear to me. You provided an excellent and well-explained solution with all the details. Thank you for the time you dedicated to me.

sgiobbio
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sun Jan 09, 2011 4:39 pm

Re: Language override for index php.file

Post by sgiobbio » Fri Apr 18, 2025 7:58 am

Hey Ceford, thanks a lot for that super clear example on how to implement the 3 Silktide config files for different languages directly in index.php.

Now, if we wanted to implement this directly in Google Tag Manager (GTM), what would the code look like?

User avatar
ceford
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3158
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Language override for index php.file

Post by ceford » Fri Apr 18, 2025 9:41 am

I am not familiar with GTM so I can't help with that! Anyone else?

Advertisement

Post Reply

Return to “General Questions/New to Joomla! 5.x”