Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Language mod

Quote Reply
Language mod
Ok, I'm trying to port over a mod I used with my Links 2.0 installation. My Links table features a "Language" column with multiple values: "en" for English", "ja" for Japanese and so forth. I tried to create a global called "langimg" that allows to display country flags for each language selected. Something along the following lines:

Code:
sub {
my ($rec) = @_;
if ($rec->{'Language'} eq 'en') {$lang_img = qq|<img src="/images/en.gif" border="0" alt="English"> |;}
if ($rec->{'Language'} eq 'ja') {$lang_img = qq|<img src="/images/ja.gif" border="0" alt="Japanese"> |;}
etc.

So far I only received the following error msgs: "Unable to compile 'langimg'". Crazy

I'd appreciate any help.
Quote Reply
Re: [Thomas.] Language mod In reply to
Links SQL uses strict coding. You need to declare all variables.

So you'd need:

my ($lang_img);
Quote Reply
Re: [Paul] Language mod In reply to
Thanks Paul, I appreciate your help. Please don't forget you're dealing with a perl illiterate. Laugh

OK, I've tried the following, still no luck ("unable to compile").

Code:
sub {
my($langimg)= @_;
if ($rec->{'Language'} eq 'en') {$langimg .= 'en.gif';}
if ($rec->{'Language'} eq 'ja') {$langimg .= 'ja.gif';}
.
.
.
return $langimg;
}
Quote Reply
Re: [Thomas.] Language mod In reply to
I think you misunderstood what he was suggesting.

Code:
sub {
my ($rec) = @_;
my $langimg;
if ($rec->{'Language'} eq 'en') {$langimg .= 'en.gif';}
if ($rec->{'Language'} eq 'ja') {$langimg .= 'ja.gif';}
.
.
.
return $langimg;
}

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Language mod In reply to
I know I should finally invest in a Perl book, lol.

Thanks Andy, that did the trick! Smile
Quote Reply
Re: [Thomas.] Language mod In reply to
Learning Perl - By O'Reilly (not sure if that is spelt right)....that was the first Perl book I purchased (amazon.co.uk)...great read, and very imformative, with lots of examples :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Language mod In reply to
I actually have one or two books, but they're catching dust, lol.

Hm, there's one more issue: if there's just one value in the column, the flag displays fine. Multiple values however result in no images displayed.
Quote Reply
Re: [Thomas.] Language mod In reply to
When you do the following, what does it show?

Code:
sub {
my ($rec) = @_;
my $langimg;
if ($rec->{'Language'} eq 'en') {$langimg .= 'en.gif';}
if ($rec->{'Language'} eq 'ja') {$langimg .= 'ja.gif';}
.
.
.
# return $langimg;
return $rec->{Language};
}

? Could you post the EXACT code it returns (i.e newlines etc). If I am thinking correctly, you may need to split $rec->{Language} where \n appear...and then compare $array[0] and $array[1].

Does that make sense? If not, please just post what the sub now returns...and I'll try and help you out a bit Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Language mod In reply to
Hi Andy, the code in your last post returns all the values in the Language column, but not the images:

en ja fr ... etc.

I don't know if this helps, but in my Links 2.0 installation the values in the Language field were delimited by ~~, the conditional statements looked as follows:

Code:
if ($rec{'Language'} =~/en/i) {
$langimg .= qq|<img src="en.gif"> |;
}
Quote Reply
Re: [Thomas.] Language mod In reply to
What is the value of your Language column?

Do some rows have more than one value in this column. If so how are they delimited?
Quote Reply
Re: [Paul] Language mod In reply to
Here's what I have in lsql_Links.def:

Code:
'Language' => {
'file_max_size' => '',
'file_save_in' => '',
'file_save_scheme' => 'HASHED',
'file_save_url' => '',
'form_display' => 'Language',
'form_names' => [
'en',
'ja',
'fr',
'es',
'po',
'ge',
'it',
'nl',
'ru',
'ko',
'zh',
'multi'
],
'form_type' => 'CHECKBOX',
'form_values' => [
'English',
'Japanese',
'French',
'Spanish',
'Portuguese',
'German',
'Italian',
'Dutch',
'Russian',
'Korean',
'Chinese',
'Multilingual'
],
'names' => [
'English',
'Japanese',
'French',
'Spanish',
'Portuguese',
'German',
'Italian',
'Dutch',
'Russian',
'Korean',
'Chinese',
'Multilingual'
],
'not_null' => '1',
'pos' => '21',
'regex' => '',
'type' => 'ENUM',
'values' => [
'en',
'ja',
'fr',
'es',
'po',
'ge',
'it',
'nl',
'ru',
'ko',
'zh',
'multi'
],
'weight' => ''
},

After importing the DB from Links 2.0 all the ~~ delimiting the field values were replaced by pipes (which probably means I have to edit them manually, sigh).

Users can enter one or multiple values in the Language field. In my LinksSQL installation multiple values are delimited by spaces.
Quote Reply
Re: [Thomas.] Language mod In reply to
>>>en ja fr ... etc. <<<

Are there new lines after it (when viewing the HTML)...i.e

en
ja
fr
... etc.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Language mod In reply to
All the values are outputted in one line, I attached an image. In the database however they're arranged vertically:

en
ja
fr
etc.


Sorry for all the trouble. Blush
Quote Reply
Re: [Thomas.] Language mod In reply to
If you want a flag to show for each country you'll need to split on the pipe and loop them.

Code:
my @countries = split /\|/, $rec->{Language};