Skip Navigation

[Résolu] Date field always in English

This support ticket is created Il y a 8 années et 7 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 13 réponses, has 2 voix.

Last updated by Pat Il y a 8 années et 6 mois.

Assigned support staff: Waqas.

Auteur
Publications
#261113

Pat

Hello,

I'm using Types and I'm not able to have the month of the date with the correct translation. My WordPress parameters are j F Y and my site is in French, but the result of the date is : 15 November 2014 !

Is there anything to do for this ?
Regards
Pat

#261542

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

The translations are meant to be displayed on the front-end, and may not work in the administration tool. But I will suggest you to take a look at this possible duplicate thread here: https://toolset.com/forums/topic/wpml-string-translation-seeming-to-read-custom-fields-but-wont-translate-when/

If this doesn't resolve the problem, please let me know.

#261553

Pat

Hello Waqas,

The issue for me is that I'm using this date within a hook. So, I'm getting the date from the postmeta in order to integrate it in the post title and don't know how to translate it into French in the function.

Let me know
Regards
Pat

#261623

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

In this case, I will suggest to use __() or _e() functions of Word Press API. These help returning the translated text.

Please see following links for more details:

http://codex.wordpress.org/Function_Reference/_2
http://codex.wordpress.org/Function_Reference/_e

#262857

Pat

Hello Waqas,

I have tried to use this code :
setlocale(LC_TIME, 'fr', 'fr_FR', 'fr_FR.ISO8859-1');
$value2 = strftime ( "%d %B %Y" , get_post_meta( $plannings, 'wpcf-pl-date', true ));

But the date included in the title is still in English.
Any other idea?
Regards
Pat

#262999

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Please consider using _e() function, since it will look for available translation (based on language) in the system and will return the correct one. Like:

$value2 = strftime ( "%d %B %Y" , _e(get_post_meta( $plannings, 'wpcf-pl-date', true ), 'your-text-domain'));

Please notice the use of _e() function above, as well as, remember to change 'your-text-domain' accordingly. Since get_post_meta() simply returns what is saved in the database. Filtering it through the _e() will get it through the correct (available) translation.

Please let me know if it works, or we can look into more details.

#263490

Pat

Hello Waqas,

Thanks for the info.
Just one point : can you explain what I need to place for "your-text-domain" ?
Regards
Pat

#263503

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

The 'text-domain' is an optional parameter, you can omit this if you are unsure. However, this is primarily used to group certain types of strings.

For example, 2 different plugins can use the same string for their purposes, but to keep 'em separate from a conflict, the 'text-domain' is used. Your theme, should define a text-domain (you can find it in functions.php).

Generally, it should work without the text-domain, please give it a try.

#263563

Pat

Hello Waqas,

That's what I was thinking, but the issue is that I placed this code :

add_action( 'cred_save_data_107', 'transfer_custom_fields_inscription_atelier' );
function transfer_custom_fields_inscription_atelier( $post_id ) {
$plannings = intval( $_POST['wpcf-ia-choix-atelier'] );
$value2 = strftime ( "%d %B %Y" , _e(get_post_meta( $plannings, 'wpcf-pl-date', true )));
$title .= $value2;
wp_update_post(array('ID' => $post_id, 'post_title' => $title));

and the result is still with a date in English in the title
Do you see any pb with this code?
Regards
Pat

#263694

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Your code is fine, but I am wondering, which plugin you are using for translation? Does that plugin translates meta fields in normal cases?

#263700

Pat

Hello Waqas,

I'm not using any plugin for translation. My site is define with the FR (French) language and it should work fine normally. In fact, everything is fine in the front end, but in the backend and in the hooks, the date is always in English.
Any idea?
Regards
Pat

#263746

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I just discussed this with my seniors and they suggested to use date_i18n() of Word Press Codex. Please consider following (your) code, altered accordingly:

add_action( 'cred_save_data_107', 'transfer_custom_fields_inscription_atelier' );
function transfer_custom_fields_inscription_atelier( $post_id ) {
	$plannings = intval( $_POST['wpcf-ia-choix-atelier'] );
	//$value2 = strftime ( "%d %B %Y" , _e(get_post_meta( $plannings, 'wpcf-pl-date', true )));
	$value2 = date_i18n ( get_option( 'date_format' ) , get_post_meta( $plannings, 'wpcf-pl-date', true ));
	$title .= $value2;
	wp_update_post(array('ID' => $post_id, 'post_title' => $title));
}

date_i18n() retrieves the date in localized format, based on timestamp. Please see http://codex.wordpress.org/Function_Reference/date_i18n for more information.

I hope this will fix the issue, please let me know if I can help you with anything related.

#263764

Pat

Hello Waqas,

Thanks for your support. Unfortunately, this is stil not working with your new code, the date in the title is stil in English !
I have also upgraded to the last version of Toolset plugin, but this has not changed anything.

Regards
Pat

#263766

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

May I ask for a temporary access to your website? So I can look into further things. I have set your next reply as Private, please input all relevant information in that area.

Also, please remember to take full backup of your website (site + database) before providing the access, I may need to change a few things, if needed.