how to offer languages plus choice of words in plugin

General questions regarding the use of languages in Joomla! 1.5.

Moderator: General Support Moderators

Locked
ewel
Joomla! Guru
Joomla! Guru
Posts: 522
Joined: Mon Oct 01, 2007 11:35 am

how to offer languages plus choice of words in plugin

Post by ewel » Fri Feb 08, 2008 1:19 pm

In my efforts to extend the functionality of a plugin that I am converting to Joomla 1.5 I have come to a standstill for lack of understanding how to best deal with language. The plugin I am working on takes the departure address filled into a one-field form and displays a Google map with the route from that departure point to a pre-defined destination.

I am trying to achieve three things:
1. I would like to offer the possibility that administrators can change pieces of text (which are the text before a text field, the text on a button and an error text if the text field is empty). This is not important if it is easy enough for administrators to make translations, but would be nice.
2. I have made two language files (English and Dutch) and would like to fully use the ability of Joomla to switch between languages.
3. I would like to present the Google map in the right language dependent on the current language on a page.

Ad 1. I achieved this by way of some paramters showing the default wording which can be changed, but I am not sure if and how to combine this with point 2.
Ad 2. I achieved this too, but again I am not sure how well it combines with point 1. If I did not have the parameters of point 1 in the plugin installation and settings xml file, how would I implement the translations?
Ad 3. Google maps comes in many languages, and to get the right page all I need to do is to insert "hl=en" or "hl=nl" etc. I could put use a php variable but this variable would need to be filled. Ideally I would be able to get the lower case two character language code out of the Joomla system, but I have no idea how to do this.
Also I would need to change "to" and "from" in the search string (if that is the right term of art); if one were to try 'from London to Dublin' in the Dutch version of Google maps a search error will result while the same addresses will return a map if 'van' and 'naar' are used. For this I would be dependent on the language files, but I do not know how to use these without creating parameters, and doing so seems to defeat the purpose of the language files.
A side question: how easy is it to change a language file for someone who does not have ftp and an html editor?

I am attaching the installation file of the otherwise functional plugin by way of illustration (please consider it a work in progress however). Any push in the right direction would be welcome..

Met dank, thanks in advance, merci beaucoup, vielen Dank, grazzi hafna etc!
You do not have the required permissions to view the files attached to this post.

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: how to offer languages plus choice of words in plugin

Post by infograf768 » Fri Feb 08, 2008 5:23 pm

these should be quite easy
$prompt = $pluginParams->def( 'prompt', 'Enter your start address: ');
  $buttonTxt = $pluginParams->def( 'buttonTxt', 'Get Directions' );
  $errorMsg = $pluginParams->def( 'errorMsg', 'Start location is empty ' );

for example:
$prompt = JText::_($pluginParams->def( 'prompt', 'Enter your start address: '));

and add the strings to the ini file

Can't reply for the rest, except concerning the editing of the ini files.
One just need a good text editor and save the files as utf8 no bom
http://www.babelstone.co.uk/Software/BabelPad.html on windows
Textwrangler on Mac
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

ewel
Joomla! Guru
Joomla! Guru
Posts: 522
Joined: Mon Oct 01, 2007 11:35 am

Re: how to offer languages plus choice of words in plugin

Post by ewel » Fri Feb 08, 2008 6:18 pm

Ok, that is helpful, thanks.

If a user of the plugin changes the parameters and changes the prompt wording from, say, 'Enter your start address: ' to 'Departure point: ', I suppose then the stings in the ini file will not work anymore, will they? I am assuming the system would look for 'Departure point: ' which as a user-changed parameter would not be in the ini file.

If they don't then adding the option to change the wording would diminish the option to change language, so then I should probably forget about the change fo wording options and just work with the ini files. In that case, I would have no parameter but something like this in the php code: $prompt = "Enter your start address: ";. How would I ensure that this works with the ini files? Would I simply put the strings in like this: 'ENTER YOUR START ADDRESS=Enter your start address: ' ?

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: how to offer languages plus choice of words in plugin

Post by infograf768 » Sat Feb 09, 2008 8:13 am

ewel wrote:
If a user of the plugin changes the parameters and changes the prompt wording from, say, 'Enter your start address: ' to 'Departure point: ', I suppose then the stings in the ini file will not work anymore, will they? I am assuming the system would look for 'Departure point: ' which as a user-changed parameter would not be in the ini file.
Exact.
ewel wrote: If they don't then adding the option to change the wording would diminish the option to change language, so then I should probably forget about the change fo wording options and just work with the ini files. In that case, I would have no parameter but something like this in the php code: $prompt = "Enter your start address: ";. How would I ensure that this works with the ini files? Would I simply put the strings in like this: 'ENTER YOUR START ADDRESS=Enter your start address: ' ?
It could be anything in the first part of the string, i.e.

if, in code, you have:

$prompt = JText::_($pluginParams->def( 'prompt', 'ENTERSTARTAD'));
or
$prompt = JText::_($pluginParams->def( 'prompt', 'enterstartad'));

the ini file should be:
ENTERSTARTAD=Enter your start address:
which a user could change to
ENTERSTARTAD=Anything the user wants to put here except a hard return.

Using the Translation Manager component would let this be edited on the fly.
See: http://joomlacode.org/gf/project/joomla_1_5_tr1/
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

ewel
Joomla! Guru
Joomla! Guru
Posts: 522
Joined: Mon Oct 01, 2007 11:35 am

Re: how to offer languages plus choice of words in plugin

Post by ewel » Sat Feb 09, 2008 10:00 am

Thanks! I think now it dawned on me how it works. I'll rewrite the whole thing in terms of language so that everything an administrator or visitor might see can be translated.

I will do it in the following way, please let me know if I am wrong...
    If in my code I have:
          $prompt = JText::_($pluginParams->def( 'prompt', 'ENTERSTARTAD')); 
    in the English language file I would have:
          ENTERSTARTAD=Enter your start address:
    and in the, say, Dutch language file this would be:
          ENTERSTARTAD=Vul uw vertrekadres in:

The translation component looks very nice, what a great piece of convenience. I evidently have not done the language files right because my plugin is not in the list, so Í will have to look more closely at some other extensions as examples.

Thanks again!

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: how to offer languages plus choice of words in plugin

Post by infograf768 » Sat Feb 09, 2008 3:56 pm

What is interesting to know is that the Translation Manager will display and let add to any language present a new ini file present in en-GB.
Thus making it a real easy task to translate to one's own language, whichever it is.
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

ewel
Joomla! Guru
Joomla! Guru
Posts: 522
Joined: Mon Oct 01, 2007 11:35 am

Re: how to offer languages plus choice of words in plugin

Post by ewel » Sun Feb 10, 2008 4:34 pm

The translation manager component is one of those few that should be advertised in the Joomla installation process or cpanel!

I thought I had grasped how to work with languages but then I decided to try and go one step further and failed. I had hoped to use descriptors for text to be used instead of the actual text.

Here are two parameters showing what I did in my xml file:
 
 
    Yes
    No
 

In my php I tried this:
  $link_text = JText::_('LINK TEXT');
  echo "";

In the en-GB ini file I have these corresponding lines:
  BORDER COLOUR LABEL=Border colour
  BORDER COLOUR DESCRIPTION=Border colour (example: silver)
  INITIAL NOTE TEXT=Make, view and save your personal notes!
  INITIAL NOTE LABEL=Display initial message for new users
  INITIAL NOTE DESCRIPTION=Display initial message for new users (Make, view and save your personal notes!)
  YES=Yes
  NO=No
  LINK TEXT=Save

The result is that my settings show labels in capitals and my form shows 'LINK TEXT' instead of 'save'.

In my xml I think I could solve this by replacing 'BORDER COLOUR LABEL' by 'Border colour' with a corresponding change of the ini file to 'BORDER COLOUR=Border colour'. I suppose in my php file I should do $link_text = JText::_('Save'); with 'SAVE=Save' in the ini.

But is there a way to do it in a way similar to what I was trying? I liked the idea of working with descriptors for text sort of like variables are used.


Locked

Return to “Language - Joomla! 1.5”