Category Archives: Languages

An accent for your website

Have you ever wanted to change the original text for a plugin?  Do you have an audience who would respond to their unique way of speaking being used on your website?

Even if you’re english and it’s in english you can still “translate”.

WordPress is so amazing when it comes to language support (if theme and plugin developers have done their job well)

  • it will use a language file if it finds one
  • it will use a translation if there is one, else will revert to the default language
  • it allows for variations of language (en_US, en_AU etc)

So if you want to talk strine, BBC, cockney, singlish, na’vi or Klingon,  for at least some of the phrases in a plugin or theme, it’s easy. (I’n not bunging it on, you Can la!)

  • Drop the code at the bottom of the post into your plugin or theme’s functions.php.
  • Decide which locale code to use-  the default wordpress language for your site (for English it is en_US) or  a variation ? (en-GB, en_au ) .  If not using the default you will need to change your  wp-config.php file to tell your wordpress your preferred locale.
  • Create a translation file with just the texts that you want to translate.  For example using code styling localisation plugin
    1. Select the theme or plugin,
    2. click add new language and enter the locale code.  It will appear in the list of language files for that plugin or theme or wordpress core
    3. click edit against the language
    4. Scroll to the texts you want to  change or “accentise”
    5. Enter your text as the translation, SAVE
    6. after you have entered your translations, most important – generate the .mo file
  • Put the .mo file into your wp-content/languages folder
Screen shot of language folder

the link to clickenter a translation

It’s a link text, and here it is

the translation in action

Don’t like the menu text ? translate it!

Change the menu text

Have some fun!

Just pick a few key phrases (they must be translateable) to make an impact.

Your website could talk like a pirate just for a day – drop the .mo file in on the day and delete it afterwards!

Danger of upgrades

An upgrade may overwrite your translations, so save it somewhere other than the main plugin language folder .  The amr-events plugins looks for language files with the plugin language text domain in the wp-content/languages folder before looking in the normal place.

Locating your language file for the amr-events plugins in the wp-contents/language should be safe from upgrades.

For other plugins you could write a quick filter function to point to your special file.  WordPress now has several filters that can be used.  The best for this purpose may be:

$mofile = apply_filters( 'load_textdomain_mofile',
                     $mofile, $domain );

Suggested Filter Function

if (!function_exists('amr_load_custom_text') ) { // for filter
	function amr_load_custom_text( $mofile, $domain='' ) {
	//only do for the plugins/themes you want
	if (!in_array($domain, array('amr-ical-events-list', 'amr-events')))
        return $mofile;

    $pathinfo = pathinfo($mofile);
	$custom_mofile = WP_CONTENT_DIR."/languages/" 
            . $pathinfo["basename"];
	if (file_exists($custom_mofile)) 			
			return ($custom_mofile); 
	else  
			return $mofile;
    }
}
add_filter ('load_textdomain_mofile','amr_load_custom_text',10,2 );

Works a treat!

How to integrate WPML and amr-events – it’s easy

Want a multilingual website with an events plugin ? WPML works with amr-events (or the other way around!) – with standard posts or custom post types.

Please note that WPML is not necessary if all you want is events in another language with localised dates and numbers.   If all you want to do is create a translation manually, the code-styling localisation translation plugin (free) is handy.

WPML is a free plugin that you can use to either create translations manually, or pass translation requests through to their ICanLocalize [aff] service. IcanLocalize requires payment for translations.

With WPML, how to make it work

It is gratifying when plugins integrate seamlessly, using WordPress as it is intended.  I designed amr-events with this in mind – that one should be able to use a host of other plugins with it and was happy to discover that paid off here.   In addition WPML enables plugins and themes to pre-configure some bits for you to make it even easier.  Thus the necessary XML file is now included in the plugin files.   

Steps:

  1. Check the WPML settings (see advanced below) to be sure that it has picked up the info from the .xml file
    • check the custom field copy settings.  This is essential to be sure that the event data goes with the translation.  Think carefully about the LOCATION (address) field.
    • check the “translate custom post type” settings (if using custom)
    • check the blog post retrieval setting if no translation
  2. Create some representative events in original languages
  3. Create the translations.  WPML should copy the necessary event data. This event data is essential for the translation to be picked up as an event in a language calendar.
  4. Create your calendar page, add shortcode, save
  5. Create the translation page of the above calendar page, add same shortcode, save
  6. View calendars in original and other languages, check that events that have been translated are showing up on the appropriate pages.

Advanced:

If you experience any problems with event data copying, then please explore the WPML configuration as follows:

  1. In WPML settings, go to MultiLingual Content Setup, scroll down to the custom fields, and check all the events fields for “copying”.   See list at bottom of this post. Note: Decide whether you want “_LOCATION” addresses to be copied or translated.  The XML file is currently set to copy, but the next version will be to translate.  If this is an inappropriate default, please let me know.
  2. If you are using custom post types and taxonomies, scroll down a bit further and tick boxes for those too to enable translation for them.  Since you can create your own taxonomies for events, it is not possible to pre-configure these for you. (Remember to flush permalinks)
  3. Under WPML > Languages, please scroollll down to more options, check “Blog posts to display” – this choice may impact your events retrieval.

See screenshots below.

Without WMPL, single language content possible, with translated plugin files

Amr-events aims to localise, using recommended WordPress functions for translation and date and number display.  So if there is a language .mo file, it should use that for all text’s produced by the plugin.

Without a .MO file – dates and numbers will localise

Even without the mo file, with the calls to WordPress date and number localisation, you may find the public output (the dates etc with your language content) tolerable if your event creator can handle the english prompts!

RTL css for event creation.

I have included a basic RTL css for right to left languages, however am aware that it may not be adequate.  I would welcome input from anyone using a right to left language.

Plugin Translations:

Please note that  I am reliant on people using it in other languages to provide feedback and pickup on any details that are not localising or are not RTL compliant.  I will fix those asap.
Translations are always appreciated (by others at least! – hard for me to know how accurate or up to date they are!).  Translations should be in .po and .mo format. Thanks.

Screenshots

Event Edit Screen With Languages
Event Edit Screen with WPML options
Example of translated calendar page with translated and original language events
Example of translated calendar page with translated and original language events
WPML Menu option
WPML Menu option
Mark custom event fields in WMPL
Enable translation for events created as custom post types
Enable Translation for events created as custom post types
Only posts in language or all?

Custom fields to mark for copy in WMPL:

In the wpml settings, the radio buttons will be greyed out if preset from the xml file

  • _DTSTART
  • _DTEND
  • _DUE
  • _GEO
  • _TZID
  • _TZNAME
  • _ATTENDEE
  • _CONTACT
  • _ORGANIZER
  • _EXDATE
  • _EXRULE
  • _RDATE
  • _RRULE
  • _SEQUENCE
  • _DURATION
  • _ALLDAY
  • _VEVENT
  • _forever
  • _timezone
  • _tztype

Location fields (amr-events and other geo plugins that integate)

/* own fields */

  • _LOCATION (optional -it is the address, you may wish to translate rather),
  • _latitude,
  • _longitude,

/* _wpgeo fields*/

  • _wp_geo_latitude,
  • _wp_geo_longitude,
  • _wp_geo_title,
  • _wp_geo_map_settings,

/* geolocation fields  no underscore */

  • geo_latitude,
  • geo_longitude,
  • geo_address,
  • geo_public,

/* _gpress posts */

  • _gpress_posts

Ical fields not yet in use, but may be later. Update required if you use new functionality:

  • _ATTACH,
  • _CLASS,
  • _PERCENT-COMPLETE,
  • _PRIORITY,
  • _RESOURCES,
  • _STATUS,
  • _COMMENT,
  • _FREEBUSY
  • _TRANSP,
  • _RECURRENCE-ID,
  • _RELATED-TO,
  • _ACTION
  • _REPEAT
  • _icaltrigger