Posted on: 12/30/05 07:57am
By: LWC
Multilingual - as in content (Geeklog is already multilingual in structure).
Once upon a time, a smart user called Euan
came up with a way[*1] to do it - but don't use this link! This code doesn't work anymore.
See, Euan's solution is not really a hack per-se. He basically replaced Geeklog's code with his own. Since Geeklog is not (and hopefully would never be) an outdated program that has no upgrades, from a programmer's view of point what he did is a major no-no!
Forget the theoretical discussion - it's already a fact that Euan's code became extinct once Geeklog was upgraded.
So what I've done was taking his code and making it version independent. I did it by hacking Geeklog's code (in the minimalist way possible) instead of replacing it.
So here it is. Unless I decide to make an official page for it, the following post is where the newest code would be and further posts would be a description of updates, so you know when to return to this post and replace the code.
Making Geeklog Multilingual
Posted on: 12/30/05 08:15am
By: LWC
Check out:
The Checklist.
Notes.
(Too bad I can't use "a name" in this site...)
The Checklist:
[QUOTE config.php]
$_CONF['allow_user_language'] = 1;
[/QUOTE]
- Topics
From now on, your topics' IDs must be in the shape of X_ln ("x" stands for the original topic's ID. "ln" stands for the first two letters in a certain language).
For example, news_en, animals_he, personal_fr.
Any topic without that extension would be ignored by Geeklog!
In the next post, you'd see how to declare those "ln"s (for example, you could set "en" to mean english.php).
- Stories
Unlike the topics, they don't have to use _ln. As a matter of fact, I suggest you only bother doing it when you have two (or more) identical stories in multiple languages. Then, if a user is inside a story and suddenly changes the language, he'd be taken to the same story in the new language (not because of Geeklog, but because of the code I shall introduce in the next post)!
- Polls
Unlike stories, they have to use _ln, as they're on the same level as topics (i.e. like folders as opposed to files).
Up to Geeklog v1.3.11, I've only hacked polls that were featured on the homepage.
In v1.4 and above, I've hacked all polls (because it was easier to control).
- Register_globals / register_long_arrays
Free! No need for those outdated things.
- Notes:
- Direct (cookie setting) links:
The default language is set up in config.php , but if you don't certain people to get another default language?
Well, soon you'd learn how to create a file called switchlang.php .
You can also use it for direct links that set the cookie in advance.
e.g. If your default contents are in English, use this when you post your link in a Hebrew site:
[quote For example:]
http://yourdomain.com/switchlang.php?lang=he
[/quote]
Making Geeklog Multilingual
Posted on: 12/30/05 08:50am
By: LWC
And now, without further adieu I present to you...my hack:
Part I - new codes:
The following are additions of either new files or new codes to exiting files in the Geeklog system.
- Creating arrays of possible languages
Or: creating a new file called languages.php (put it near config.php) :
This file just has 2 arrays - one just for the language changer's form and one in general.
You can enter as many languages as you want (but obviously it's useless to add languages you don't write content for anyway).
<?php
$_languages = array (
'en' => 'English',
'he' => 'Hebrew'
);
$_languagefiles = array (
'en' => 'english_utf-8',
'he' => 'hebrew'
);
?>
See the keys? That's why I've stressed before how important is it to use X_ln. That's the "ln"!
- Creating a "determine the language" function
Or: a hack for system/lib-custom.php :
First of all, let's define the most important function - this is the function I would keep using later on for everything else.
function language() {
global $_CONF, $_USER;
if ( !empty ($_USER['language']))
$retval = $_USER['language'];
else if ( !empty ($_COOKIE['language']))
$retval = $_COOKIE['language'];
else
$retval = $_CONF['language'];
return $retval;
}
The default language is naturally the one from config.php
From now on, I would usually use substr(language(), 0, 2) . Yes, that's the "ln" again!
- Creating a "change a language" block
Or: a hack for system/lib-custom.php :
Note: you will need to create a new Geeklog block and call the following function from there!
function phpblock_language()
{
global $_CONF;
include($_CONF['path'].'languages.php');
$retval = '';
if ( !isset( $_COOKIE[$_CONF['cookie_language']]))
$need_cookies_for_lang = '<br><font size=1>(Requires cookies)</font>';
$lang = language();
$retval .= '<form name="change" action="'. $_CONF['site_url'] . '/switchlang.php">';
$retval .= '<input type="hidden" name="oldlang" value="' . substr($lang, 0, 2) . '">';
$retval .= '<select onchange="change.submit()" name="lang">';
foreach ($_languages as $key=>$value) {
if ($lang == $_languagefiles[$key])
$selected = " selected";
else $selected = "";
$retval .= '<option value="' . $key . '"' . $selected. '>' . $value . '</option>';
}
$retval .= '</select>';
if (isset($need_cookies_for_lang)) $retval .= $need_cookies_for_lang;
$retval .= '</form>';
return $retval;
}
Yes, this is the worst part about this hack. It demands cookies even form anonymous users. But how else can make sure a user only gets his/her language?
- Creating a file for the language changer's form
Or: creating a new file called public_files/switchlang.php :
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4 |
// +---------------------------------------------------------------------------+
// | switchLang.php |
// | Switches between translation files. |
// | |
// | Copyright (C) 2006 by the following author: |
// | http://lior.weissbrod.com |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2003 by the following authors: |
// | |
// | Authors: Stratos Gerakakis - admin@stratosgear.com |
// | Robert Dobozy - robogl7@robod.net |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
include_once('lib-common.php');
include($_CONF['path'].'languages.php');
//If not allowed, just ignore and return
if ($_CONF['allow_user_language'] == 1) {
if (isset($_REQUEST['oldlang'])) {
$oldlang = strtolower(COM_applyFilter($_REQUEST['oldlang']));
}
// do we really have a new language to switch to?
if (isset($_REQUEST['lang'])) {
$lang = strtolower(COM_applyFilter($_REQUEST['lang']));
// does it exist in our current translation list?
if( is_file( $_CONF['path_language'] . $_languagefiles[$lang] . '.php' )) {
// Set the language cookie.
// Mainly used for the anonymous user so the rest of his session
// will remain in his selected language
setcookie ($_CONF['cookie_language'], $_languagefiles[$lang],
time() + 31536000, $_CONF['cookie_path'],
$_CONF['cookiedomain'], $_CONF['cookiesecure']);
// if he is not anonymous, store the preference in the database
if ($_USER['uid'] > 1) {
DB_query("UPDATE {$_TABLES['users']} SET language='{$_languagefiles[$lang]}'
WHERE uid = {$_USER['uid']}");
}
}
}
}
// If the user came from within your site, send them back to the referrer page
if (isset($_SERVER['HTTP_REFERER']))
if (strpos($_SERVER['HTTP_REFERER'], $_CONF['site_url']) !== false) {
$ret = $_SERVER['HTTP_REFERER'];
// Change the language's ID if needed
if (isset($lang) && isset($oldlang)) {
if (strpos($ret, '&') !== false) {
$ret = split("&", $ret);
$extra_vars = "&" . $ret[1];
$ret = $ret[0];
} else $extra_vars = '';
if (substr($ret, -3) == '_' . $oldlang)
$ret = substr_replace($ret, $lang, -2);
$ret .= $extra_vars;
}
}
// If the user didn't come from within your site, send them to your main page
if (!isset($ret))
$ret = $_CONF['site_url'] . '/';
Header("Location: $ret");
?>
The best thing I like about this is that if you change a language, you'll be taken to the same item you were in only in the new language.
I've made many fixes and improvements in this file.
- Showing only stories of a certain language
Or: a hack for public_html/index.php :
"Empty topic" mode is an interesting case (or /index.php without any parameters - in human lingo). It pulls stories from every topic the user has access to.
So let's add to that...in that user's language!
$sql = " (date <= NOW()) AND (draft_flag = 0)";
// custom code - start
if (empty($topic)) {
$lang = "%_" . substr(language(), 0, 2);
$sql .= " AND s.tid LIKE '$lang' ";
}
// custom code - end
// if a topic was provided only select those stories.
if (!empty($topic)) {
See, that's it!
Part II - hacks to exiting codes:
The following are (minimal as possible)
modifications for existing codes. So
use them instead of current codes and that means do
not - I repeat, do
NOT - add them in addition to the original codes as it would create a real mess and/or end life as we know it!
- Showing only topics of a certain language
Or: a hack for public_html/lib-common.php -
function COM_showTopics :
The list of topics is the list of topics the user has access to.
So let's add to that...in that user's language!
$sql = "SELECT tid,topic,imageurl FROM {$_TABLES['topics']}";
// custom code - start
$lang = "%_" . substr(language(), 0, 2);
$sql .= " WHERE tid LIKE '$lang' ";
// custom code - end
if( $_USER['uid'] > 1 )
{
$tids = DB_getItem( $_TABLES['userindex'], 'tids',
"uid = '{$_USER['uid']}'" );
if( !empty( $tids ))
{
// custom code - start
$sql .= " AND (tid NOT IN ('" . str_replace( ' ', "','", $tids )
. "'))" . COM_getPermSQL( 'AND' );
// custom code - end
}
else
{
// custom code - start
$sql .= COM_getPermSQL( 'AND' );
// custom code - end
}
}
else
{
// custom code - start
$sql .= COM_getPermSQL( 'AND' );
// custom code - end
}
if( $_CONF['sortmethod'] == 'alpha' )
Those are just minimal changes. It's just that the "topics' list" code is spread across many lines.
- Showing only polls of a certain language
or: a hack for public_html/lib-common.php -
function COM_showPoll :
Up to Geeklog v1.3.11 only! (or: before polls became a plugin).
I've decided not to hack public_html/polls.php itself, but those of you who are still with me should know how to do it yourselves.
However, surely I must match the homepage's polls to the chosen language, which is pretty easy.
else
{
// custom code - start
$lang = "%_" . substr(language(), 0, 2);
$sql = "AND qid LIKE '$lang' ";
$result = DB_query( "SELECT qid from {$_TABLES['pollquestions']} WHERE display = 1 $sql ORDER BY date DESC" );
// custom code - end
$nrows = DB_numRows( $result );
Again, that's it!
Part III - Plugins
The following are (minimal as possible)
modifications for existing codes in plugins' files. That means you must use them
instead of current codes and
not in addition.
Polls (starting in Geeklog v1.4)
- Featured polls on the homepage
or: a hack for /plugins/polls/functions.inc -
function POLLS_pollVote :
// custom code - start
$lang = "%_" . substr(language(), 0, 2);
$sql = "AND qid LIKE '$lang' ";
$question = DB_query( "SELECT question,voters,commentcode,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['pollquestions']} WHERE qid='$qid' $sql" );
// custom code - end
$Q = DB_fetchArray( $question );
- The polls' list page
or: a hack for public_html/polls/index.php :
// custom code - start
$lang = "%_" . substr(language(), 0, 2);
$sql = "qid LIKE '$lang' ";
$query_arr = array('table' => 'pollquestions',
'sql' => $sql = "SELECT *,UNIX_TIMESTAMP(date) as unixdate, display FROM {$_TABLES['pollquestions']} WHERE $sql",
// custom code - end
'query_fields' => array('question'),
To the brave few who got this far - I hope your site will become multilingual soon!
You can always contact me for help.
And may this hack someday become official!
Making Geeklog Multilingual
Posted on: 12/30/05 02:39pm
By: samstone
Ya, right, LWC!
You hacked the lib-common.php and called yourself minimalist?
Com_shwoPoll is no longer in lib-comon.php and your called yourself up-to-date?
Just kidding!
First, it doesn't make it better. The previous code at least shows the topics in different languages. Now when I changed the language, while I am on the home page, it not only didn't find the stories, but also didn't show the topics.
I thought maybe because your code was for 1.3.11, so I tried that on such site and it doesn't even switch language, it keep jumping back to English when I chose Hebrew.
I think Euan's hack was more minimal than yours, except the index.php hack has problem.
In anycase, thank for the codes. I will try to read it with my broken php-ish to figure out where the problem could be.
Sam
Making Geeklog Multilingual
Posted on: 12/30/05 03:55pm
By: LWC
I've added the version I use to the checklist. Do you run it?
I'm happy to tell you I run this hack on many sites and never had a problem.
If you read my code well enough, you'd see that unlike Euan, who used his own SQL lines, I usually just enter a new clause into existing Geeklog lines. That is why I call myself a minimalist.
My hack for a certain code is only as big as the lines in that code.
As for the polls, I bet you refer to the fact that it's a plugin now. Well, as much as I try to be version independent, would you mind telling me how exactly could I have prepared for that? When I'll switch versions, I'll update this topic accordingly (and write a new post that says the code was updated so people would know).
As for the topics, make sure you went over the checklist.
Making Geeklog Multilingual
Posted on: 12/30/05 05:36pm
By: samstone
I was just teasing you with those comments because you talked like a
Anyway, I tested again on 1.3.11 and found out the problem was I had the user language off in my config.php. I turned it on and now it works. I am a 'minimalist' when it comes to reading Hebrews, but I see it works!
So I attest that your super codes work! Thank you very much!
Now, I have to figure out with the 1.4.0 because that is the multilingual site I am building on.
I think it has to do with the changes in index.php or lib-common.php, which allow only english topics and stories to show up on the front page once the hack is in place.
Sam
Making Geeklog Multilingual
Posted on: 12/30/05 08:32pm
By: LWC
You're absolutely right. I've added it to the checklist. Sorry.
As for 1.4 (polls aside), both the parts I've hacked in public_html/index.php and in function COM_showTopics in public_htm/lib-common.php were not - I repeat, not - changed! I'm telling you this after running a file comparison program! So I have no idea why you neither see in the front page only stories in your language nor topics in your language like in 1.3.11.
Run through the checklist again.
Making Geeklog Multilingual
Posted on: 12/30/05 10:24pm
By: samstone
LWC, Your confidence and insistance just sound obnoxious.
But, I have nothing elses to say than a triple "Thank you!"
The problem is here:
Since I got used to Euan's concept, I just assigned any two letters for the language array. Since Chinese language has two types -- traditional and simplified, I couldn't use 'ch', but 'cn' and 'tw' as the common language code for 'China' and 'Taiwan'. Like in en-US and en-UK, they use zh-CN and zh-TW.
At your insistance and confidence on your codes, I went back to use everything original on the 1.4.0. site, with your Hebrew, and to my surprised it worked. So I narrowed it down to the language files.
So finally, after concentrating on the possible problems with language files, I found out you need the first two letters of the language file name.
So, the following instruction:
Topics
From now on, your topics' IDs must be in the shape of X_ln ("x" stands for the original topic's ID. "ln" stands for the first two letters in a certain language).
Should be:
Topics
From now on, your topics' IDs must be in the shape of X_ln ("x" stands for the original topic's ID. "ln" stands for the first two letters in a certain language's FILE NAME).
The solution is changing the language file names so that they don't have the same first two letters. The reqirement is that you have to change the file names of the plugins also.
Making Geeklog Multilingual
Posted on: 12/30/05 10:58pm
By: samstone
A question. There is a 30px gap between the dropdown menu and the bottom edge of the block. How to make it not to have such a large gap?
Sam
Making Geeklog Multilingual
Posted on: 12/31/05 12:01am
By: samstone
I feel it facinating to see the left and right blocks swapped when I tested Hebrew language on 1.4.0., but didn't happen on 1.3.11.
Is it a new feature with 1.4.0 or your sites also do the swapping with the earlier version?
Sam
Making Geeklog Multilingual
Posted on: 12/31/05 09:11am
By: LWC
samstone vs. ln
[QUOTE samstone]
Your confidence and insistance just sound obnoxious.
[/QUOTE]
And this after saying you were right and that I was sorry...
With that said...you were totally wrong about "ln"! Think about this for a second. Did you think my code has artificial intelligence and it just reads your mind in order to match languages? I wish...
No, you declare those "ln"s in languages.php . If you wanted, you could decide there that "ch" means english.php !
samstone vs. blocks
That block simply ends with a "/form" HTML tag. Anything after that is Geeklog's templates.
samstone vs. rtl
Yes, my sites all do that. I've submitted a patch that does this a long time ago, but the project site is down.
Here's a new topic I've just opened about this.
Making Geeklog Multilingual
Posted on: 12/31/05 01:18pm
By: samstone
No, you declare those "ln"s in /languages.php . If you wanted, you could decide there that "ch" means english.php !
No I can't declare "ch" to mean english.php. It has to be the first two letters. In my case I had to change the chinese_simplified_utf-8 and chinese_traditional_utf-8 files to simplified_chinese_utf-8 and traditional_chinese_utf-8 in order to make it work with X_tr and X_si.
You might have to take a look at it. But, what you said makes sense, if the first two letter is the definition than why we bother to define them?
That block simply ends with a "/form" HTML tag. Anything after that is Geeklog's templates.
I have tried many ways with style.css because other blocks doesn't leave such a gap. I tried "display: inline" tage with all relevent left block css but doesn't work. There might be a css for "form" that I might be able to use in style.css. I have to read about it.
Another question. Euan has a staticpage listing block that the list changes according to language. Which functions in conjunction with
the hack.[*2] I can see its usefullness. Have you look at it?
Sam
Making Geeklog Multilingual
Posted on: 12/31/05 01:40pm
By: LWC
I don't know how else to convince you there's no artificial intelligence involved, so I'll just ask you how can the following go wrong?
[QUOTE languages.php]
$_languages = array (
'bl' => 'English',
'ch' => 'Hebrew'
);
$_languagefiles = array (
'bl' => 'english_utf-8',
'ch' => 'hebrew'
);
?>
[/QUOTE]
In "bl" mode, you'd only see topics such news_bl, general_bl, etc.
In "ch" mode, you'd only see news_ch, general_ch, etc.
Just because it's English/Hebrew, doesn't mean I have to use en/he!
Making Geeklog Multilingual
Posted on: 12/31/05 01:59pm
By: samstone
OK, this thing is driving me crazy. I couldn't believe I was wrong based on what I saw with my two open eyes on my bright and clear computer screen, so I went back to test it. And I have proven myself a total idiot! I should quit the web development industry!
Then the question remains. What did happen? If it wasn't the codes and it wasn't even the language files. If there is no artifical intelligence, then there must be some supernatural intelligence out there... finding something to blame to keep myself sane...hee, hee, hee
Sam
Making Geeklog Multilingual
Posted on: 12/31/05 02:19pm
By: LWC
You tell this story and don't mention the most important thing - does it work now or not...?
I assume it does work because you use a past tense.
If it does, I can only assume that when it failed, it was because your topics' IDs didn't match with what you defined in languages.php .
Making Geeklog Multilingual
Posted on: 12/31/05 03:37pm
By: samstone
Yes, everything works now.
I have no answer as to why it didn't work. I am sure it wasn't the topic id's because it worked when I had a topic chosen. It just didn't work with the home page.
One possibility could be due to the privious cache or cookies, since I used Euan's hack before I switched to yours.
Sam
Making Geeklog Multilingual
Posted on: 12/31/05 07:06pm
By: LWC
Well, now that you've confirmed it's really version independent (at least unless Geeklog really makes a drastic changes in the way it uses MySQL), I've removed the version demand in the checklist.
So with that out of the way, it's time to hack the new polls' plugin that was introduced in Geeklog v1.4.
I'm glad to announce I've hacked it (I've updated the original post)!
I just need someone with Geeklog v1.4 to try it out! Report here if it works, please.
Making Geeklog Multilingual
Posted on: 12/31/05 11:16pm
By: samstone
Got this error
Sat Dec 31 23:34:01 2005 - 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND qid LIKE '%_en' ORDER BY unixdate desc' at line 1. SQL in question: SELECT *,UNIX_TIMESTAMP(date) as unixdate, display FROM gl_pollquestions WHERE AND qid LIKE '%_en' ORDER BY unixdate desc ;
Sam
Making Geeklog Multilingual
Posted on: 01/01/06 07:37am
By: LWC
You should use a quote box for unwrapped paragraphs like these (not to mention that it's a quote and not a code anyway). I've had to copy it to Notepad just to read it.
Anyway, thanks. It simply had an extra "AND" in there. I've updated it. Try again.
Making Geeklog Multilingual
Posted on: 01/01/06 01:46pm
By: samstone
Works!
Just a comment. Some of your custom codes are replacements of the existing codes, in lib-common.php, poll/index.php, etc.
Someone unaware of it would "insert" those codes and found it not working. Since the first few items were insertions, I continued to insert the rest of items. Only when it didn't work I found out that some of the lines to be repeated by your codes with a few changes. I had to comment out the old lines to make it work.
Just a thought for making the instruction a little more user friendly.
Thanks for the great work, and Happy New Year!
Sam
Making Geeklog Multilingual
Posted on: 01/01/06 06:17pm
By: LWC
Your wish is my command. Done.
Happy new year. Do you see how symbolic it turned out?
Making Geeklog Multilingual
Posted on: 01/01/06 09:21pm
By: Euan
I've updated my hack to work with 1.4.0rc1. You can now use the code on my site too if you prefer not to hack lib-common.php.
Cheers, Euan.
Making Geeklog Multilingual
Posted on: 01/10/06 01:02pm
By: Anonymous (duvide)
Thanks LWC for this great hack. This is exactly what I am looking for for my multilingual duvide.com site.
Right now I am trying it out on a fresh 1.4 rc1 install but I am getting this sql error:
Tue 10 Jan 2006 23:49:32 MYT - 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE tid LIKE '%_en' ORDER BY sortnum' at line 1. SQL in question: SELECT tid,topic,imageurl FROM WHERE tid LIKE '%_en' ORDER BY sortnum
Can you help?
Thanks/Frank
Making Geeklog Multilingual
Posted on: 01/11/06 03:41am
By: samstone
Boy, I remember I ran into that problem a couple of times, but forgot how I solved it. What version of GL are you testing on?
Sam
Making Geeklog Multilingual
Posted on: 01/11/06 03:45am
By: samstone
By the way, LWC,
How can I add a menu link at the top, let's say 'Gallery' using custom menu setting in lib-custom.php, to make it multilingual? How do I add an array in the language files and instruct the menu link to pick the words up from the language file?
Sam
Making Geeklog Multilingual
Posted on: 01/11/06 04:51am
By: Anonymous (duvide)
I am testing it on GL 1.40 rc1.
I think it has something to do with the alterations in index.php but not sure...
Frank
Making Geeklog Multilingual
Posted on: 01/11/06 11:45am
By: LWC
Hey, duvide. Well, that's an easy one. Your line says "select whatever FROM WHERE...". But FROM what? From "nothing", according to your line.
Now first of all, we've already established v1.4 changed neither the relevant lines in public_html/index.php nor in public_html/lib-common.php .
Secondly, your line looks identical to the one from public_html/lib-common.php - now take a look in my code and see it says FROM {$_TABLES['topics']} - and for some reason your output for that is null as if your Geeklog has no $_TABLES['topics']. Perhaps check system/lib-database.php
And finally, like I've already begged samstone, please use a quote box...to quote a text. It's really annoying to read it unwrapped.
Making Geeklog Multilingual
Posted on: 01/11/06 12:07pm
By: LWC
Well, samstone, a menu link is not a multilingual
content issue, is it? That's your standard multilingual structure that Geeklog already supports and therefore isn't related to this topic.
However, I'd help you nonetheless. See, just because Geeklog supports it doesn't mean...your plugin does!
So first of all, your plugin must have a multilingual structure itself. But
unlike Geeklog, you have to know that such a plugin usually only comes with english.php (and perhaps a few other chosen languages), which means that if your language is, say, Hebrew, you must either download it from geeklog.net or from the author's page OR translate it yourself!
Guess which option is the common one...
Secondly, just because a plugin has multilingual structure...doesn't mean it implements it on its menu titles! Some plugins hardcore the titles (usually in English, if the author at least has a minimal common sense).
Last and not least...since you've mentioned the word "Gallery", I can just cut short this discussion and recommend
Media Gallery[*3] , which not only is awesome in general, but happens to be using a multilingual structure
and implementing it on its menu title (the latter is thanks to yours truly's personal request).
- A little sidenote: the Staticpages' plugin is an exception as its menu titles are really content and not structure. And it really is a problem when you want multilingual titles. The easiest solution is to choose not to display the title and instead display via HTML tags in the content itself (of course the title header would still be in one language only).
This, of course, raises the general question of multilingual content's support in staticpages.
What I do is I activate PHP scripting and then use something like:
if (substr(language(), 0, 2)) = "he") {
$display = 'Something in Hebrew';
} else {
$display = 'Something in English';
}
// Now I manipulate $display to look however I want.
// And when I'm finally done
echo $display;
(it calls my language() function from system/lib-custom.php) to determine the language and display the matching text (including a title). And I use many parameters, of course (e.g. $title), but in the end I insert them all to $display.
Making Geeklog Multilingual
Posted on: 01/11/06 12:24pm
By: samstone
Thanks for the response. I know what I am asking for is no related to your hack, but by having this, our sites can be "completely" multilingual, at least in navigation.
I fact, I am not just talking about a plugin, I am talking about any link, a Static Page, or even external link. For example if I created a staticpage "About us" and I want to include it with the top menu bar, I can use the Custom Menu that comes with Geeklog in lib-custom.php.
Currently you can add a link-word there, like "About Us", but instead of intering "About Us" there, I want it to pick up an array from the language file like [lang_aboutus] that is added by me in each language file, so that when the language change it will pick up the same word in different language.
(Talking about that, it might be a good idea to add as a feature to Geeklog to have a "custom language" module, so that the additonal words can be in seperate language files, like english_custom.php.)
In any case, for the time being, I wonder how hard it will be to add an language array in the language files, and make the Custom Menu pick it up from there. I saw Euan has done it with his Top Menu block using $page[] array. That concept might be similar, but this is for the Custom Menu to pick it up rather than being in a seperate box.
As for "Gallery" I just use it for example becuase that is the sample code in the lib-custom.php. I am aware of the Media Gallery and, in fact, I have uploaded the Chinese Translation there for v0.98b.
You know what I am talking about now? In brief, I want to make the Custom Menue to speak in different language. Then we will be fully multilingual in navigation.
Sam
Making Geeklog Multilingual
Posted on: 01/11/06 12:37pm
By: samstone
Regarding your side note, I remember Euan has mentioned that since Staticpages (and even the blocks) use ID, we might be able to hack it with the same concept using _en, _he at the end of the StaticPage ID. What do you think?
Still it is only for the StaticPages, it doesn't solve the need of other types of links that I was talking bout.
Maybe I should post a seperate topic to see if anyone has a solution to raise the level of the current custom menu elements to multilingual.
Sam
Making Geeklog Multilingual
Posted on: 01/11/06 01:12pm
By: samstone
Yea, solved the problem, at least temporarity. I have to type in the menu words munually, so it requires UTF-8 capable editor to edit the lib-custom.php.
function CUSTOM_menuEntries ()
{
global $_CONF, $_USER;
include($_CONF['path'].'languages.php');
if ( strtolower($lang) == "english" ) {
$lang = 'en';
} else {
$lang = 'tr';
}
$myentries = array ();
if ($lang == 'tr') {
$myentries[] = array ('url' => $_CONF['site_url'] . '/whatever.html',
'label' => 'Whatever in Chinese Characters');
} else {
$myentries[] = array ('url' => $_CONF['site_url'] . '/whatever.html',
'label' => 'Whatever in English Characters');
}
return $myentries;
}
This way, I can make every custom menu item multilingual. This makes your multilingual code base even more useful.
You might want to refine this and add it to your code area, so that your multilingual dream will be more complete, and other people dont' have to look all over.
Sam
Making Geeklog Multilingual
Posted on: 01/12/06 07:08am
By: LWC
Since staticpages can use PHP, I rather use scripting. That way I can manage everything in one page.
Also, what's "strtolower($lang)"? You just use it as if you've declared it first, but you didn't.
I highly recommend to use the "if (substr(language(), 0, 2)) = "he") - else" structure.
As you can see in the default custom menu, you're supposed to use $LANG parameters. Your problem is that you want new words and then you have to apply a hack.
Unlike staticpages, which are UTF-8 by nature (if your site is), /public_html/lib-common.php, as you've pointed out, must be converted to UTF-8 first.
Alas, last time I tried converting any Geeklog file (except language files) to UTF-8, I've killed Geeklog...
So speaking of plugins, I'm less concerned with staticpages and more concerned with Filemgmt and Chatterblock.
Does anyone want to come up with ideas how to make them support a multilingual content?
Making Geeklog Multilingual
Posted on: 01/12/06 09:09am
By: Anonymous (duvide)
thanks LWC, it was not so clear that some of the changes were only meant for gl 1.3.12 and not for 1.4.
Now it sort of works but not quite. I checked it with several languages but I can only switch between english and german properly with Hebrew I get an error message. And I cannot switch to french or russion which I also put into the array at all.
Would there be a way to make the block titles also multilingual?
Making Geeklog Multilingual
Posted on: 01/12/06 10:11am
By: samstone
Duvide,
I remember some of the errors I encountered were because I "added" those codes to the files. You need to look carefully to find out some of the codes are for replacement of the original codes. Otherwise, there will be repeated lines of codes that could be the cause of your errors.
LWC, I found out that I didn't need the startlower line. The following is what actually working for me right now.
// Custom Menu Entries
function CUSTOM_menuEntries ()
{
global $_CONF, $_USER;
include($_CONF['path'].'languages.php');
$lang = language();
$retval = '';
$myentries = array ();
if ($lang == 'spanish_utf-8') {
$myentries[] = array ('url' => $_CONF['site_url'] . '/staticpages/index.php/information',
'label' => 'Información');
} else {
$myentries[] = array ('url' => $_CONF['site_url'] . '/staticpages/index.php/information',
'label' => 'Information');
}
return $myentries;
}
I didn't have to convert any files to utf-8, except lib-custom.php where I need to write some foreign language in. Making menue multilingual is very important for me because I have some custom links that don't look good if they don't change after changing the language.
As for Filemgmt and other plugins, the more we can make them multilingual, the merrier!
Sam
Making Geeklog Multilingual
Posted on: 01/12/06 11:24am
By: Anonymous (duvide)
I don't understand which files do you mean now, the languages.php?
f
Making Geeklog Multilingual
Posted on: 01/12/06 02:20pm
By: samstone
I was talking about this section on LWC's custom codes:
Part II - hacks to exiting codes:
The following are (minimal as possible) modifications for existing codes. Be careful not to add them in addition to the original codes as it would create a real mess and/or end life as we know it!
I just created another mulitlingual site (Spanish - English) using these codes and it worked without any problem. So the issue is not the codes themself, but understanding of the instruction. I guess LWC could make it clearer by showing the original codes and then comment out the original codes and adding the new codes at the same place. But, at this point as long as you understand that some codes are for adding in and others are for replacement, you should be fine.
Sam
Making Geeklog Multilingual
Posted on: 01/12/06 03:19pm
By: LWC
I'm glad it wasn't clear...because there are at least 5 places where I stressed it works for both versions (except polls, to which I posted both versions)!
This is also why, samstone, I'm not about to highlight the original codes. The post with the hack is big as it is. Besides, I did leave hints of the original code (above "// custom code - start" and below "//custom code - end").
And I recommed you again to use language(), 0, 2)) so it would be compatible with languages.php .
Making Geeklog Multilingual
Posted on: 01/12/06 04:00pm
By: samstone
And I recommed you again to use language(), 0, 2)) so it would be compatible with languages.php .
It is not that I am refusing to use what you are talking about, I am just not php literate enough to put it together that way. I spoke a broken php language and the computer somehow understood my command and worked. That's why I said that you might want to refine the codes I posted and make it "professional."
As for the clearness of your posting, it was clear enough for me, but obviously not for Duvide. I belong to the
STC[*4] "Society of Technical Communication" which teaches me to blame myself if a lay person doesn't understand what I am talking about. Most programmers see several steps ahead than a lay person that's why sometimes their explanations are like foreingn languages.
But you can be a good programmer and never need the skill of technical communication if you don't need to communicate your concept to lay persons. I loved OS/2 when it came out, but later Win95, a poorer operation system, took over the market because Microsoft knows better how to communicate with lay people.
Look at Geeklog, it is technically superior to many other more popular CMS, but they seem to somehow communicate better to the lay people and became popular. So success requires communication skills are much as technical skills. In Microsoft's case, the latter is even more important.
What a philosopher I am!
Sam
Making Geeklog Multilingual
Posted on: 01/12/06 07:25pm
By: Euan
My downloads are back online.
Cheers, Euan.
Making Geeklog Multilingual
Posted on: 01/13/06 10:15pm
By: samstone
Have you guys noticed that both this and Euan's hack don't change the language if the story is in the full story mode?
Sam
Making Geeklog Multilingual
Posted on: 01/14/06 08:08am
By: LWC
Yes, they do...if your story ends with _ln.
Like I've said, it's not mandatory because not all stories are written in more than one languages. In cases where they're not, you'd redirect people into 404 pages!
Besides, it's unlikely someone would go directly into a story. They would usually go into a topic or in the front page first.
Euan, it's ok if you don't, but why don't you post instead in
your dedicated topic that's even called after your name? You can keep it an updated topic about changes in your page.
Making Geeklog Multilingual
Posted on: 01/16/06 12:27pm
By: Anonymous (duvide)
And I recommed you again to use language(), 0, 2)) so it would be compatible with languages.php .
is this the problem that I have only 2 languages? I still don't quite get it.
And I would like to use multilingual so much
and I will not switch to mambojumbo!
The other thing is that I still would like to know if there also would be a way to make the block titles multiling?
Thank you guys so much for your help!
Making Geeklog Multilingual
Posted on: 01/16/06 01:46pm
By: samstone
What you quoted has nothing to do with your situation. LWC was talking to me regarding the menu bar customization.
As LWC said, there is no artificial intelligence in the codes.
All you need is follow his instructions, in the first three posts, and make sure you follow it exactly what he said. Don't try to skip a single letter.
Sam
Making Geeklog Multilingual
Posted on: 01/16/06 06:04pm
By: LWC
samstone said it best. Also, learn a lesson from samstone and make sure you don't use Euan's hack and mine at the same time...
If you lost all hope, would you consider paying so I'd do it for you?
As for block titles, what I do is generally disable block titles (by commenting them out in the left/right blocks' templates) and then hack Geeklog to add titles to specific blocks that really demand titles.
Making Geeklog Multilingual
Posted on: 01/21/06 12:30pm
By: Anonymous (duvide)
Thanks for your advice, both of you! I will incorporate it very soon or get back to you...
The last couple of days I was busy with something else.
f
Making Geeklog Multilingual
Posted on: 02/11/06 09:54am
By: LWC
First of all, I'd like to let everyone know I have this hack working 100% in Geeklog v1.4. I've told you it makes no difference. So forget about using that as an escuse anymore!
Secondly, I've upgraded switchlang.php so I encourage you all to do the same.
The improvements:
+ You can now use direct links for your site that force up a language (via the same cookie but bypassing the form)!
=>
See the starting notes/checklist post to see an example!
+ Where there's no referrer or it's external (using the new direct links), it would take the visitor to your main page, but this time I've made sure there's a "/" in the end.
=>
It matters for those of you whose sites don't use your root folders.
See, it would now use "http://yourdomain.com/yoursite/" instead of "http://yourdomain.com/yoursite", because the latter could cause troubles if, for example, your domain was pointed to an external host.
Making Geeklog Multilingual
Posted on: 02/15/06 08:38am
By: LWC
Reactiing on the sudden demise of $_CONF['cookie_lastvisit'] by the hands Geeklog v1.4, I've changed
$_CONF['cookie_lastvisit']
to
$_CONF['cookie_language']
in function phpblock_language() in system/lib-custom.php .
It means of course the only way to make the "cookies needed" message go away is to switch a language, which means people using the default language would have to switch and then switch back to make it go away.
But in Geeklog v1.4 the only ever present cookies are language and theme, so I see no better way.
Of course, it will also go away if you just use the new direct (cookie setting) links (see previous post).
Making Geeklog Multilingual
Posted on: 02/21/06 01:16am
By: samstone
After careful testing, I've confirmed that this code does not work with the Chinese language names at they are now:
chinese_traditional_utf-8
chinese_simplified_utf-8
I had to change it to:
tradtional_chinese_utf-8
simplified_chinese_utf-8
Making Geeklog Multilingual
Posted on: 02/21/06 07:13am
By: LWC
Haven't we been through this before? Your problem is not with the languages, but with your own keywords. You just can't use the same keyword twice (i.e. "ch").
[QUOTE Just make sure your languages.php looks like:
$_languages = array (
'ch_t' => 'Chinese Traditional',
'ch_s' => 'Chinese Simplified'
);
$_languagefiles = array (
'ch_t' => 'chinese_traditional_utf-8',
'ch_s' => 'chinese_simplified_utf-8'
);
?>
[/QUOTE]
And make sure your topics' IDs, etc. end with ch_t and ch_s when needed.
Making Geeklog Multilingual
Posted on: 02/21/06 10:17am
By: samstone
Yes, we've been through this before, and you've proven you were right, and that's why this time, I thought it would be an easy job. But, I went crazy after setting up the codes exactly they way it was instructed and it didn't work, until I remember last time I had the file names changed.
Of course, I am not stupid enough to use the same key word twice. I use 'tr' and 'si'. I tested in many ways you can imagine. It worked only after the first two letters match the id.
Anyway, I'll leave the mystery for the future. For now, I am glad that it works.
Sam
Making Geeklog Multilingual
Posted on: 03/01/06 04:28pm
By: samstone
One of my sites suddenly went down with the following error. I guess it has to do with the multilingual part.
Wed Mar 1 16:12:06 2006 - 1030: Got error 122 from table handler. SQL in question: SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) as day, u.username, u.fullname, u.photo, t.topic, t.imageurl FROM gl_stories as s, gl_users as u, gl_topics as t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND (date = 2) AND (s.tid IN ('General','News_en','News_sp','General_en','Archives_en','General_sp')) ORDER BY featured DESC, date DESC LIMIT 0, 5
Sam
Making Geeklog Multilingual
Posted on: 03/01/06 06:47pm
By: LWC
I've never hacked this line and in the lines I did hack I always just wrote "LIKE %_ln".
However, I've taken the time to search for this line and traced it in public_html/index.php (way below my hack there). I suggest you check the different "$sql .=" lines. I believe you've messed up one of them.
I think I should start charging you...
Making Geeklog Multilingual
Posted on: 03/02/06 09:31pm
By: samstone
Problem solved. It was my server's /temp files exceeding quota. MySQL sock is in that directory, so it ended up having no room to process sql commands.
Sam