Localizing user fields (ie. gallery content rather than GUI)
dr_gaston
Joined: 2003-08-18
Posts: 4 |
Posted: Tue, 2003-09-09 03:56 | |||
This small patch to allow the users to enter multi-language text for all fields. This is done by using a special syntax: This string as an album title will display the English title unless the user has selected French, in which case the French title is displayed. Simple and efficient, you can see an example at http://art.baudard.net. Please apply the attached patch by going to the directory right above your gallery installation and typing the command: Basically, what this patch does is add an extra function in 'util.php' to parse the user-entered fields before display: /* This function extracts the translation of a user-entered field value Users must enter thetext in the following format: default_string|lang_code:translated string Example: My vacation by the sea|fr_CA:My vacation by the sea|de_DE:Mein urlaub am rand des meeres Will display the English text unless the current language is either fr_CA or de_DE */ function parseMLField($field) { global $gallery; // If no separator found, return untouched input $endpos = strpos($field,"|"); if ($endpos == FALSE) return $field; // If no current language tag, return default string $begpos = strpos($field, "|".$gallery->language.":"); if ($begpos == FALSE) return substr($field, 0, $endpos); // We've found a transtlation ... // skip lanbguage tag in itself $begpos = $begpos + 7; // go to end of translated string (ie. next tag or end of field) $endpos = strpos($field, "|", $begpos); if ($endpos == FALSE) $endpos = strlen($field); return substr($field, $begpos, $endpos-$begpos); } It then calls on this function before displaying any user-entered fields (gallery title, album title, descriptions, custom fields, ...) in the scripts 'albums.php', 'view_albums.php', 'view_photos.php', 'slideshow.php' and a few others in the 'html_wrap' directory: - <title><?php echo $gallery->app->galleryTitle ?></title> + <title><?php echo parseMLField($gallery->app->galleryTitle) ?></title> - <?php echo $gallery->app->galleryTitle ?> + <?php echo parseMLField($gallery->app->galleryTitle) ?> - $caption = $gallery->album->getCaption($index); + $caption = parseMLField($gallery->album->getCaption($index)); - $buf = $album->fields[$field]; + $buf = parseMLField($album->fields[$field]); - print "<center>".$gallery->album->fields["summary"]."</center>"; + print "<center>". parseMLField($gallery->album->fields["summary"]) ."</center>"; Etc. Enjoy ..... http://art.baudard.net for a demo
|
||||
Posts: 6818
Hello dr_gaston,
thanks for your effort.
Your solution looks nice, but _I_ think we cant use this for Gallery main code.
But the idea behind it is still very interesting and we wont forget it.
This is on my todo list for a later 1.4.1-cvs or maybe 1.4.2
wbR,
Jens
Posts: 23
Hello there.
This patch is working for Gallery 1.4.4?
Thanks!
Posts: 6818
Hello,
this post was made 1,5 years ago
its definitely NOT working with 1.4.4.
Also i must correct my statement.
Its not longer on my ToDo for 1.x
This feature will never go in 1.x series.
Jens
Posts: 23
Yeah I saw the date :lol: Just asking to be sure :wink:... Thanks!
Posts: 23
Ok, I have a solution to gallery 1.4.4-pl6, using the idea of dr_gaston, I came with this solution... I am testing it, but with the titles of the albums works...
The idea:
Modify the editField function in util.php by adding some "parsing" functionality to it. What I do is to parse the field description. For example, a title of an album look like this:
"Default Language|en_US:Healthy Food|es_ES:Comida Sana"
then in the editField function I did this (it might not be the best of codes but hey! it works)
I am testing it to find if this works on other fields that are modified by this function....
Here is the complete function.
Of course any suggestions, improvements are always welcome! :D
Posts: 8
Any chance to get this working with 1.5?
And how could I apply it without being able to use ´patch´.
Posts: 5
Will multilingual caption be a G2 feature ?
Posts: 6818
thibaud: yes, according to bharat it already does.
jens