multiple php quotations from html + php code

Hi, and thanks for taking your time to read this. ;D

First of all, I’m trying to do multiple language through if / else statements. The website was originally only in English, and now I’m re-doing it into 2 Languages, and possibly more in the future. The site will be the same for 6-12 months, thus I personally don’t mind just coding it in.

The original HTML code I’m trying to ‘convert’ into php code:
[php]

Featured Videos

[/php]

So far, this is my code, which isn’t displaying the image and link correctly. I’ve been reading about double/triple PHP quotations, but I just can’t differentiate it, yet!
[php]

<?php $currentlang = get_bloginfo('language'); if($currentlang=="en-US") echo "

Featured Videos
\" target=\"_blank\">'/images/youtube.jpg'\">

";
elseif ($currentlang=="da-DK")

echo “

Duplicate code will be here, just in Danish

”;
else
echo “

Just a fallback

”;
?>
[/php]

Hopefully someone can help me, maybe tell the difference or just any advice, how you otherwise would do multiple translations. I’m currently using Polylang and ACF.

Best Regards,
Runi

There are a few ways to handle this, it just depends on how extravagant you want to go, and what area’s you feel most comfortable.

You can do a database lookup on the server side before the page is rendered.
You can do a JSON file that stores the versions.

Either way, you will have a placeholder text as a label, then which ever option you go with will use that label and the language selector stored in either a data table (for long term) or the session variable (for short term and current usage) to display the text that should be shown to that particular user.

Hi Astonecipher!

Thanks for the answer! :smiley:

I’ve used this before, that worked perfectly with changing language. And btw, the site is www.atlanticwool.com
[php]

<?php $currentlang = get_bloginfo('language'); if($currentlang=="en-US") echo '

Latest Products

'; elseif ($currentlang=="da-DK") echo '

Seneste Produkter

'; else echo "
Latest Products.
"; ?>

[/php]

But I could see JSON as an workaround! I’ve been doing some research in the mean time, and I’ve found out, that you can’t really put php code inside echo, is that correct? Cause that would be php code inside php code? I’ve been, as you could see in my previous example, trying to mark different quotations, but still no luck.

It would otherwise be great, if you could elaborate just a little bit more with the JSON option!

Best regards,
Runi ;D

What do you mean by php code inside an echo?

The JSON object usage is better suited for use with a templating engine. If you are currently using one, I can give an example…

Sponsor our Newsletter | Privacy Policy | Terms of Service