Best way to translate month names

I am using Codeigniter! What would be the best way to translate the names of the months. I have a date in timestamp mysql: 2012-09-22 11:21:53
I can convert it to 'September 22, 2012' using the php date() function. I want to rename 'September' to 'Sentýabr' . Can the set_locale () function do this. By the way, this is Turkmen Language . thanks.


OK, I created some php file to check it as such:

cool.php

 <?php setlocale(LC_ALL,'ru_RU'); echo strftime('%B',time()); ?> 

September returns. What could be the problem.


I have

  /* Set locale to Turkmen */ setlocale(LC_ALL, 'tk'); 

and

  echo strftime( '%B',time()); 

Result: returns September

I need to return September in my language

+4
source share
4 answers

You can use str_ireplace() with arrays for names in English and equivalent names in Turkmen in the same order.

Something like that:

 $nmeng = array('january', 'february', ..); $nmtur = array('ocak', 'subat', ...); $dt = 'September 22, 2012'; $dt = str_ireplace($nmeng, $nmtur, $dt); 
+8
source

Use setlocale() and strftime ...

 setlocale(LC_TIME, 'ru_RU'); echo strftime('%B %e, %Y', strtotime('2012-09-22 11:21:53')); 

Edit:

If you are using a Windows server, change %e to %d ( %e does not work on Windows).

 echo strftime('%B %d, %Y', strtotime('2012-09-22 11:21:53')); 

For windows, check here to see the supported format.

+3
source

the best way to translate the names of the months is to put them in a language file and call it, how to read here, how to use language files in codeigniter Language library you can use the project in you again and again if you have a website with two languages.

 $this->lang->line('September'); your english language file $lang['january'] = 'january'; $lang['february'] = 'february'; ... $lang['September'] = 'September'; your turkish language file $lang['january'] = 'ocak'; $lang['february'] = 'subat'; ... $lang['September'] = 'Eylül'; 
+2
source

Add this to the index.php file at the top:

 /* Set locale to Turkmen */ setlocale(LC_ALL, 'tk'); 

The documentation for this is here: http://php.net/manual/en/function.setlocale.php

Also, @xdazz is correct that you must combine it with strftime instead of the date () function.

You may need to confirm that "tk" is used for the Turkmen language.

0
source

Source: https://habr.com/ru/post/1436285/


All Articles