[mod] How to setup up multi-language front end

3rd party code for phpList

[mod] How to setup up multi-language front end

Postby hakan » 7:00am, Mon 22 May, 2006

1. Requirements
~~~~~~~~~~~~~~~
- A Newsletter system which integrates into existing multi-language
site. Currently the site consists in German and English version. Italian and
Spanish versions are planned.

2. Issues
~~~~~~~~~
- PHPList is relatively easy to integrate into an existing site. But for
multi-language support one would have to set up a new PHPList instance for
every new language. Dynamic front end language switch is however possible with
some coding. See 4. Multi-language support for details.
- Not all messages where translatable. See
- http://mantis.phplist.com/view.php?id=6405
- http://mantis.phplist.com/view.php?id=6406
- http://mantis.phplist.com/view.php?id=6407

3. Integrate PHPList into your own site
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- We are using a simple framework for our site. Basically we setup a rather
static header, navigation and a footer. Depending on a $_GET variable we then
include a content page. For getting the multi-language requirement met we also
set a language variable with default to German.

Language settings:
Code: Select all
if (isset($_GET['lang']) && $_GET['lang'] == 'en') {
    $lang = '_en';
} else {
    $lang = '';
}


Include content page:
Code: Select all
if (isset($_GET['link'])) {
    switch ($_GET['link']) {
        case 'lb':
            require_once "laptopbattle$lang.php";
            break;
        case 'news':
            require_once "news_lb$lang.php";
            break;


If someone points to http://example.com/?link=lb we include
laptopbattle.php
If someone points to http://example.com/?link=lb&lang=en we include
laptopbattle_en.php

With this framework, including PHPList's subscription page is easy:

Code: Select all
if (isset($_GET['link'])) {
    switch ($_GET['link']) {
        // ...
        case 'join':
            require_once "join_lb$lang.php";
            break;
        case 'newsletter':
            // Including PHPList by setting proper $_GET variables
            if ($lang == '') {
                $_GET['language_module'] = 'german.inc';
                // id is the ID of the list to subcribe
                // Each list can have it's custom fields (called
                // attributes in PHPList) like country, name, age, ...
                // Each custom field has it's translation.
                $_GET['id'] = 1;
            } else if ($lang == '_en') {
                $_GET['language_module'] = 'english.inc';
                $_GET['id'] = 2;
            }

            // Default is the subscription form
            if (!isset($_GET['p'])) {
                $_GET['p']  = 'subscribe';
            }
            require_once 'lists/index.php';
            break;
        case 'faq':
            require_once "faq_lb$lang.php";
            break;
        // ...


With this approach you have to check, that you have no $_GET variable name
clashes. PHPList uses at least $_GET['p'] and $_GET['id']. On our site we do
not use this variables, so no variable name clashes where experienced.

If someone points to http://example.com/?link=newsletter, we include
lists/index.php

This is the front end entry point of PHPList. To get it running one has to pass
the required paramter $_GET['id']. A German subscription page was created
with the id 1 and an English subscription page with id of 2. Depending on our
current language ($lang) we set $_GET['id']. If no other action was set, we
set the default action "subcribe". After the variables are set, we then
inlcude the front end entry page of PHPList (lists/index.php)

Note that setting $_GET['language_module'] has no effect with standard
installation of PHPList. To get dynamic front end language switch working leads
to our next point.

4. Multi-language support
~~~~~~~~~~~~~~~~~~~~~~~~~
To get dynamic front end multi-language support one has to add following lines
to lists/index.php near the top:

Code: Select all
// Around line 27 in PHPList 2.10.2 lists/index.php

// Added for dynamic language support (Hakan Kuecuekyilmaz)
if (isset($_GET['language_module'])) {
    $GLOBALS['language_module'] = $_GET['language_module'];
}

require_once dirname(__FILE__) .'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__) .'/admin/init.php';


With this small modification, dynamic front end multi-language supports
works. Before one includes lists/index.php he can set $_GET['language_module']
to the desired <language>.inc file.

5. Examples
~~~~~~~~
German front end:
http://example.com/?link=newsletter

English front end:
http://example.com/?link=newsletter&lang=en
--
$Id: phplist_integration.txt 231 2006-05-22 06:54:29Z hakan $
Hakan Kuecuekyilmaz <hakan>, 2006-05-22
Last edited by hakan on 9:59pm, Wed 24 May, 2006, edited 1 time in total.
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Postby bevan » 8:24pm, Tue 23 May, 2006

Thanks for your excellent contribution!! :)

It will be very much appreciated by all the community!

I've requested it be included in the next major release: http://mantis.phplist.com/view.php?id=6461
bevan
PL Master
 
Posts: 465
Joined: 8:07pm, Sun 05 Feb, 2006
Location: Buenos Aires, Argentina

Postby bugsmi0 » 8:03pm, Fri 26 May, 2006

Could you put these instructions in easy form to understand ?

if we are only using english for language file

how does this include work ?

what file do we have to edit
where to put code

would like the entire subscribe/unsubscribe process to be pulled into web template pages if possible
bugsmi0
PL Nut
 
Posts: 33
Joined: 11:08am, Sat 04 Mar, 2006

Postby hakan » 11:04am, Sat 27 May, 2006

In a single language setup up, I would try to find out where the content of my site is included.

In my simple framework it is in index.php:

Code: Select all
if (isset($_GET['link'])) {
    switch ($_GET['link']) {
        case 'lb':
            require_once "laptopbattle.php";
            break;
        case 'news':
            require_once "news_lb.php";
            break;
        case 'dates':
            require_once "dates_lb.php";
            break;


That means, if somebody clicks:
http://example.com/index.php?link=dates

the file dates_lb.php gets included as content page.

If you want to include your subscription page, you have to find out the id of your subscription page created. You mentionend that you have only one English subscription page. So your id should be 1.

Then you include the front end entry page of PHPlist with the proper $_GET variables, like:
http://example.com/index.php?link=newsletter

Code: Select all
        case 'newsletter':
            // Including PHPList by setting proper $_GET variables
            $_GET['id'] = 1;

            // Default is the subscription form
            if (!isset($_GET['p'])) {
                $_GET['p']  = 'subscribe';
            }
            require_once 'lists/index.php';
            break;


Please take care, that your site is not using $_GET['id'] or $_GET['p'], as these variables are used by PHPlist.

To get the unsubscription page working you have to set up the proper URL's in your administration site of PHPlist.

In my example:
edit URL where users can subscribe
http://example.com/?link=newsletter&p=subscribe

edit URL where users can unsubscribe
http://example.com/?link=newsletter&p=unsubscribe

edit URL where users have to confirm their subscription
http://example.com/?link=newsletter&p=confirm

edit URL where users can update their details
http://example.com/?link=newsletter&p=preferences

edit URL where messages can be forwarded
http://example.com/?link=newsletter&p=forward

the "link=newsletter" is needed to jump into the correct switch/case branch to inlcude lists/index.php

I hope, it is now a bit clearer.

Regards, Hakan
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Postby bugsmi0 » 11:38pm, Sun 28 May, 2006

a few items not clear,

where does the term newsletter come from in the code ?

is link=newsletter a phplist function ? or is newsletter something we named somewhere in the phplist

i'm unable to use the complete code example using modx cms
these three items in the code won't work but when I remove them it doesn't show any error

case 'newsletter':
require once ( works with include)
and break;

so far i'm only able to pull in the subcribe page but the subcribe/unsubcrbie process won't remain in the site pages

I placed the phplist inside the modx cms directory site/lists/
bugsmi0
PL Nut
 
Posts: 33
Joined: 11:08am, Sat 04 Mar, 2006

Postby hakan » 6:32am, Mon 29 May, 2006

Hi,

the link=newsletter is for controlling my own index.php content includes. If the URL is http://example.com/índex.php?link=dates, I include dates.php as content page.

I would have to see your main page. I think it is not always that easy to integrate PHPlist into your own site. It depends on your main page.

Regards, Hakan
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Postby bugsmi0 » 4:18pm, Wed 31 May, 2006

when you say main page you mean the page where I want to pull in the subscribe form ?

the url would go something like this

domain.com/index.php?q=list


the actual list dir would be domain.com/lists/
bugsmi0
PL Nut
 
Posts: 33
Joined: 11:08am, Sat 04 Mar, 2006

Confirmation email

Postby Jac » 6:09am, Sun 04 Jun, 2006

Hello Hakan and thanks for your solution,

Could you tell how did you solve sending different confirmation emails depending on the language. That is, the confirmation email would have different URLs to click on depending on language.

This stands also for preferences, ...

It would be interesting to know how to add new placeholders (a new row into phplist_config table) to use them in these case, for example. If someone knows please post it.

Thanks.
Jac
phpList newbie
 
Posts: 1
Joined: 5:57am, Sun 04 Jun, 2006

Postby hakan » 9:04am, Tue 06 Jun, 2006

bugsmi0 wrote:when you say main page you mean the page where I want to pull in the subscribe form ?

the url would go something like this

domain.com/index.php?q=list


the actual list dir would be domain.com/lists/


Correct: main page, is the page where you want to pull in the subscribe form.

Correct: domain.com/index.php?q=list. In my case it is domain.com/index.php?link=newsletter.

I think you got the point now. If you still got problems, I would have to see you source code.

Bye, Hakan
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Re: Confirmation email

Postby hakan » 9:17am, Tue 06 Jun, 2006

Jac wrote:Hello Hakan and thanks for your solution,

Could you tell how did you solve sending different confirmation emails depending on the language. That is, the confirmation email would have different URLs to click on depending on language.

This stands also for preferences, ...

It would be interesting to know how to add new placeholders (a new row into phplist_config table) to use them in these case, for example. If someone knows please post it.

Thanks.


I created two subscribe pages. One for the English and one for the German subcribe page. On the admin page "subcribe pages" I setup following links for the English subscription page:

For instance
Message they receive when they confirm their subscription
....
....
To update your details and preferences please go to [PREFERENCESURL]&amp;lang=en.
If you do not want to receive any more messages, please go to [UNSUBSCRIBEURL]&amp;lang=en.

The parameter "lang" is used by index.php to set the desired language with $_GET['language_module'].

As you already noticed, not all types of messages are translateable on the admin page in "subcribe pages". You have to add the missing ones in
lists/admin/subscribelib2.php and in lists/admin/spageedit.php

Also see bug
http://mantis.phplist.com/view.php?id=6405

I attached a patch for spageedit.php.

Bye, Hakan
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Postby berkleebassist » 2:20am, Wed 02 Aug, 2006

hakan wrote:In a single language setup up, I would try to find out where the content of my site is included.

In my simple framework it is in index.php:

Code: Select all
if (isset($_GET['link'])) {
    switch ($_GET['link']) {
        case 'lb':
            require_once "laptopbattle.php";
            break;
        case 'news':
            require_once "news_lb.php";
            break;
        case 'dates':
            require_once "dates_lb.php";
            break;


That means, if somebody clicks:
http://example.com/index.php?link=dates

the file dates_lb.php gets included as content page.

If you want to include your subscription page, you have to find out the id of your subscription page created. You mentionend that you have only one English subscription page. So your id should be 1.

Then you include the front end entry page of PHPlist with the proper $_GET variables, like:
http://example.com/index.php?link=newsletter

Code: Select all
        case 'newsletter':
            // Including PHPList by setting proper $_GET variables
            $_GET['id'] = 1;

            // Default is the subscription form
            if (!isset($_GET['p'])) {
                $_GET['p']  = 'subscribe';
            }
            require_once 'lists/index.php';
            break;


Please take care, that your site is not using $_GET['id'] or $_GET['p'], as these variables are used by PHPlist....

I know this topic is a few months old, but let's say I wanted to include this into a standard HTML document, like, say www.mattgermak.com (beware, there's an auto-started music player on that page, and it's a bit loud.) How could I accomplish this? I'll assume that it will probably require some php, but I'm a newbie to the world of php, although as I understand it's not too tough. Thanks![/url]
berkleebassist
phpList newbie
 
Posts: 1
Joined: 6:33pm, Tue 01 Aug, 2006

Postby scuba303 » 3:55pm, Fri 27 Apr, 2007

hello,

did you setup own attributes for each languages? or how did you translate city / stadt etc?
scuba303
phpList newbie
 
Posts: 4
Joined: 10:45am, Fri 27 Apr, 2007

Postby hakan » 12:24pm, Wed 02 May, 2007

scuba303 wrote:hello,

did you setup own attributes for each languages? or how did you translate city / stadt etc?


Hi,

each language has it's own subscription page. In a given subscription page you can define your own attributes. That's how I defined City for the English subscription page and Stadt for the German subscription page.

Cheers,

Hakan
hakan
PL Nut
 
Posts: 21
Joined: 5:00am, Mon 22 May, 2006
Location: Stuttgart/Germany

Postby Sizoberz » 10:34pm, Tue 10 Jul, 2007

I really need this, but I don´t understand how to set it up.
Can someone explain me step by step how to do it please ?
Sizoberz
phpList newbie
 
Posts: 3
Joined: 10:29pm, Tue 10 Jul, 2007

Postby Sizoberz » 9:35pm, Wed 11 Jul, 2007

hakan wrote:In a single language setup up, I would try to find out where the content of my site is included.

In my simple framework it is in index.php:

Code: Select all
if (isset($_GET['link'])) {
    switch ($_GET['link']) {
        case 'lb':
            require_once "laptopbattle.php";
            break;
        case 'news':
            require_once "news_lb.php";
            break;
        case 'dates':
            require_once "dates_lb.php";
            break;


That means, if somebody clicks:
http://example.com/index.php?link=dates

the file dates_lb.php gets included as content page.

If you want to include your subscription page, you have to find out the id of your subscription page created. You mentionend that you have only one English subscription page. So your id should be 1.

Then you include the front end entry page of PHPlist with the proper $_GET variables, like:
http://example.com/index.php?link=newsletter

Code: Select all
        case 'newsletter':
            // Including PHPList by setting proper $_GET variables
            $_GET['id'] = 1;

            // Default is the subscription form
            if (!isset($_GET['p'])) {
                $_GET['p']  = 'subscribe';
            }
            require_once 'lists/index.php';
            break;


Please take care, that your site is not using $_GET['id'] or $_GET['p'], as these variables are used by PHPlist.

To get the unsubscription page working you have to set up the proper URL's in your administration site of PHPlist.

In my example:
edit URL where users can subscribe
http://example.com/?link=newsletter&p=subscribe

edit URL where users can unsubscribe
http://example.com/?link=newsletter&p=unsubscribe

edit URL where users have to confirm their subscription
http://example.com/?link=newsletter&p=confirm

edit URL where users can update their details
http://example.com/?link=newsletter&p=preferences

edit URL where messages can be forwarded
http://example.com/?link=newsletter&p=forward

the "link=newsletter" is needed to jump into the correct switch/case branch to inlcude lists/index.php

I hope, it is now a bit clearer.

Regards, Hakan


Now I get it working :-)
It works for subscribe and preferences page, but not for unsubscribe.
How can that be ?
Last edited by michiel on 2:24pm, Tue 04 Jun, 2013, edited 1 time in total.
Reason: domain mentioned no longer exists
Sizoberz
phpList newbie
 
Posts: 3
Joined: 10:29pm, Tue 10 Jul, 2007

Next

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 1 guest