wordpress - Create a multilingual calendar in php - 'translating' with setlocale

552

I am creating an hourly calendar (a booking form), and I have my calendar created

    {-code-1}

I have an array of booked dates in my{-code-2} variable.

Now since the site I'm working on is build on wordpress and translated with WPML, I can check the language of the site like:

{-code-3}

So for instance for Swedish this will be{-code-4}, for Germande etc.

So I googled a bit, and what I found is that I can change the format of my time and dates by usingsetlocale(). So I tried:

if ($current_lang == '{-code-4}') {
    setlocale(LC_ALL, '{-code-4}-SE');
} elseif($current_lang == 'de') {
    setlocale(LC_ALL, 'de-DE');
} else{
    setlocale(LC_ALL, 'en-US');
}

I also tried with just:

setlocale(LC_TIME, '{-code-4}-SE');

But nothing changed on my frontend.

I tried putting myif-else loop with$timestamp inside (and even changed the name to match the translation), I put thefor loop in, but nothing changed.

How do I handle the translation when building calendar with php?

824

Answer

Solution:

Ok, so the answer is that I was missing the proper locale. But that just points out the bigger issue - if the server I deploy this won't have it it won't be ok.

So the solution is to install the proper localization on server

sudo locale-gen sv_SE
sudo locale-gen sv_SE.UTF-8

or whatever language you need...

People are also looking for solutions to the problem: php - How to Display total mysql queries executed specific mysqli class

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.