Translation to Arabic on Appointments+ Dates

Hello,

Not sure if this is a bug with your Appointments+ plugin, or if I'm doing something completely wrong here - but here it goes:

Firstly we use the latest stable version of WPML for translations, and using string translation for your plugin successfully.

Our appointments page on the appointments confirmation page the date for example, the date doesn't translate to Arabic (despite the rest of the page) - e.g. December 21, 2013 2:20 pm - should be translated to ?????? 21, 2013 2:00 ?
http://blood.startupdev.co.uk/ar/make-an-appointment/
(english version: http://blood.startupdev.co.uk/make-an-appointment/)

Although interesting enough when you go through to PayPal, then click "back" and then go through the appointments stuff again - the appointment confirmation date is translated sometimes :S

It would appear the Ajax request for appointments confirmation doesn't get passed to WPML for translation everytime I reckon.

Getting very confused and frustrated with the bug/issue, if your able to point me in the right direction it would be much appreciated :slight_smile: Thanks!

  • Vladislav

    Hello,

    Just to make sure we're on the same page, the date in question is the value of the "Date and time:" field in the confirmation dialog - i.e. this: http://screencast.com/t/aNBddFQdxI right? I'm sorry if I'm asking a trivial question, but just trying to pinpoint the exact place where things go wrong in an unfamiliar locale.

    Anyway, if this is the case, as I'm seeing in the AJAX response, the label is properly localized (hopefully?) but the value is consistently in this format. For the date/time displaying, we're using the standard date_i18n localization wrapper (http://codex.wordpress.org/Function_Reference/date_i18n) which should work with standard translation techniques, but I'm not sure how WPML handles it, so I'll have a deeper look into that. Additionally I have tried reproducing the interesting behavior with going back from PayPal, but haven't been successful this far.

  • StartupGuys

    Hello,

    Yes we're talking about the value of the date and time field (as shown in your screenshot). That's interesting how the AJAX response is working, but still not translating correct on the frontend - very confusing. If your able to dig deeper, I would appreciate the help, as I've burnt many hours trying to get it translated :slight_frown:

    Also regarding the service names - do you have a method to translate this with WPML? It's a database stored value, so I'm not sure? As it's not ideal putting both languages on the service dropdown list - as I'm sure you can see :slight_smile:

    Thanks for your help in advance!

  • StartupGuys

    Hey Vladislav,

    Thanks for your pointer on live chat, I've got the date translation working on the confirmation screen of making an appointment! :slight_smile:

    Just need some pointers on the following outstanding plugin translation issues if you are able to help please:

    1) How can I translate the service names into Arabic? e.g. Online Blood Clinic Appointment - 20 Minutes // ???? ?? ??????? ??????? ??? ????? ???? 20 ????? - I can't display both at the same time as that's confusing, need to load the correct translation for the frontend forms.

    2) How can I translate 'pm' on the appointment times select table? See screenshot attached.

    3) How can I translate the date (and service name) in the confirmation and reminder emails? e.g. can I create a custom shortcode for the emails to DATE_TIME_AR?

    Many thanks for your help in advance for the above points, really stuck on them - can get my client live once completed.

  • Vladislav

    Hi,

    I'm very happy we managed to get the translation to work! As for the "pm" string not being translated, I think I have figured out where the issue might be - the "secs2hours" method seems to be using date() instead of locale-aware date_i18n to convert the time strings. This call is used in some other places too, so I'd like to perform some more checks to make sure this change doesn't reflect on something unwanted. In the meanwhile, perhaps using a 24h clock convention could be a workable interim option?

    As for translating the service names, unfortunately they're fixed-form for now, so naming them in a bilingual manner is probably the best idea for now. However, as for including the new macros in the emails, that is entirely doable with a little bit of custom code. Every confirmation email is passed through the filter named "app_confirmation_message", and the reminder emails are passed through a similar filter, named "app_reminder_message" and there's also the "app_notification_message" filter for notifications. Functions hooked to either one of those filters will accept up to 3 parameters, in this order: 1) a message body created and expanded this far, 2) an appointment object (with all the data) and 3) the appointment ID. Whatever is returned from this filter will be used as the message body.

    With this in mind, this bit of code will implement a custom macro expansion just before the email is sent out:

    function ar_app_date_time ($body, $app) {
    	global $appointments;
    	$start_datetime = strtotime($app->start);
    	$body = preg_replace('/DATE_TIME_AR/', date_i18n($appointments->datetime_format, $start_datetime), $body);
    	return $body;
    }
    add_filter("app_confirmation_message", "ar_app_date_time", 10, 2);
    add_filter("app_reminder_message", "ar_app_date_time", 10, 2);
    add_filter("app_notification_message", "ar_app_date_time", 10, 2);
  • StartupGuys

    Hi Vladislav,

    Unfortunately the date on the Arabic confirmation screen seems to have reverted itself automatically back to english :slight_frown: what a nightmare, didn't even change anything.

    Doesn't matter if I use the 24 hour or AM/PM format - the date (month) has stopped translating itself.

    I've added your code to our current theme functions.php file, The email shortcode returns, the following in the email contents:

    December 14, 2013 12:20 pm_AR (which obviously isn't correct or working)

    I must be missing something fundamental here, your assistance would be greatly appreciated please :slight_smile:

    Thank you,
    Andy

  • Vladislav

    Hello,

    As for the code in the functions.php from my post above, the result you got was entirely my fault - I have missed to factor in the fact that by the time the filter is reached, the default macros will already be expanded - ie. DATE_TIME part of DATE_TIME_AR will be replaced woth the date/time. The best approach is to use something more unique for your own macros - along the lines of AR_TIMEDATE, which will not be recognized by the plugin and will be passed verbatim to your filters.

    As for the other issue, I actually kinda expected them to stay fixed if we didn't prod and change anything. Do you perhaps have some sort of object caching active? If so, can you please try temporarily turning it off and see if that gives us a bit more predictable behavior?

  • akaanc

    Hello,

    I also would like to use this plugin with wpml and translate service names amd other dynamic content?

    I asked if wpml staff can find a way to translate this plugin but im sure you have a better idea if its doable.

    Is there anything you can do to make this plugin fully translatable via wpml or with your own way. I really like that plugin because its constantly updated and has the best support i've ever seen. Can you make it possible to work ith wpml or translate dynamic contents. Maybe an addon for that?

  • Vladislav

    Hello,

    As for the date/time format translation issue, it seems that apparently, WPML doesn't work with AJAX calls at all, which is what seems to be our problem: http://wpml.org/forums/topic/ajax-call-locale-bug-fix/

    In addition to the bit of code from the first post in the thread (which needs to be added to a mu-plugin or your functions.php in order to make WPML work with AJAX), we also need a way to send our current language back too. You can add something like this to make sure we're sending the proper language:

    function app_my_language_filter () {
    	global $sitepress;
    	$lang = $sitepress->get_current_language();
    	?>
    <script>
    ;(function ($) {
    $.ajaxSetup({
    	beforeSend: function (jqxhr, settings) {
    		settings.data += '&lang=<?php echo esc_js($lang); ?>';
    	}
    });
    })(jQuery);
    </script>
    	<?php
    }
    add_action('wp_footer', 'app_my_language_filter');

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.